CSCI 675 - P1, CSCI 675 - p2, CSCI 675 - P3

Ace your homework & exams now with Quizwiz!

Which of the following is needed in order to execute the following statement: time_t timer; Answers: #include <time.h> #include <ctime> #include <cstdlib> There is a syntax error Response Feedback: For this questions, students need to know C libraries, including: , <cctype>, <ctime>, <cmath>, <cstdlib>, and C++ headers, including: <iomanip>, <iostream>

#include <ctime>

We use (Root, LeftSubTree, RightSubtree) notation to represent a tree. Assume that we have AVL tree (7, 5, (8, NULL, 9)), after insert new node 10, what will be the new AVL tree? Here NULL represent empty subtree. In this case, 8 has no left child. Answers: None of these (7, 5, (9, 8 10)) (7, 5, (8, NULL, (9, NULL, 10)) (8, (7, 5, NULL), (9, NULL, 10)) Response Feedback: Student shall know AVL insertion, rotation, and property. May study at http://www.geeksforgeeks.org/avl-tree-set-1-insertion/ May use to https://www.cs.usfca.edu/~galles/visualization/AVLtree.html visualize.

(7, 5, (9, 8 10))

Identify the correct translation into logical notation of the following assertion. "Some boys in the class are taller than all the girls" Note : taller(x,y) is true if x is taller than y. Answers: (∃x) (boy(x) → (∀y) (girl(y) → taller(x,y))) (∃x) (boy(x) → (∀y) (girl(y) ∧ taller(x,y))) (∃x) (boy(x) ∧ (∀y) (girl(y) → taller(x,y))) (∃x) (boy(x) ∧ (∀y) (girl(y) ∧ taller(x,y))) Response Feedback: Student need to know Propositional and first order logic. May study at http://www.geeksforgeeks.org/proposition-logic/ and http://www.geeksforgeeks.org/mathematical-logic-propositional-equivalences/

(∃x) (boy(x) ∧ (∀y) (girl(y) → taller(x,y)))

Suppose we have the following definition: vector<int> vec, vec1; //use push_back to put 10 values into vec vector<int>::iterator p = vec.begin(); vector<int>::const_iterator q = vec.begin(); Which of the following expressions is NOT legal? Treat the effect of these as non-cumulative. Answers: *p = 1; *q = 1; q = vec1.end(); p = vec.end (); Response Feedback: Students shall know how to use iterators

*q = 1;

By using which operator does point to next element is represent in iterator? Answers: - ++ -- + Response Feedback: Student shall understand STL and iterator in each class in STL

++

Suppose that outFile is an ofstream connected to file named "output.txt". What will be output to output.txt file due to following code? int x = 5; outFile.setf(ios::showpos); outFile << x; Answers: 5 +5 -5 5.0 Response Feedback: students shall know how to use iomanip library. The ofstream can use setf with argument ios::fixed, ios::showpos, ios::showpoint. Also know that setprecision function and precision member functon

+5

The two linear equations above can be used to express gcd(225, 60) as a linear combination of 225 and 60: 15 = C · 225 + D · 60 What is the correct value for C? Answers: 1 -4 4 -1 Response Feedback: Student needs to know Euclidean Algorithm, Extended Euclidean Algorithm, and how to calculate the multiplicative inverse

-1

What is the output of the following code? public class MyClass{ private int x; public void output() { System.out.println(x); } public static void main(String [] args) { MyClass myClass = new MyClass(); // 1 myClass.output(); // 2 } } Answers: Compile error at line // 1 Compile error at line // 2 0 garbage value

0

Suppose the numbers 7, 5, 1, 8, 3, 6, 0, 9, 4, 2 are inserted in that order into an initially empty binary search tree. The binary search tree uses the usual ordering on natural numbers. What is the in-order traversal sequence of the resultant tree? Answers: 0 1 2 3 4 5 6 7 8 9 0 2 4 3 1 6 5 9 8 7 9 8 6 4 2 3 0 1 5 7 7 4 1 0 3 2 4 6 8 9 Response Feedback: Students shall be able to trace a binary search tree, do traversal, insert, delete algorithms, and their run time. May study at http://www.geeksforgeeks.org/binary-search-tree-data-structure/

0 1 2 3 4 5 6 7 8 9

What is the output of the following Java code? Answers: compile error at line 6 compile error at line 3 1 compile error at line 7

1

Apply the following insertion sort to array 4 1 2 5 3. Right after i is increased to 2, before the next iteration of loop body, what is the array? void insertionSort(int arr[], int n) { int i, key, j; for (i = 1; i < n; i++) { key = arr[i]; j = i-1; while (j >= 0 && arr[j] > key) { arr[j+1] = arr[j]; j = j-1; } arr[j+1] = key; } } Answers: 4 1 2 5 3 1 4 2 5 3 none of these 1 2 4 5 3 Response Feedback: Student shall be able to trace and implement insertion sort and selection sort algorithm. May study at http://www.geeksforgeeks.org/

1 4 2 5 3

Which of the following statement(s) is TRUE? A hash function takes a message of arbitrary length and generates a fixed length code. A hash function takes a message of fixed length and generates a code of variable length. A hash function may give the same hash value for distinct messages. Answers: 1 only 2 only 1 and 3 only 2 and 3 only Response Feedback: Students need to know hash with open addressing and separate chaining. May study at http://www.geeksforgeeks.org/data-structures/

1 and 3 only

Prove that 1 cross times 2 plus 2 cross times 3 plus... plus n cross times left parenthesis n plus 1 right parenthesis equals fraction numerator n left parenthesis n plus 1 right parenthesis left parenthesis n plus 2 right parenthesis over denominator 3 end fraction If we proof by mathematical induction, what will be proven under certain condition in inductive step? Answers: 1 cross times left parenthesis 1 plus 1 right parenthesis equals fraction numerator 1 left parenthesis 1 plus 1 right parenthesis left parenthesis 1 plus 2 right parenthesis over denominator 3 end fraction 1 cross times 2 plus 2 cross times 3 plus... plus k cross times left parenthesis k plus 1 right parenthesis plus left parenthesis k plus 1 right parenthesis cross times left parenthesis k plus 2 right parenthesis space equals space fraction numerator left parenthesis k plus 1 right parenthesis left parenthesis k plus 2 right parenthesis left parenthesis k plus 3 right parenthesis over denominator 3 end fraction 1 cross times 2 plus 2 cross times left parenthesis 2 plus 1 right parenthesis space equals space fraction numerator 2 left parenthesis 2 plus 1 right parenthesis left parenthesis 2 plus 2 right parenthesis over denominator 3 end fraction k is positive integer and 1 cross times 2 plus 2 cross times 3 plus... plus k cross times left parenthesis k plus 1 right parenthesis equals fraction numerator k left parenthesis k plus 1 right parenthesis left parenthesis k plus 2 right parenthesis over denominator 3 end fraction Response Feedback: Student shall know how to proof by mathematical induction and use mathematical induction to prove recurrence relation.

1 cross times 2 plus 2 cross times 3 plus... plus k cross times left parenthesis k plus 1 right parenthesis plus left parenthesis k plus 1 right parenthesis cross times left parenthesis k plus 2 right parenthesis space equals space fraction numerator left parenthesis k plus 1 right parenthesis left parenthesis k plus 2 right parenthesis left parenthesis k plus 3 right parenthesis over denominator 3 end fraction

Prove that 1 cross times 2 plus 2 cross times 3 plus... plus n cross times left parenthesis n plus 1 right parenthesis equals fraction numerator n left parenthesis n plus 1 right parenthesis left parenthesis n plus 2 right parenthesis over denominator 3 end fraction If we proof by mathematical induction, what will be the base case? Answers: 1 cross times left parenthesis 1 plus 1 right parenthesis equals fraction numerator 1 left parenthesis 1 plus 1 right parenthesis left parenthesis 1 plus 2 right parenthesis over denominator 3 end fraction 1 cross times 2 plus 2 cross times 3 plus... plus k cross times left parenthesis k plus 1 right parenthesis plus left parenthesis k plus 1 right parenthesis cross times left parenthesis k plus 2 right parenthesis space equals space fraction numerator left parenthesis k plus 1 right parenthesis left parenthesis k plus 2 right parenthesis left parenthesis k plus 3 right parenthesis over denominator 3 end fraction 1 cross times 2 plus 2 cross times left parenthesis 2 plus 1 right parenthesis space equals space fraction numerator 2 left parenthesis 2 plus 1 right parenthesis left parenthesis 2 plus 2 right parenthesis over denominator 3 end fraction k is positive integer and 1 cross times 2 plus 2 cross times 3 plus... plus k cross times left parenthesis k plus 1 right parenthesis equals fraction numerator k left parenthesis k plus 1 right parenthesis left parenthesis k plus 2 right parenthesis over denominator 3 end fraction Response Feedback: Student shall know how to proof by mathematical induction and use mathematical induction to prove recurrence relation.

1 cross times left parenthesis 1 plus 1 right parenthesis equals fraction numerator 1 left parenthesis 1 plus 1 right parenthesis left parenthesis 1 plus 2 right parenthesis over denominator 3 end fraction

What is the output of the following piece of code? int i = 0; while(++i <= 5) cout << i << ", "; Answers: This is an infinity loop, nothing output 1, 2, 3, 4, 5, 6, There is a syntax error 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, Response Feedback: Students shall know the syntax and semantics of for loop, while loop, and do while loop.

1, 2, 3, 4, 5,

Suppose that I have function void myswap(int& x, int& y){ int temp = x; x = y; y = temp; } what will be the output of the following code segment? int x = 5, y = 10; myswap(x, y); cout << x << ", " << y; Answers: There is a syntax error There is a run time error 10, 5 5, 10 Response Feedback: Students shall be able to write and use functions with pointer argument and can write and call functions that pass by reference

10, 5

What is the output of the following Java code? Answers: Compile error in line 6 Compile error in line 10 100 0

100

What is the value of numbers.capacity() after the following code? Answers: 0 Unknown 10 100 Response Feedback: Students shall know vector class in C++. May study http://www.cplusplus.com/reference/vector/vector/ and the functions in it

100

Suppose the input is 1234. What is the output of the following function? void display(int x){ if(x < 10){ cout << x; return; } display(x/10); cout << x%10 << ", "; } Answers: 12, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4 12, 3, 4 Response Feedback: Students shall be able to write and trace recursive algorithm

12, 3, 4,

Consider the following brute force factoring algorithm. How many numbers the algorithm will check if N = 23457 which happen to be a prime number? Input: Integer N greater than 1. Output: "Prime" if N is prime. If N is composite, return two integers greater than 1 whose product is N. For x = 2 to N-1 If x evenly divides N, Return( x, N/x ) End-for Return( "Prime" ) Answers: 1 123455 351 123457 Response Feedback: Student shall know the concept about prime factorization, greatest common divisor and least common multiple. Also know that factoring is a hard problem

123455

The preorder traversal sequence of a binary search tree is 30, 20, 10, 15, 25, 23, 39, 35, 42. Which one of the following is the postorder traversal sequence of the same tree? Answers: 15, 10, 25, 23, 20, 42, 35, 39, 30 10, 20 , 15, 23, 25, 35, 42, 39, 30 15, 20, 10, 23, 25, 42, 35, 39, 30 15, 10, 23, 25, 20, 35, 42, 39, 30 Response Feedback: Students shall be able to trace a binary search tree, do traversal, insert, delete algorithms, and their run time. May study at http://www.geeksforgeeks.org/binary-search-tree-data-structure/

15, 10, 23, 25, 20, 35, 42, 39, 30

Consider the following C++ code struct node { int data; struct node *left, *right; }; void print(node *root, int k, int &count) { if (root != NULL && count <= k) { print(root->right, k, count); count++; if (count == k) cout << root->data; print(root->left, k, count); } } what is output of print(root, 3, count); where int count = 0; and root represent the following tree? Answers: 10 16 20 10 20 Response Feedback: Students shall be able to trace a binary search tree, do insert, delete algorithms, and their run time. May study at http://www.geeksforgeeks.org/binary-search-tree-data-structure/

16

Output of following program? Assume that the size of int is 4 bytes and size of double is 8 bytes, and there is no alignment done by the compiler. #include<iostream> #include<stdlib.h> using namespace std; template<class T, class U, class V=double> class A { T x; U y; V z; static int count; }; int main() { A<int, int> a; A<double, double> b; cout << sizeof(a) << endl; cout << sizeof(b) << endl; return 0; } Answers: 20 28 16 24 There is a syntax error 8 16 Response Feedback: Student shall know how to write and use template functions and classes For more study, visit http://www.geeksforgeeks.org/c-plus-plus-gq/templates-gq/

16

A binary tree T has 20 leaves. The number of nodes in T having two children is Answers: 18 17 Could be any number between 11 and 19, inclusive 19 Response Feedback: Students need to know all properties of a Binary Tree. May study at http://www.geeksforgeeks.org/binary-tree-data-structure/

19

Given three functions: int fun(int x) { return x*x;} double funny(int x) { return x;}; double fun(double x) { return x;} What is the output of the following code: cout << setprecision(2) << funny(2.0); Answers: 2 4.0 There is a compile error 2.0 Response Feedback: Students shall know how to overload functions, opeartors, and how to use them

2

What is the output of the following Java progam? Answers: 2 Compile error in line 8 Run time except at line 8 99 Compile error in line 9

2

What is the output of the following code if user's input is 8? Answers: 2 There is a compile error in code 0 1

2

What is the output? Assume that the size of char is 1 byte and size of int is 4 bytes, and there is no alignment done by the compiler. #include<iostream> #include<stdlib.h> using namespace std; template<class T, class U> class A { T x; U y; static int count; }; int main() { A<char, char> a; A<int, int> b; cout << sizeof(a) << endl; cout << sizeof(b) << endl; return 0; } Answers: 6 12 2 8 8 8 There is a syntax error Response Feedback: Students shall know how to write and use template. Also know the size of each data type.

2

What is the output of following function for start pointing to second node of following linked list? 1->2->3->4->5->6 void fun(struct node* start) { if(start == NULL) return; cout << start->data; if(start->next != NULL ) fun(start->next->next); cout << start->data; } Answers: 2 4 6 6 4 2 2 4 6 2 4 6 1 3 5 5 3 1 1 3 5 1 3 5 Response Feedback: Students shall know the linked list and how to implement it. May study at http://www.geeksforgeeks.org/data-structures/linked-list/

2 4 6 6 4 2

Which of the following traversals is sufficient to construct BST from given traversals 1) Inorder 2) Preorder 3) Postorder Answers: 1 and 3 2 and 3 1 and 2 all of three Response Feedback: Students shall be able to trace a binary search tree, do traversal, insert, delete algorithms, and their run time. May study at http://www.geeksforgeeks.org/binary-search-tree-data-structure/

2 and 3

Assume that x has prime factorization: 3 squared cross times 5 cross times 7 cubed, and y has prime factorization: 2 cubed cross times 5 squared cross times 7 squared, what is the least common multiple of x and y? Answers: 5 cross times 7 squared 2 cubed cross times 3 squared cross times 5 to the power of 7 x 7 to the power of 5 2 cubed cross times 3 squared cross times 5 squared cross times 7 cubed 2 cubed cross times 3 squared cross times 5 cubed cross times 7 to the power of 5 Response Feedback: Student shall know the concept about prime factorization, greatest common divisor and least common multiple. Also know that factoring is a hard problem

2 cubed cross times 3 squared cross times 5 squared cross times 7 cubed

Solve each of the following recurrence equation with the given initial values. bn = bn−1 + 12bn−2. Initial values: b0 = −2, b1 = 20. Answers: a subscript 1 left parenthesis minus 4 right parenthesis to the power of n plus a subscript 2 3 to the power of n a subscript 1 4 to the power of n plus a subscript 2 left parenthesis minus 3 right parenthesis to the power of n 2 left parenthesis 4 right parenthesis to the power of n minus 4 left parenthesis minus 3 right parenthesis to the power of n 2 left parenthesis minus 4 right parenthesis to the power of n minus 4 left parenthesis 3 right parenthesis to the power of n Response Feedback: Student needs to know how to solve linear homogeneous recurrence relation

2 left parenthesis 4 right parenthesis to the power of n minus 4 left parenthesis minus 3 right parenthesis to the power of n

Count the number of binary strings of length 8 subject to each of the following restrictions: There is at least one 0 and one 1. Answers: 2 to the power of 7 2 to the power of 8 minus 2 2 to the power of 8 minus 1 2 to the power of 8 Response Feedback: Student shall know sum and product rules, permutation and combination, and the inclusive and exclusive rule

2 to the power of 8 minus 2

What is the output of the following Java program? Answers: There is a run time exception 2, 3 There is a compile error 1, 2

2, 3

What is the output of the following code? vector<string> names; names.push_back("Tom"); names.push_back("Jack"); cout << names.size() << ", " << names[1] << endl; Answers: 2, Tom 10, Jack 2, Jack There is a syntax error Response Feedback: Students shall know string and vector and their member functions. Study them at http://www.cplusplus.com/reference/

2, Jack

What is the output of the following code? Answers: 20 There is a syntax error in line 12 There is a syntax error in line 10 15

20

If we use binary search algorithm to search 1 4 8 9 11 15 19 20 25 28 32 35 36 48 52 for key 17, list the elements that will be compared with key in order of when the comparison happens Answers: 20 9 15 19 20 35 28 15 none of these 20 9 15 17 Response Feedback: Students shall know how to apply linear search and binary search algorithm

20 9 15 19

Given array {3, 7, 6, 5, 2, 1, 8, 4}, use quick sort algorithm to sort the array. what will be the return value from the first call of partition? Assume the last element is used as pivot for partition and array index starts from 0. Answers: 6 5 4 3 Response Feedback: Students shall understand the quick sort, merge sort, insertion sort, and selection sort. Also know their run time and the stability. May study at http://www.geeksforgeeks.org/

3

Assume that x has prime factorization 5 to the power of 4 cross times 11 squared cross times 13 cubed and y has prime factorization 3 cross times 7 cross times 11 cross times 13 cubed, what is the prime factorization of the product of x and y? Answers: 3 cross times 5 to the power of 4 cross times 7 cross times 11 squared cross times 13 cubed 3 cross times 5 cross times 7 cross times 11 cross times 13 3 cross times 5 to the power of 4 cross times 7 cross times 11 cubed cross times 13 to the power of 6 11 cross times 13 cubed Response Feedback: Student shall know the concept about prime factorization, greatest common divisor and least common multiple. Also know that factoring is a hard problem

3 cross times 5 to the power of 4 cross times 7 cross times 11 cubed cross times 13 to the power of 6

Solve each of the following recurrence equation with the given initial values. bn = 4bn−1 − 4bn−2. Initial values: b0 = 3, b1 = 10. Answers: 3 left parenthesis 2 right parenthesis to the power of n plus n left parenthesis 2 right parenthesis to the power of n plus 1 end exponent 5 left parenthesis 2 right parenthesis to the power of n minus 3 n left parenthesis 2 right parenthesis to the power of n 3 left parenthesis 2 right parenthesis to the power of n minus n left parenthesis 2 right parenthesis to the power of n plus 1 end exponent a subscript 1 2 to the power of n plus a subscript 2 n left parenthesis 2 right parenthesis to the power of n Response Feedback: Student needs to know how to solve linear homogeneous recurrence relation

3 left parenthesis 2 right parenthesis to the power of n plus n left parenthesis 2 right parenthesis to the power of n plus 1 end exponent

A hash table of length 10 uses open addressing with hash function h(k)=k mod 10, and linear probing. After inserting 6 values into an empty hash table, the table is as shown below. How many different insertion sequences of the key values will result in the hash table shown above? . Answers: 30 40 20 10 Response Feedback: Students need to know hash with open addressing and separate chaining. May study at http://www.geeksforgeeks.org/data-structures/

30

Breadth First Search (BFS) is started on a binary tree beginning from the root vertex. There is a vertex t at a distance four from the root. If t is the n-th vertex in this BFS traversal, then the maximum possible value of n is ___________ Answers: 31 32 16 15 Response Feedback: Students need to know all algorithms of a binary tree, including pre-order, in-order, and post order traverse, Bread first search and Depth first search. May study at http://www.geeksforgeeks.org/binary-tree-data-structure/

31

What is the output of the following Java program? Answers: -1 There is compile error 4 There is run time error since the array to be searched is not sorted

4

Consider a max heap, represented by the array: 40, 30, 20, 10, 15, 16, 17, 8, 4. Now consider that a value 35 is inserted into this heap. After insertion, the new heap is Answers: 40, 30, 20, 10, 15, 16, 17, 8, 4, 35 40, 35, 20, 10, 30, 16, 17, 8, 4, 15 40, 30, 20, 10, 35, 16, 17, 8, 4, 15 40, 35, 20, 10, 15, 16, 17, 8, 4, 30 Response Feedback: Student shall know heap algorithms, properties, insert, and delete. May study at http://www.geeksforgeeks.org/heap-data-structure/

40, 35, 20, 10, 30, 16, 17, 8, 4, 15

A bit string consists of 0s and 1s. For example, 0101 is a bit string with four bits. How many bits strings with length 6 or 5 that begins with 0? Answers: 48 64 32 24 Response Feedback: Student shall know sum and product rules, permutation and combination, and the inclusive and exclusive rule

48

Assume int x = 5; int y = 10; What will be the y value after the execution of following C++ code segment? if(x > y){ y = 8; } else{ if(x > 20); y = 5; } Answers: There is a syntax error 8 10 5 Response Feedback: Students shall pay attention to the syntax of if, if-else, if-esel if -else, and switch structure

5

Suppose I have the following recursive function, what is the return value when call myop(4)? int myop(int n){ if(n <= 2) return 1; return 1 + myop(n-1) + myop(n-2) } Answers: 6 8 5 7 Response Feedback: students shall be able to write and trace the recursive function

5

What is the output of the following code segment? int x = (int) 5.6789; System.out.println(x); Answers: 6 5 There is a run time error There is a compile error

5

Suppose that I have function void myswap(int x, int y){ int temp = x; x = y; y = temp; } what will be the output of the following code segment? int x = 5, y = 10; myswap(x, y); cout << x << ", " << y; Answers: 5, 10 There is a run time error 10, 5 There is a syntax error Response Feedback: Students shall be able to write and use functions with pointer argument and can write and call functions that pass by reference

5, 10

What is the output? #include <iostream> #include <iterator> #include <list> using namespace std; int main () { list<int> mylist; for (int i = 0; i < 10; i++) mylist.push_back (i * 10); list<int> :: iterator it = mylist.begin(); advance (it, 5); cout << *it << endl; return 0; } Answers: 30 40 50 60 Response Feedback: Students shall know the functions in iterator class. May study http://www.cplusplus.com/reference/iterator/

50

What is the multiplicative inverse of 6 Mod 7? Answers: 5 1 3 6 Response Feedback: Student needs to know Euclidean Algorithm, Extended Euclidean Algorithm, and how to calculate the multiplicative inverse

6

What is the output of the following code? int *p = new int[3]; *p = 1; *(p+1) = 2; *(p+2) = 3; int result = 0; int * q = p; for(int i = 0; i < 3; i++){ result += *q; q++; } cout << result; Answers: 1 6 0 There is a syntax error Response Feedback: Students shall know dynamic array. How to declare and initialize it.

6

What will be the output of the code? Assume user types 5 on keyboard? int *p, x; p = new int; *p = 10; cin >> x; p = &x; cout << ++*p; Answers: 5 11 There is a syntax error 6 10 Response Feedback: Student shall know how to declare a pointer variable. Allocate memory, How to initialize the value pointed by it and How to use the pointer variable.

6

6 people line up for a wedding picture, how many different ways to do this? Answers: 6! / 2 6! 5! 6 Response Feedback: Student shall know sum and product rules, permutation and combination, and the inclusive and exclusive rule

6!

The following postfix expression with single digit operands is evaluated using a stack: 8 1 3 + / 2 3 ** + 5 1 ** - The top two elements of the stack after the first * is evaluated are: Answers: 6, 3 5, 7 6, 2 1, 5 Response Feedback: Student needs to know stack and queue algorithms, implementations and applications. May study at http://www.geeksforgeeks.org/data-structures/

6, 2

Assume int x = 15; int y = 10; What will be the y value after the execution of following C++ code segment? if(x > y) if(x > 20) y = 6; else y = 7; Answers: There is a syntax error 7 10 6 Response Feedback: Students shall pay attention to the syntax of if, if-else, if-esel if -else, and switch structure

7

Consider an undirected random graph of eight vertices. The probability that there is an edge between a pair of vertices is 1/2. What is the expected number of unordered cycles of length three? Answers: 1/8 7 8 1 Response Feedback: Student needs to know types of graph, the representation of a graph, the algorithms related to the graph. May study at http://www.geeksforgeeks.org/graph-data-structure-and-algorithms/

7

To proof that 7 to the power of n space end exponent minus space 1 space i s space d i v i s i b l e space b y space 6 space f o r space a l l space p o s i t i v e space i n t e g e r space n. We want to prove by mathematical induction. Which of the following is in induction step? Answers: 7 to the power of n plus 1 end exponent minus 1 equals 7 left parenthesis 7 to the power of n minus 1 right parenthesis space space plus space 6 7 to the power of n minus 1 space equals space 7 left parenthesis 7 to the power of n minus 1 end exponent minus 1 right parenthesis plus 6 When n = 1, the statement is true W h e n space n space equals space 2 comma space 7 squared minus 1 space equals space 48 space i s space d i v i s i b l e space b y space 6 Response Feedback: Student shall know five proof skills. Direct proof, proof by contradiction, proof by cases, proof by contrapositive, and proof by mathematical indcution

7 to the power of n plus 1 end exponent minus 1 equals 7 left parenthesis 7 to the power of n minus 1 right parenthesis space space plus space 6

Use Euclid's Algorithm to calculate gcd (72, 27). The result is: Answers: 3 9 27 1 Response Feedback: Student needs to know Euclidean Algorithm and Extended Euclidean Algorithm

9

What is the output of the following code? Answers: 21 There is a syntax error 0 9

9

A 3-ary max heap is like a binary max heap, but instead of 2 children, nodes have 3 children. A 3-ary heap can be represented by an array as follows: The root is stored in the first location, a[0], nodes in the next level, from left to right, is stored from a[1] to a[3]. The nodes from the second level of the tree from left to right are stored from a[4] location onward. An item x can be inserted into a 3-ary heap containing n items by placing x in the location a[n] and pushing it up the tree to satisfy the heap property. Which one of the following is a valid sequence of elements in an array representing 3-ary max heap? Answers: 9, 5, 6, 8, 3, 1 9, 6, 3, 1, 8, 5 9, 3, 6, 8, 5, 1 1, 3, 5, 6, 8, 9 Response Feedback: Student shall know the heap property, inset and delete, and heap sort. May study at http://www.geeksforgeeks.org/heap-data-structure/

9, 5, 6, 8, 3, 1

What is the output of the following code segment? char c = 'A'; System.out.println(c+32); Answers: 97 c32 a There is a compile error

97

A large intersection left parenthesis A large union B right parenthesis equals Answers: B A A large union B A large intersection B Response Feedback: Student shall know set operations and set identities

A

What is the output of the following code if the value of score is 100? Assume variables score and grade has been declared as int and char, respectively. Answers: There is a compile error in line 21 There is a compile error in line 19 U A

A

What is the value of x after the execution of the following line of code? int x = (int) (Math.random()*100); Answers: 1 Syntax Error A random integer between 0 and 99, inclusive A random integer between 1 and 100, inclusive Response Feedback: Student shall know the methods in Math class. For instance, sqrt, pow, floor, ceil, random, etc

A random integer between 0 and 99, inclusive

What is the output of the following code? Answers: Derived::fun() called Compile error in line 8 Base::fun() called Compile error in line 16

Base::fun() called

A Boolean expression that is a sum of products of literals is said to be in disjunctive normal form (DNF) . A Boolean expression that is a product of sums of literals is said to be in conjunctive normal form (CNF). Indicate whether the following Boolean expressions are in conjunctive normal form or disjunctive normal form or both or neither. yxzw Answers: CNF Neither Both DNF Response Feedback: Student shall know basic Boolean operations, Boolean functions, and from Boolean function to gates

Both

Which of the following statements is/are TRUE for an undirected graph? P: Number of odd degree vertices is even Q: Sum of degrees of all vertices is even Answers: P only Q only Both P and Q Neither P or Q Response Feedback: Student needs to know types of graph, the representation of a graph, the algorithms related to the graph. May study at http://www.geeksforgeeks.org/graph-data-structure-and-algorithms/

Both P and Q

Which of the following return true if char c is an English letter. Assume that c has been initialized. Answers: Character.isAlpha(c) Character.isLetter(c) Character.isLetterOrDigit(c) Character.isDigit(c)

Character.isLetterOrDigit(c)

What is the output of the following Java code segment? int arr[2]; System.out.println(arr[0]); System.out.println(arr[1]); Answers: Compile error 0 0 garbage value garbage value Running time Exception

Compile error

What is the output of the following Java code segment? String s = "Hello"; // 1 System.out.println(s.size()); // 2 Answers: 5 Compile error in line // 2 6 Compile error in line // 1

Compile error in line // 2

What is true about the following Java code segment? Answers: There is no compile error Compile error in line 6 Compile error in line 10 Compile error in line 11

Compile error in line 11

What is true about the following Java program Answers: There is a compile warning message indicates that one catch clause can never be reached. However, the program still can run and the output will be: Caught derived class exception Compile error in line 9 Compile error in line 12. There is no compile warning or error. The output will be: Caught derived class exception

Compile error in line 12.

What is the output of the following Java program? Answers: Compile error in line 15 Grandparent Parent Child Grandparent Child Compile error in line 23

Compile error in line 15

What will the output in file data.txt after we execute the following Java program? Answers: nothing in file Hello World Compile error in line 5 HelloWorld Compile error in line 3

Compile error in line 3

What is the output of the following code? Answers: x = 10 y = 20 x = 20 y = 10 Compile error(s) in mySwap method Compile error(s) in main method

Compile error(s) in main method

Copy of What is the output? #include <iostream> using namespace std; class Test { static int count; int id; public: Test() { count++; id = count; cout << "Constructing " << id << endl; if(id == 3) throw 3; } ~Test() { cout << "Destructing " << id << endl; } }; int Test::count = 0; int main() { try { Test array[3]; } catch(int i) { cout << "Caught " << i << endl; } } Answers: Constructing 1 Constructing 2 Constructing 3 Destructing 1 Destructing 2 Caught 3 Constructing 1 Constructing 2 Constructing 3 Destructing 3 Destructing 2 Destructing 1 Caught 2 There is a syntax error Constructing 1 Constructing 2 Constructing 3 Destructing 2 Destructing 1 Caught 3 Response Feedback: Students shall know how exception is handled and also know the order constructor and destructor are called

Constructing 1

Which of the following algorithms can be used to most efficiently determine the presence of a cycle in a given graph ? Answers: Kruskal' Minimum Spanning Tree Algorithm Breadth First Search Prim's Minimum Spanning Tree Algorithm Depth First Search Response Feedback: Student needs to know types of graph, the representation of a graph, the algorithms related to the graph. May study at http://www.geeksforgeeks.org/graph-data-structure-and-algorithms/

Depth First Search

What is the output of the following code? Answers: Compile error in line 16 Compile error in line 15 Base::fun() called Derived::fun() called

Derived::fun() called

What is the output of the following Java program? Answers: Divide by zero error inside the finally block Divide by zero error inside the finally block 0, Divide by zero error inside the finally block

Divide by zero error

Which of the following is the head of copy constructor of Employee class? Answers: void Employee(const Employee& other) Employee(Employee& other) void Employee() void Employee(Employee& other) Employee() Employee(const Employee& other) Response Feedback: Students are required to know how to write big three: Copy constructor, Destructor, and Assignment Operator for a class

Employee(const Employee& other)

Is the following statement valid about shortest paths? Given a graph, suppose we have calculated shortest path from a source to all other vertices. If we modify the graph such that weights of all edges is becomes double of the original weight, then the shortest path remains same only the total weight of path changes. Answers: False Response Feedback: Student needs to know types of graph, the representation of a graph, the algorithms related to the graph. May study at http://www.geeksforgeeks.org/graph-data-structure-and-algorithms/

False

True or false? Regarding the following two rules of when to write Big Three: Copy Constructor, Assignment Operator, and Destructor? 1. Only write the one you will explicitly use in your program. For instance, you may write Copy Constructor but not destructor. 2. Prefer to write these methods even if the implicit ones are correct. Answers: True, False False, True False, False True, True Response Feedback: Students are required to understand the Big Three: Copy constructor, Destructor, and Assignment Operator. You may read more information from https://www.cs.umd.edu/class/spring2002/cmsc214/Projects/P1/copy-dest.html

False, False

What is the output of the following Java program? Answers: Compile error in line 4 Compile error in line 6 Good Morning Compile error in line 5

Good Morning

Suppose in.txt contains one line of data: "Hello World". What will be the content of out.txt after execute the following Java program. Suppose open file to read and open file to write both successfully. Answers: Hello World HELLO WORLD Compile Error Nothing

HELLO WORLD

What is the output of the following Java code segment? StringBuilder s = new StringBuilder("Hello"); s.replace(1, 7, "World"); //1 System.out.println(s); Answers: HWorldo Compile error in line //1 HWorld StringIndexOutOfBoundsException at line //1

HWorld

What is the output of the following code if user typed: Hello World then hit Enter Key? Scanner input = new Scanner(System.in); String greeting = input.nextLine(); System.out.println(greeting); Answers: There is run time error There is a syntax error Hello Hello World

Hello World

Predict output of the following program #include<iostream> using namespace std; class Base { public: virtual void show() { cout<< "I am base \n" ; } }; class Derived: public Base { public: void show() { cout<< "I am derived \n" ; } }; int main( void ) { Base *bp = new Derived; bp->show(); Base &br = *bp; br.show(); return 0; } Answers: I am base I am base I am base I am derived I am derived I am base I am derived I am derived Response Feedback: Students shall understand virtual function, polymorphism, and inheritance

I am derived I am derived

A Binary Search Tree (BST) stores values in the range 37 to 573. Consider the following sequence of keys. I. 81, 537, 102, 439, 285, 376, 305 II. 52, 97, 121, 195, 242, 381, 472 III. 142, 248, 520, 386, 345, 270, 307 IV. 550, 149, 507, 395, 463, 402, 270 Suppose the BST has been unsuccessfully searched for key 273. Which all of the above sequences list nodes in the order in which we could have encountered them in the search? Answers: II and III I and III III and V III only Response Feedback: Students shall be able to trace a binary search tree, do insert, delete algorithms. May study at http://www.geeksforgeeks.org/binary-search-tree-data-structure/

III only

What is the output? #include <iostream> using namespace std; int main() { try { try { throw 10; } catch (int n) { cout << "Inside Catch\n"; throw; } } catch (int a) { cout << "Outside Catch\n"; } return 0; } Answers: There is a syntax error Inside Catch Inside Catch Outside Catch Outside Catch Response Feedback: Students shall know how exception is handled. For extra study, may visit http://www.geeksforgeeks.org/c-plus-plus-gq/exception-handling-gq/

Inside Catch

Give the following simplified classes and code, what is the output of the last statement? class Pet{ public: virtual void print(); string name; private: }; class Dog:public Pet{ public: void print(); string breed; }; void Pet::print(){ cout << "My name is " << name; } void Dog::print(){ Pet::print(); cout << "My breed is " << breed << endl; } Dog* dPtr = new Dog; Pet* pPtr = dPtr; dPtr->name = "rover"; dPtr->breed = "Collie"; pPtr->print(); Answers: My name is roverMy breed is Collie My breed is Collie My name is rover My breed is Collie Nothing will be printed Response Feedback: The student shall understand the polymorphism

My name is roverMy breed is Collie

What is the output of the following Java program? Answers: Run time exception 0 MyClass@xxxxxxxx where xxxxxxxx is some hexadecimal number

MyClass@xxxxxxxx where xxxxxxxx is some hexadecimal number

What is the outcome of the following code? class Main { public static void main(String args[]) { int x = 0 ; int y = 10 ; System.out.println( y/x); } } Answers: 10 No compile error but will throw ArithmeticException exception 0 Compile error

No compile error but will throw ArithmeticException exception

Consider the Node structure as following /* Node of a doubly linked list */ struct Node { int data; Node *next; // Pointer to next node in DLL Node *prev; // Pointer to previous node in DLL }; What will be the code for step 2 in C++? /* Given a node as prev_node, insert a new node after the given node */ void insertAfter(struct Node* prev_node, int new_data) { /*1. check if the given prev_node is NULL */ /* 2. allocate new node */ /* 3. put in the data to the new node */ /* 4. Make next of new node as next of prev_node */ /* 5. Make the next of prev_node as new_node */ /* 6. Make prev_node as previous of new_node */ /* 7. Change previous of new_node's next node */ } Answers: Node new_node = new Node; Node *new_node = new Node; Node new_node; Node *new_node; Response Feedback: Students shall know basic algorithms (insert after, insert in front, back, and delete) about double linked list. May Study at http://www.geeksforgeeks.org/doubly-linked-list/

Node *new_node = new Node;

Which of the following is a true about Binary Trees Answers: Every binary tree is either complete or full. Every full binary tree is also a complete binary tree. Every complete binary tree is also a full binary tree. No binary tree is both complete and full None of the above Response Feedback: Students need to know all properties and algorithms of a binary tree, including pre-order, in-order, and post order traverse, Bread first search and Depth first search. May study at http://www.geeksforgeeks.org/binary-tree-data-structure/

None of the above

You are given pointers to first and last nodes of a double linked list, which of the following operations are dependent on the length of the linked list? Answers: remove the first element of the list insert in front of the list remove the last element of the list add new element at the end of the list None of these Response Feedback: Students shall know basic algorithms (insert after, insert in front, back, and delete) about double linked list. May Study at http://www.geeksforgeeks.org/doubly-linked-list/

None of these

Give the following simplified classes and code, what is the output of the last statement? class Pet{ public: virtual void print(); string name; private: }; class Dog:public Pet{ public: void print(); string breed; }; void Pet::print(){ cout << "My name is " << name << endl; } void Dog::print(){ Pet::print(); cout << ", My breed is " << breed << endl; } Dog dPtr; Pet pPtr; dPtr.name = "rover"; dPtr.breed = "Collie"; pPtr = pDog; pPtr->print(); Answers: Nothing will be printed. The last statement has syntax error My name is rover, My breed is Collie My name is rover , My breed is Collie Response Feedback: Student shall understand the polymorphism and sliced problem

Nothing will be printed. The last statement has syntax error

What is the Big O notation for following run time function? T left parenthesis n right parenthesis space equals space 1000 n log n space plus space 2 to the power of n space plus space 20000 Answers: O(n log n) O(1) O left parenthesis 2 to the power of n right parenthesis O left parenthesis n squared right parenthesis Response Feedback: Student shall know big O notation. Also Big capital omega space a n d space B i g space capital theta

O left parenthesis 2 to the power of n right parenthesis

What is the run time of binary search? Answers: O left parenthesis ln space n right parenthesis O(1) O(n) O left parenthesis n squared right parenthesis Response Feedback: Students need to know the linear search and binary search and their running time

O left parenthesis ln space n right parenthesis

Let G be a graph with n vertices and m edges. What is the tightest upper bound on the running time on Depth First Search of G? Assume that the graph is represented using adjacency matrix. Answers: O(n) O left parenthesis n squared right parenthesis O(m+n) O(mn) Response Feedback: Student needs to know types of graph, the representation of a graph, the algorithms related to the graph. May study at http://www.geeksforgeeks.org/graph-data-structure-and-algorithms/

O left parenthesis n squared right parenthesis

What is the worse case run time for following algorithm? CountDuplicatePairs This algorithm counts the number of duplicate pairs in a sequence. Input: a1, a2,...,an, where n is the length of the sequence. Output: count = the number of duplicate pairs. count := 0 For i = 1 to n For j = i+1 to n If ( ai = aj ), count := count +1 End-for End-for Return( count ) Answers: O left parenthesis n squared right parenthesis O left parenthesis n right parenthesis O left parenthesis n cubed right parenthesis O left parenthesis 1 right parenthesis Response Feedback: Student shall know big O notation. Also Big capital omega space a n d space B i g space capital theta. Be able to analyze the run time of a given algorithm.

O left parenthesis n squared right parenthesis

What is the worse case run time for following algorithm? MaximumSubsequenceSum Input: a1, a2,...,an n, the length of the sequence. Output: The value of the maximum subsequence sum. maxSum := 0 For i = 1 to n thisSum := 0 For j = i to n thisSum := thisSum + aj If ( thisSum > maxSum ), maxSum := thisSum End-for End-for Return( maxSum ) Answers: O left parenthesis 1 right parenthesis O left parenthesis n squared right parenthesis O left parenthesis n space log n right parenthesis O left parenthesis n right parenthesis Response Feedback: Student shall know big O notation. Also Big capital omega space a n d space B i g space capital theta. Be able to analyze the run time of a given algorithm.

O left parenthesis n squared right parenthesis

What is the time complexity of Build Heap operation. Build Heap is used to build a max(or min) binary heap from a given array. Build Heap is used in Heap Sort as a first step for sorting. Answers: O(log n) O(n^2) O(n) O(n log n) Response Feedback: Student shall know heap algorithms, properties, insert, and delete, and the run time. May study at http://www.geeksforgeeks.org/heap-data-structure/

O(n)

What is the worst case time complexity for search, insert and delete operations in a general Binary Search Tree? Answers: O(log n) for search ; O(n) for delete and insert O(n) for all O(log n) for all O(log n) for search and insert; O(n) for delete Response Feedback: Students shall be able to trace a binary search tree, do insert, delete algorithms, and their run time. May study at http://www.geeksforgeeks.org/binary-search-tree-data-structure/

O(n) for all

Which of the following is true about pure virtual functions? 1) Their implementation is not provided in a class where they are declared. 2) If a class has a pure virtual function, then the class becomes abstract class and an instance of this class cannot be created. Answers: Both 1 and 2 are correct Only 1 is correct Only 2 is correct Neither 1 nor 2 is correct Response Feedback: Students shall understand virtual function, pure virtual function, and abstract class. May study https://en.wikipedia.org/wiki/Virtual_function

Only 2 is correct

Suppose we run Dijkstra's single source shortest-path algorithm on the following edge weighted directed graph with vertex P as the source. In what order do the nodes get included into the set of vertices for which the shortest path distances are finalized? Answers: P, Q, T, R, U, S P, Q, R, U, S, T P, Q, R, S, T, U P, Q, R, U, T, S Response Feedback: Student needs to know types of graph, the representation of a graph, the algorithms related to the graph. May study at http://www.geeksforgeeks.org/graph-data-structure-and-algorithms/

P, Q, R, U, S, T

Which of the following statement(s)is / are correct regarding Bellman-Ford shortest path algorithm? P: Always finds a negative weighted cycle, if one exists. Q: Finds whether any negative weighted cycle is reachable from the source. Answers: Q only P only Neither P and Q Both P and Q Response Feedback: Student needs to know types of graph, the representation of a graph, the algorithms related to the graph. May study at http://www.geeksforgeeks.org/graph-data-structure-and-algorithms/

Q only

In AVL tree insert, suppose node w has been inserted by performing standard Binary Search Tree insertion. Starting from w, travel up and find the first unbalanced node. Let z be the first unbalanced node, y be the child of z that comes on the path from w to z and x be the grandchild of z that comes on the path from w to z. Assume the subtree rooted at z as following (here T1, T2, T3, and T4) are subtrees. What shall you do to pre-balance the AVL tree? Answers: Left Rotate z Right Rotate z Left Rotate y then Right Rotate z Right Rotate y then Left Rotate z Response Feedback: Student shall know AVL insertion, rotation, and property. May study at http://www.geeksforgeeks.org/avl-tree-set-1-insertion/ May use to https://www.cs.usfca.edu/~galles/visualization/AVLtree.html visualize.

Right Rotate z

What will be the output of following piece of code? System.out.println("/"Hello World/""); Answers: "Hello World" Hello World Run time error Syntax Error Response Feedback: The students shall know the escape characters. \n, \t, \", and \\

Syntax Error

In the following function template, what must be TRUE in order to use the function with a given data type? template <class T> int smallest( T array[], int size) { int small=0, i; for(i=0;i<size;i++) { if(array[i] < array[small]) small=i; } return small; } Answers: The data type must have a < operator defined for it. The data type must be a pre-defined data type. The data type must be numeric. The data type must be character based. Response Feedback: Students shall understand how to write and use template functions

The data type must have a < operator defined for it.

Which of the following should be virtual if a base class uses dynamic memory allocation? Answers: The destructor The copy constructor all public functions The constructor Response Feedback: Students shall understand the destructor, constructor, and the call order when create an object and when destroy an object

The destructor

In a room there are only two types of people, namely Type 1 and Type 2. Type 1 people always tell the truth and Type 2 people always lie. You give a fair coin to a person in that room, without knowing which type he is from and tell him to toss it and hide the result from you till you ask for it. Upon asking, the person replies the following: "The result of the toss is head if and only if I am telling the truth.‍ Which of the following options is correct? Answers: If the person is of Type 2, then the result is tail The result is head The result is tail If the person is of Type 1, then the result is tail Response Feedback: Study the Quiz questions and understand the answers http://www.geeksforgeeks.org/propositional-and-first-order-logic-gq/

The result is head

Which of the following is True about AVL tree? Answers: The worst time for insert is O(n) The worst time for delete is O(n) The worst time for insert and delete are both O(log n) The worst time for insert and delete are both O(n) Response Feedback: Student shall know AVL insertion, rotation, and property. May study at http://www.geeksforgeeks.org/avl-tree-set-1-insertion/ May use to https://www.cs.usfca.edu/~galles/visualization/AVLtree.html visualize.

The worst time for insert and delete are both O(log n)

Let G be a weighted undirected graph and e be an edge with maximum weight in G. Suppose there is a minimum weight spanning tree in G containing the edge e. Which of the following statements is always TRUE? Answers: There exists a cycle in G having all edges of maximum weight All edges in G have the same weight Edge e cannot be contained in a cycle. There exists a cutset in G having all edges of maximum weight. Response Feedback: Student needs to know types of graph, the representation of a graph, the algorithms related to the graph. May study at http://www.geeksforgeeks.org/graph-data-structure-and-algorithms/

There exists a cutset in G having all edges of maximum weight.

Suppose that I have function void myswap(int *x, int *y){ int temp = *x; *x = *y; *y = temp; } what will be the output of the following code segment? int x = 5, y = 10; myswap(x, y); cout << x << ", " << y; Answers: 5, 10 There is a syntax error 10, 5 There is a run time error Response Feedback: Students shall be able to write and use functions with pointer argument and can write and call functions that pass by reference

There is a syntax error

What is the output of the following code if user typed: 1 2 3 then hit Enter Key? (there are spaces between numbers) Scanner input = new Scanner(System.in); int x = input.next(); System.out.println(x); Answers: There is a syntax error 1 There is run time error 123

There is a syntax error

What is the output of the following code? BigDecimal d1 = new BigDecimal("1.11"); BigDecimal d2 = new BigDecimal("2.22"); System.out.println(d1 + d2); Answers: 1.112.22 1.11+2.22 3.33 There is a syntax error Response Feedback: Student shall know the BigInteger and BigDecimal classes, which belong to java.math package.

There is a syntax error

What is the output of the following piece of code? for(int i = 0; i < 5; i++); cout << i << ", "; Answers: 6, 0, 1, 2, 3, 4, 5, There is a syntax error 4, 0, 1, 2, 3, 4, 5, 6, Response Feedback: Students shall know syntax and semantics of for loop, while loop, and do while loop

There is a syntax error

What is the output of the following piece of code? int i = 0; do{ cout << i << ", "; }while (++i <= 5) Answers: 6, 5, This is an infinity loop, nothing output There is a syntax error 1, 2, 3, 4, 5, Response Feedback: Students shall know the syntax and semantics of for loop, while loop, and do while loop.

There is a syntax error

What will be the output after the execution of the following piece of code? char grade = 'a'; switch(grade){ case 'A', case 'a': cout <<"Excellent"; break; case 'B', case 'b': cout << "Good"; break; case 'C', case 'c': cout << "Average"; break; default: cout << "Work harder"; break; } Answers: Excellent Good Average Work harder There is a syntax error Response Feedback: Students shall pay attention to the syntax of if, if-else, if-esel if -else, and switch structure

There is a syntax error

Consider the following implementation, what is the correct? int mystrcmp(const char* str1, const char * str2){ while(*str1 != '\0' && *str2 != '\0') if(*str1++ != *str2++) break; return *str1 - *str2; } Answers: This implementation is correct. It will compare two strings as built-in strcmp function does This implementation is incorrect. The two arguments shall not be const char * This implementation is incorrect since there will be infinite loop This implementation is incorrect since there are some syntax error Response Feedback: students shall understand built-in C-string functions and know how to implement them

This implementation is correct. It will compare two strings as built-in strcmp function does

Which of the following are propositions? Answers: Give me a cup of tea, please Would you like to have a cup of tea? He likes to drink tea. This tea tastes good.

This tea tastes good.

What is the output of the following code if the value of score is 78? Assume variable score and grade has been declared as int and char, respectively. Answers: U There is a compile error in line 12 C There is a compile error in line 11

U

Which of the following is the negation of [∀ x, α → (∃y, β → (∀ u, ∃v, y))]? Answers: [∀ x, ¬α → (∃y, ¬β → (∀u, ∃ v, ¬y))] [∃ x, α → (∀y, β → (∃u, ∀ v, y))] [∃ x, α → (∀y, β → (∃u, ∀ v, ¬y))] [∃ x, α ʌ (∀y, β ʌ (∃u, ∀ v, ¬y))] Response Feedback: Study the Quiz questions and understand the answers http://www.geeksforgeeks.org/propositional-and-first-order-logic-gq/

[∃ x, α ʌ (∀y, β ʌ (∃u, ∀ v, ¬y))]

What is the output of the following Java program? Answers: Compile error in line 23 Compile error in line 17 a = 20 a = 10

a = 20

Given characteristic equation for a recurrence relation. Express the solution to recurrence relation as a linear combination of terms. (x-1)(x+2) = 0 Answers: 1 plus left parenthesis minus 2 right parenthesis to the power of n a subscript 1 plus a subscript 2 left parenthesis minus 2 right parenthesis to the power of n a subscript 1 left parenthesis minus 1 right parenthesis to the power of n plus a subscript 2 2 to the power of n left parenthesis minus 1 right parenthesis to the power of n plus 2 to the power of n Response Feedback: Student needs to know how to solve linear homogeneous recurrence relation

a subscript 1 plus a subscript 2 left parenthesis minus 2 right parenthesis to the power of n

Assume char c = 'A'; Which of the following change value of c to 'a'? Answers: c = Character.toLowerCase(c); c = c.toLowerCase(); Character.toLowerCase(c); c.toLowerCase(); Response Feedback: Student shall know all eight wrapper classes in Java

c = Character.toLowerCase(c);

If we use binary search algorithm to search 5 4 8 9 21 15 19 20 25 28 32 35 36 48 52 for key 17, list the elements that will be compared with key in order of when the comparison happens Answers: cannot use binary search algorithm because the key is not in the array 20 9 15 19 cannot use binary search algorithm since the array to be searched is not sorted 1 8 15 Response Feedback: Students need to know how to apply linear search and binary search algorithms

cannot use binary search algorithm since the array to be searched is not sorted

Which of the following declare and initialize a character type variable name grade with value 'A'? Answers: char grade = "A" char grade = A; char grade = 'A'; char grade = "A"; Response Feedback: The students shall know how to correctly declare and initialize variables of type int, char, double, and bool

char grade = 'A';

Assume that I have a Student class, and I overloaded the operators >> and << for Student class. If I want to input a Student object from keyboard, which of the following code is correct? Assume the Student object variable name is s. Answers: cin >> s; cout << s; s >> info; Cannot do it Response Feedback: The student shall know how to oeverload operators +, -, *, /, >>, and <<. if it is needed

cin >> s;

Which statement can never be reach in following code? #include <iostream> using namespace std; int main() { int x = -1; try { cout << "Before throw \n"; if (x < 0) { throw x; cout << "After throw \n"; } } catch (int x ) { cout << "Caught Exception \n"; } cout << "After catch \n"; return 0; } Answers: cout << "Before throw \n"; cout << "After throw \n"; cout << "After catch \n"; cout << "Caught Exception \n"; Response Feedback: Students shall understand how exception is handled

cout << "After throw \n";

Which of the following are best code to continue if the file open fails Answers: cout << "Cannot open file. Exit the progam"; exit(1); cout << "Cannot open file. Exit the progam"; exit(0); exit(0); exit(1); Response Feedback: Students need to know how to open a file to read or write and handle the situation that file open fails

cout << "Cannot open file. Exit the progam"; exit(1);

If x and y are both even, then x + y is even. Proof: Assume that x = 2m, y = 2n, then x + y = 2 (m + n) which is even. The above proof method is: Answers: direct proof proof by contrapositive proof by mathematical induction proof by contradiction Response Feedback: Student shall know five proof skills. Direct proof, proof by contradiction, proof by cases, proof by contrapositive, and proof by mathematical indcution

direct proof

Which of the following method is NOT a method in Double class? Answers: static Diouble valueOf(double) static Diouble valueOf(String) double valueOf(String) String toString()

double valueOf(String)

Which of the following Boolean function represents the following circuit? Answers: f left parenthesis x comma space y comma space z right parenthesis equals top enclose x space plus space y space plus top enclose y z f left parenthesis x comma space y comma space z right parenthesis space equals space left parenthesis top enclose x plus y right parenthesis top enclose x z f left parenthesis x comma space y comma space z right parenthesis space equals space left parenthesis top enclose x z space plus top enclose y right parenthesis z f left parenthesis x comma space y comma space z right parenthesis space equals space top enclose left parenthesis top enclose x plus y right parenthesis end enclose space plus space y z (There is a short bar on top of x) Response Feedback: Students need to know the relationship between Boolean function and circuit

f left parenthesis x comma space y comma space z right parenthesis space equals space left parenthesis top enclose x plus y right parenthesis top enclose x z

Design a circuit from a description of the circuit in English. The output is 1 if all three inputs are 1 Answers: f left parenthesis x comma space y comma space z right parenthesis space equals space x y top enclose z space plus space top enclose x y z space plus space x top enclose y z f(x, y, z) = x + y + z f(x, y, z) = xy + yz + zx f(x, y, z) = xyz Response Feedback: Student shall be able to design a circuit

f(x, y, z) = xyz

What is the output of the following Java progam? Answers: false true Compile error in line 4 Compile error in line 10

false

Which one of the following hash functions on integers will distribute keys most uniformly over 10 buckets numbered 0 to 9 for i ranging from 0 to 2020? Answers: h left parenthesis i right parenthesis space identical to i squared space left parenthesis m o d space 10 right parenthesis h left parenthesis i right parenthesis space identical to i cubed space left parenthesis m o d space 10 right parenthesis h left parenthesis i right parenthesis space identical to left parenthesis 11 cross times i squared right parenthesis space left parenthesis m o d space 10 right parenthesis h left parenthesis i right parenthesis space identical to left parenthesis 12 cross times i squared right parenthesis space left parenthesis m o d space 10 right parenthesis Response Feedback: Students need to know hash with open addressing and separate chaining. May study at http://www.geeksforgeeks.org/data-structures/

h left parenthesis i right parenthesis space identical to i cubed space left parenthesis m o d space 10 right parenthesis

What is miss from the outer loop head in following insertion sort algorithm? void insertionSort(int arr[], int n) { int i, key, j; for (______________) { key = arr[i]; j = i-1; /* Move elements of arr[0..i-1], that are greater than key, to one position ahead of their current position */ while (j >= 0 && arr[j] > key) { arr[j+1] = arr[j]; j = j-1; } arr[j+1] = key; } } Answers: i = 1; i < n - 1; i++ i = 1; i < n; i++ i = 0; i < n - 1; i++ i = 0; i < n; i++ Response Feedback: Student shall be able to trace and implement insertion sort and selection sort algorithm. May study at http://www.geeksforgeeks.org/

i = 1; i < n; i++

Consider the Node structure as following /* Node of a doubly linked list */ struct Node { int data; Node *next; // Pointer to next node in DLL Node *prev; // Pointer to previous node in DLL }; What will be the code for missing step in C++? // may need two lines of code /* Given a reference (pointer to pointer) to the head of a list and an int, inserts a new node on the front of the list. */ void push(struct Node** head_ref, int new_data) { /* 1. allocate new node */ /* 2. put in the data into new node */ /* 3. Make next of new node as head and previous as NULL */ /* 4. ____________________________ */ /* 5. move the head to point to the new node */ } Answers: (*head_ref)->prev = new_node; head_ref->prev = new_node; if(*head_ref != NULL) (*head_ref)->prev = new_node; if(head_ref != NULL) head_ref->prev = new_node; Response Feedback: Students shall know basic algorithms (insert after, insert in front, back, and delete) about double linked list. May Study at http://www.geeksforgeeks.org/doubly-linked-list/

if(*head_ref != NULL) (*head_ref)->prev = new_node;

If the name of the input file was in a variable named filename, which of the following is the correct way to open the input stream named inFile and associate it with this file? Answers: inFile = filename; inFile.open("filename"); inFile.open(filename); inFile = "filename"; Response Feedback: Student shall know how to open file to read or write and handle the situation that file cannot be open successfully.

inFile.open(filename);

Suppose I have the following Scanner object: File file = new File("data.txt") Scanner input = new Scanner(file); After I read data from file, which of the following close the file? Answers: input.close(); input.close(file); file.close(input); file.close() Response Feedback: Student shall know how to create and use a Scanner object to read from a file

input.close();

Which of the following code calculate the sum of all elements in given array int a[SIZE}; where SIZE is an int constant that has been initialized. Assume a has been initialized. Answers: int result = 0; for(int i = 0; i < SIZE; i++) result *= a[i]; int result = 0; for(int i = 0; i < SIZE; i++) result += a[i]; int result = 1; for(int i = 0; i < SIZE; i++) result *= a[i]; int result; for(int i = 0; i < SIZE; i++) result += a[i]; Response Feedback: Student shall know array declaration, initialization, and the algorithm related to array, for instance, find max, min, sum, and product of array elements. be able to search and sort array

int result = 0; for(int i = 0; i < SIZE; i++) result += a[i];

Which of the following doesn't have 5 as output? Answers: int x = 5; cout << ++x; cout << 40%7; int x = 5; cout << x++; cout << 40/7; Response Feedback: The students shall know operators +, -, *, /, %, ++, --, and their precedence.

int x = 5;

BigInteger class belongs to which of the following package? Answers: java.lang java.math java.io java.util Response Feedback: Students shall know the often used classes and their packages. For instance, System, Math, String, Scanner, Integer (and other seven wrapper classes), BigInteger, BigDecimal.

java.math

Prove that 1 cross times 2 plus 2 cross times 3 plus... plus n cross times left parenthesis n plus 1 right parenthesis equals fraction numerator n left parenthesis n plus 1 right parenthesis left parenthesis n plus 2 right parenthesis over denominator 3 end fraction If we proof by mathematical induction, what will be the assumption for the inductive step? Answers: 1 cross times left parenthesis 1 plus 1 right parenthesis equals fraction numerator 1 left parenthesis 1 plus 1 right parenthesis left parenthesis 1 plus 2 right parenthesis over denominator 3 end fraction 1 cross times 2 plus 2 cross times 3 plus... plus k cross times left parenthesis k plus 1 right parenthesis plus left parenthesis k plus 1 right parenthesis cross times left parenthesis k plus 2 right parenthesis space equals space fraction numerator left parenthesis k plus 1 right parenthesis left parenthesis k plus 2 right parenthesis left parenthesis k plus 3 right parenthesis over denominator 3 end fraction k is positive integer and 1 cross times 2 plus 2 cross times 3 plus... plus k cross times left parenthesis k plus 1 right parenthesis equals fraction numerator k left parenthesis k plus 1 right parenthesis left parenthesis k plus 2 right parenthesis over denominator 3 end fraction 1 cross times 2 plus 2 cross times left parenthesis 2 plus 1 right parenthesis space equals space fraction numerator 2 left parenthesis 2 plus 1 right parenthesis left parenthesis 2 plus 2 right parenthesis over denominator 3 end fraction Response Feedback: Student shall know how to proof by mathematical induction and use mathematical induction to prove recurrence relation.

k is positive integer and 1 cross times 2 plus 2 cross times 3 plus... plus k cross times left parenthesis k plus 1 right parenthesis equals fraction numerator k left parenthesis k plus 1 right parenthesis left parenthesis k plus 2 right parenthesis over denominator 3 end fraction

A large union left parenthesis B large intersection C right parenthesis space equals Answers: left parenthesis A large intersection B right parenthesis space large union left parenthesis A large intersection C right parenthesis left parenthesis A large union B right parenthesis large intersection left parenthesis A large union C right parenthesis empty set B large union C large union A Response Feedback: Student shall know set operations and set identities

left parenthesis A large union B right parenthesis large intersection left parenthesis A large union C right parenthesis

In a depth-first traversal of a graph G with n vertices, k edges are marked as tree edges. The number of connected components in G is Answers: k k+1 n-k+1 n-k Response Feedback: Student needs to know types of graph, the representation of a graph, the algorithms related to the graph. May study at http://www.geeksforgeeks.org/graph-data-structure-and-algorithms/

n-k

What will the output in file data.txt after we execute the following Java program? Answers: nothing in file HelloWorld Compile error in line 5 Hello World

nothing in file

To overload functions with symbolic names (like + - / <<), you must use the keyword ________ before the symbolic name. Answers: operator const reference void Response Feedback: The student shall know how to oeverload operators +, -, *, /, >>, and <<. if it is needed

operator

/* Given a node prev_node, insert a new node after the given prev_node */ void insertAfter(Node* prev_node, int new_data) { if (prev_node == NULL) { cout << "the given previous node cannot be NULL" << endl; return; } Node* new_node =new Node; new_node->data = new_data; new_node->next = prev_node->next; ________________________ } Fill up the missing line Answers: prev_node->next = NULL; prev_node->next = new_node; prev_node = new_node -> next; prev_node = new_node; Response Feedback: Students shall know the linked list and how to implement it. May study at http://www.geeksforgeeks.org/data-structures/linked-list/

prev_node->next = new_node;

What does the following function do? void fun(int n) { queue<int> q; q.push(0); q.push(1); for (int i = 0; i < n; i++) { int a = q.front(); q.pop(); int b = q.front(); q.pop(); q.push(b); q.push(a + b); cout << a << ", "; } } Answers: print out first n Fibonacci numbers reversely print out numbers 0 to n-1 reversely print out first n Fibonacci numbers print numbers 0 to n-1 Response Feedback: Student need to know the algorithm, implementation, and application for stack and queue. May study at http://www.geeksforgeeks.org/data-structures/

print out first n Fibonacci numbers

Consider the following C++ function: void fun(int n){ stack<int> s; while(n > 0){ s.push(n%2); n = n/2; } while(!s.empty()){ cout << s.top(); s.pop(); } } what dose this function do in general? Answers: print the binary representation of n in reverse order print the value of square root of n print the value of square root of n in reverse order print the binary representation of n Response Feedback: Student need to know the algorithm, implementation, and application for stack and queue. May study at http://www.geeksforgeeks.org/data-structures/

print the binary representation of n

For every integer n, if n2 is an odd, then n is odd. What is the best way to proof the above statement? Answers: proof by cases proof by mathematical induction Direct proof proof by contrapositive Response Feedback: The student shall know five proof skills: Direct proof, proof by contrapositive, proof by contradiction, proof by cases, and proof by mathematical induction. For this problem, shall proof by contrapositive. That is to prove that if n is even, then n squared is even. Suppose that n = 2m, then n squared equals left parenthesis 2 m right parenthesis squared equals 4 m squared space w h i c h space i s space e v e n

proof by contrapositive

Which of the following is the correct head of main function in java? Answers: public static void main(String args) public static void main(String [] args) public static int main(String [] args) public void main(String [] args) Response Feedback: Student shall know the head of main function, which is an entry point of a project

public static void main(String [] args)

Which of the following is not a stable sort? Answers: quick sort merge sort Insertion sort selection sort Response Feedback: Students shall understand the quick sort, merge sort, insertion sort, and selection sort. Also know their run time and the stability. May study at http://www.geeksforgeeks.org/

quick sort

Suppose we have Random rand = new Random(); Which of the following expression generates a random integer between 20 and 100, inclusive? Answers: rand.nextInt() % 81 rand.nextInt() % 80 rand.nextInt() % 81 + 20 rand.nextInt() % 80 + 20 Response Feedback: Student shall know how to use random method in Math class and nextInt, nextDouble methods in Random class to generate random numbers in give range.

rand.nextInt() % 81 + 20

You are given pointers to first and last nodes of a singly linked list, which of the following operations are dependent on the length of the linked list? Answers: remove the first element of the list insert in front of the list remove the last element of the list add new element at the end of the list Response Feedback: Students shall know the linked list and how to implement it. May study at http://www.geeksforgeeks.org/data-structures/linked-list/

remove the last element of the list

Fibonacci sequence is defined as following: f subscript 1 space equals space 1 comma space f subscript 2 equals 1 comma space f subscript n space end subscript equals space f subscript n minus 1 end subscript plus f subscript n minus 2 end subscript space w h e n space n space greater or equal than 3. Write a recursive function, take positive integer n as input, return nth Fibonacci number. What is placed in _____________ int fibonacci(int n){ if(n == 1 || n == 2) _____________ return fibonacci(n-1)+fibonacci(n-2); } Answers: int result = 1; return 0; return 1; return 2; Response Feedback: Students shall be able to write and trace recursive algorithm

return 1;

The following propositional statement (P → (Q v R)) → ((P ^ Q) → R) is: Answers: a contradiction valid satisfiable but not valid Response Feedback: Students may study logic and practice at http://www.geeksforgeeks.org/propositional-and-first-order-logic-gq/

satisfiable but not valid

Which of the following mystrlen is the best implementation? Answers: size_t mystrlen(const char * source){ size_t result = 0; while(*source != '\0') result++; return result; } size_t mystrlen(const char * source){ size_t result = 0; while(*source++ != '\0') result++; return result; } size_t mystrlen(char * source){ size_t result = 0; while(*source != '\0'){ result++; source++; } return result; } size_t mystrlen(const char * source){ size_t result = 0; while(*++source != '\0') result++; return result; } Response Feedback: Students shall understand the built in C-string functions such as strlen, strcat, strcpy, strcmp, strncpy, strncat, and their implementations

size_t mystrlen(const char * source){ size_t result = 0; while(*source++ != '\0') result++; return result; }

Which assignment statements will copy the value " toaster" into a string variable (str1)? Answers: strcpy(str1,"toaster"); str1 += toaster; str1 = toaster; str1 = "toaster"; Response Feedback: Students shall know the difference between C-string and string. Shall study the class string and related examples at http://www.cplusplus.com/reference/string/string/

str1 = "toaster";

Assume that char name[80] = "John Doe"; char nameCopy[80]; Whihc of the following assign "John Doe" to nameCopy? Answers: strcpy(name, nameCopy); nameCopy = name; name = nameCopy; strcpy(nameCopy, name); Response Feedback: Students shall know how to do C-string assignment, copy, comparison, query length, and concatenate.

strcpy(nameCopy, name);

Which of the following is correct definition for Student structure which is used in LinkedList that stores student's info: id, gpa, name? Answers: struct Student{ int id; double gpa; string name; Student* next; } structure Student{ int id; double gpa; string name; Student* next; }; struct Student{ int id; double gpa; string name; Student next; }; struct Student{ int id; double gpa; string name; Student* next; }; Response Feedback: The students are require to know how to write and use struct

struct Student{ int id; double gpa; string name; Student* next; };

Assume that I have a structure: struct Student{ string name; int id; double gpa; Student* next; }; Student *student = new Student; How to I assign the student gpa as 3.85? Answers: student-gpa = 3.95; student'gpa = 3.95; student->gpa = 3.95; student.gpa = 3.95; Response Feedback: Know how to write and use struct

student->gpa = 3.95;

Which of the following access a variable named next in structure *student ? Answers: student->next student'next student student-next Response Feedback: know how to write and use struct

student->next

What is the output of the following Java progam? Answers: Compile error in line 7 true false Compile error in main function

true

Suppose that the base class has a private attribute int id; then which of the following methods the child class will use to manipulate id? Answers: int getId() const; void setId(int _id); int setId(int _id); void getId() const; Response Feedback: Students shall know how to write Child class. Understand the virtual methods, and the accessibility of parent class' methods and attributes

void setId(int _id);

By the law of Boolean Algebra, x top enclose y plus x y space equals Answers: top enclose x y y xy x Response Feedback: Student shall know basic Boolean operations, Boolean functions, and gates

x

What is the output of the following Java code? Answers: Compile error in mySwap method Compile error in main method x = 20 y = 10 x = 10 y = 20

x = 10 y = 20

Which boolean function derived from following table? x y f(x, y) 0 0 1 0 1 0 1 0 0 1 1 1 Answers: y x y space plus space top enclose x y top enclose x y space plus space top enclose y x x y space plus space top enclose x space top enclose y Response Feedback: Student shall know basic Boolean operations, Boolean functions, and gates

x y space plus space top enclose x space top enclose y

Simplify the following Boolean Expression: (x+y)xy + xz Answers: xyz z(x+y) x(y+z) y(x+z) Response Feedback: Student shall know Laws of Boolean Algebra and relationship between Boolean function and circuit

x(y+z)

Use the following selection sort to sort int array {2, 5, 3, 6, 4, 1}, Right after i is increased to 3, before the next outer loop, what is the array? void selectionSort(int arr[], int n) { int i, j, min_idx; // One by one move boundary of unsorted subarray for (i = 0; i < n-1; i++) { // Find the minimum element in unsorted array min_idx = i; for (j = i+1; j < n; j++) if (arr[j] < arr[min_idx]) min_idx = j; // Swap the found minimum element with the first element swap(&arr[min_idx], &arr[i]); } } Answers: {1, 5, 3, 6, 4, 1} {1, 2, 3, 4, 6, 5} {1, 2, 3, 6, 4, 5} {2, 5, 3, 6, 4, 1} Response Feedback: Student shall be able to trace and implement insertion sort and selection sort algorithm. May study at http://www.geeksforgeeks.org/

{1, 2, 3, 6, 4, 5}

Suppose that A = {1, 2, 3, 4, 5, 6}, B = {3, 4, 5}, C = {1, 2, 4}, what is A minus left parenthesis B minus C right parenthesis ? Answers: empty set {4, 5} {6} {1, 2, 4, 6} Response Feedback: Student shall know set operations and set identities

{1, 2, 4, 6}

Suppose that we use merge sort algorithm to sort the following array: {3, 6, 1, 7, 2, 8, 5, 4}. What will be the array right before the last call of merge? Answers: {1, 3, 6, 7, 2, 4, 5, 8} {2, 4, 5, 8, 1, 3, 6, 7} {3, 6, 1, 7, 2, 8, 4, 5} {1, 2, 3, 4, 5, 6, 7, 8} Response Feedback: Students shall understand the quick sort, merge sort, insertion sort, and selection sort. Also know their run time and the stability. May study at http://www.geeksforgeeks.org/

{1, 3, 6, 7, 2, 4, 5, 8}

Which of the following is the head of destructor of Employee class? Answers: ~Employee(Employee& other) ~Employee(const Employee& other) void ~Employee() ~Employee() void ~Employee(const Employee& other) void ~Employee(Employee& other) Response Feedback: Students are required to know how to write big three: Copy constructor, Destructor, and Assignment Operator for a class

~Employee()

Which one of these first-order logic formula is valid? Answers: ∀x∃y P(x, y) => ∃y∀x P(x, y) ∃x(P(x) ∨ Q(x)) => (∃xP(x) => ∃xQ(x)) ∃x(P(x) ∧ Q(x)) <=> (∃xP(x) ∧ ∃xQ(x)) ∀x(P(x) => Q(x)) => (∀xP(x) => ∀xQ(x)) Response Feedback: Study the Quiz questions and understand the answers http://www.geeksforgeeks.org/propositional-and-first-order-logic-gq/

∀x(P(x) => Q(x)) => (∀xP(x) => ∀xQ(x))


Related study sets

MKTG 409 EXAM 4 MINDTAP: Chapter 15

View Set

Skeletal System: Arm and Shoulder Bones

View Set

Ch. 31: Skin Integrity and Wound Care

View Set

EAQ: Client Needs- basic care and comfort

View Set

interior design flashcards ( BYU INTDE 041)

View Set

Sociology of Families Final Review

View Set