You are on page 1of 68

C++

Ti liu ch mang tnh cht tham kho, cm sao chp di mi hnh thc #: khut cu hi hoc p n C ver. 2010 Ngun: http://www.dsangcse.freevnn.com Lin h: Sangcse/0168.4543269

Cu 1: #include <iostream.h> # The result of program is a. 03 b. 13 c. 31 d. 01 Cu 2: #include <iostream.h># a. The value of x is: 0 The value of x is: 2 The value of cal is: 8 b. The value of x is: 8 The value of x is: 8 The value of cal is: 2 c. The value of x is: 8 The value of x is: 2 The value of cal is: 8 d. # Cu 3: ____ Memory is Volatitle a. Virtual b. Main c. A d. Cache Cu 4: ____ form of access is used to add and remove nodes from a queue a. FIFO, First In First Out b. LIFO, Last In First Out c. Both a) and b) d. Neither a) nor b) Cu 5: ____ method removes the value from the top of a stack

a. push() member method b. isEmpty() member method c. pop() member method d. isFull() member method Cu 6: ____ file contains the actual stack application a. StackLinkedListDemo.cpp b. QueueLinkedListDemo.cpp c. Neither a) nor b) d. None of the above Cu 7: ____ is the way you groups things together by placing one thing on top of another and then removing things one at a time from the top a. Poiter b. All of the above c. Array d. Stack Cu 8: ____ method places a value onto the top of a stack. a. push() member method b. isFull() member method c. isEmpty() member method d. pop() member method Cu 9: A Binary Search Tree is a special case of a. neither(k-ary tree) or (a binary tree) b. a binary tree c. both (k-ary tree) and (a binary tree) d. a k-ary tree Cu 10: A, B, and C are variables of type int. Which of the following segments would NOT have effect of interchanging the values of the variables A and B. a. C=B; B=A; A=C: b. C=A; A=B; B=C: c. C=A; B=A; A=B d. A=A+B; B=A-B; A=A-B: Cu 11: A pointer to a pointer a variable whose value is an ____ of another ____ variable a. Address, Pointer b. Value, address c. Both a) and b) d. Neither a) nor b) Cu 12: A tree with n nodes has a. n edges b. n - 1 edges c. none of the others d. n + 1 edges

Cu 13: A multidimensional array consists of ____ arrays defined by sets of array elements a. None of the above b. three c. two d. Two or More Cu 14: A Stack is best characterized as a. Last In First Out b. Both (Last First Out) and First In First Out c. First In First Out d. Neither (Last In First Out) and First In First Out Cu 15: A method is to be # a. Sum b. NumRight c. Diff d. Prod Cu 16: A referenced element of a ____, is removable in O(1) a. stack b. iterator c. array d. queue Cu 17: A ____ is a data structure that organizes data similar to a line in the supermarket, where the first one in line is the first one out. a. neither of them b. stacks linked list c. both of them d. queue linked list Cu 18: A queue is defined as: a. A data structure that supports addition to back, removal from front, and check on fullness/emptiness b. A collection of data that can be accessed only at the two ends (front and back) c. A FIFO (first-in, first-out) data structure d. All of the others answers Cu 19: A linked list index is ____ that represents the position of a node in a linked list. a. a character b. a boolean c. a variable d. An Integer

Cu 20: A Linked list can grow and shrink in size dynamically at ____ a. Ending b. Run time c. Beginning d. None of the above Cu 21: A multidimensional array consists of ____ arrays defined by sets of array elements a. None of the above b. Two or More c. three d. two Cu 22: A traversal of the binary search tree in figure is given as: 12, 27, 25, 28, 20, 38, 45, 42, 35, 30 Determine one which of the following traversals has been performed

a. Reverse PreOrder Traversal b. InOrder Traversal c. PostOrder Traversal d. # Cu 23: A simple sorting algorithm like selection sort or bubble sort has a worst-case of a. O(n^3) time, because the worst case has really random input which takes longer to sort b. On(n^2) time because sorting 1 element takes O(n) time c. O(1) time because all lists take the same amount of time to sort d. O(n) time because it has to perform n swqps to order the list Cu 24: A pedigree chart is stored in a binary tree. From the following choices, the easiest way to implement a method that will print out that pedigree chart one generation at a time (parents first, then grandparents, then great-grandparents, etc.) is to use a a. stack b. All of the above c. queue d. binary search tree

Cu 25: A rood tree is a directed graph in which each node is referenced by at most ____ node(s) a. 1 b. 0 c. 2 d. 3 Cu 26: A binary tree is a tree in which each node is referenced by at most ____ node(s) a. 2 b. 0 c. 3 d. 1 Cu 27: A preorder traversal of this tree below is

a. 30 5 20 8 1 15 12 18 10 25 35 b. 20 30 5 8 1 15 12 18 10 25 35 c. 20 30 5 1 15 12 8 18 10 25 35 d. 20 30 5 8 1 15 12 18 25 35 10 Cu 28: A searching algorithm requires at most 100n^3log(n) + 25n^5 comparisons to search an array of n elements. The worst-case time complexity for the algorithm a. 100n^3log(n) b. O(n^3) c. O(n^8) d. O(n^5) Cu 29: A particular algotithm uses #

a. 0 b. d c. b d. c Cu 30: A method is to be written to search an array for a specified item and return its index. The problem specifications do not indicate do not indicate what should be returned if the item sought

appears in more than one place in the array. Which of the following actions would be most appropriate? a. the specifications should be modified to indicate what be done if there are duplicate entries b. the method should be written so as to output an error message if there are duplicate entries c. the method should be written so as to return the index of all instances of the item d. the method should be written so as to delete duplicate entries if any are found Cu 31: After delete node 2, the node #

a. 3 b. 5 c. 7 d. 4 Cu 32: After execution of the statement: Char *p = Stuff; What would be printed by following statement? printf (%c, *p+3); a. S b. u c. f d. V Cu 33: After execution of the statement: Char *p = Stuff; What would be printed by following statement? printf (%c, *p+2); a. uff b. tuff c. Suff d. ff

Cu 34: After execution of the statement: Char *p = incoll4; What would be printed by following statement? printf (%c, *p+3); a. inc b. II4 c. k d. oII4 Cu 35: After execution of the statement: Char *p = incoll4; What would be printed by following statement? printf (%c, *p+2); a. c b. C c. n d. K Cu 36: An array is a way to reference a series of memory locations using the ____ a. Multiple names b. Same name c. different name d. Unique name Cu 37: An Algorithm that: Array is imaginary divided into two parts sorted one and unsorted one. At the beginning, sorted part is empty, while unsorted one containts whole array. At every step, algorithm finds minimal element in the unsorted part and adds it to the end of the sorted one. When unsorted part becomes empty, algorithm stops. That is a (an) ____ a. Quick sort b. Selection Sort c. Insertion Sort d. Bubble sort Cu 38: An Algorithm that: 1. Compare each pair of adjacent elements from the beginning of an array and, if they are in reversed order, swap them. 2. If at least one swap has been done, repeat step 1 That is a (an) ____ a. Selection Sort b. Bubble sort c. Insertion Sort d. Quick sort Cu 39: An Algorithm that:

Array is imaginary divided into two parts sorted one and unsorted one. At the beginning, sorted part contains first element of the array and unsorted one contains the rest. At every, algorithm takes first element in the unsorted part and inserts it to the right place of the sorted one. When unsorted part becomes empty, algorithm stops. That is a (an) ____ a. Insertion Sort b. Quick sort c. Selection Sort d. Bubble sort Cu 40: An inorder traversal of this tree is

a. 8 5 1 30 12 15 18 20 25 10 35 b. 8 5 1 30 12 18 20 25 10 35 15 c. 5 1 30 12 8 15 18 20 25 10 35 d. 8 5 1 12 15 18 20 30 25 10 35 Cu 41: Arrange the following functions, often used to represent complexity of algorithms in order from slowest to fastest O(1), O(n), O(n*log2 n), O(log2 n), O(n^2), O(2^n) a. 2^n n*log n n^2 n log n 1 b. n*2 2^n n*log n n log n 1 c. n*log 2^n n^2 n n log n 1 d. 2^n n^2 n*log n n log n 1 Cu 42: Assume that Algorithm Test has a time complexity O(n^3), and that Algorithm Compute has time complexity O(n^2). What is the time complexity of the following algorithm? Execute Algorithm Test For 5 trials, execute Algorithm Compute Execute Algorithm Test a. O(n^18) b. O(n^3) c. O(n^16) d. O(n^2) Cu 43: Big-O notation gives an approximate measure of an algorithms computing time: a. for a large number of inputs b. for any machine used c. All of the others answers d. for various language used Cu 44: Based on the following code segment: # Cout<< newNum;

The output of the this segment is (all variables are of type int)? a. 7580 b. 758 c. 857 d. 8570 Cu 45: char *ptGrade; which is the data type in this declaration? a. The data type in this is Char b. int c. long int d. All of the above Cu 46: Consider the following code: void negate (int& x) { x = -1 * x; } What would happen during a call negate(&y); in main? (y is an integer variable.) a. x is negated, y is not b. y is negated, x is not c. This code will not correctly compile d. Both x and y are negateed Cu 47: # a. 4 b. 5 c. 2 d. 1 Cu 48: Consider the following code: void negate (int x) { x = -1 * x; } What would happen during a call negate(&y); in main? (y is an integer variable.) a. x is negated, y is not b. This code will not correctly compile c. Both x and y are negateed d. y is negated, x is not

Cu 49: Consider the following code: void negate (int& x) { x = -1 * x; } What would happen during a call negate(&y); in main? (y is an integer variable.) a. y is negated, x is not b. Both x and y are negateed c. This code will not correctly compile d. x is negated, y is not Cu 50: Consider the following code given typedef int *intptr; intptr p, q r; p = new int; q = new int; *p = 10; *q := 15; r = p; p = q; q = r; Value of * p after run this segment is a. 15 b. 5 c. 10 d. 11 Cu 51: Consider the following two program segments. //SEGMENT 1 # a. 2.6 b. 3.3 c. 3.1 d. 3.6 Cu 52: Consider the following code given Typedef int *intptr; # The output would be a. 15 15 b. 15 10 c. 10 15 d. 10 10

Cu 53: Consider the following functions of n: (i) n^2 + log n; (ii) n^2 log n; (iii) 1 + 2 + + 2n; (iv) log (n!). Which one of the following function is not O(n^2)? a. (iv) only: b. (ii) only: c. (ii) and (iv): d. (iii) and (iv): Cu 54: Consider the following segment of C code: Int data[] = { 10, 20, 30}; Printf ( %u \n, data, &data[0] ) What can be used said about the result: a. The outputs would not be the same, but data and &data[0] are both addresses b. The outputs would be the same and data and &data[0]; are both addresses c. The outputs would not be the same d. The outputs would be the same, but data and &data[0] are not both addresses Cu 55: # a. steprac b. ccaarrppeettss c. serc d. carpets Cu 56: Consider the following method: pblic static void foo(int x) { cout<< + x; if (x > 0) foo(x-3); } What is the output of the method call foo(6)? a. 6 3 0 b. 6 3 c. 3 6 d. 0 3 6 Cu 57: Consider the following Sort algorithms: Quicksort, Insertion Sort, Bubble Sort Which is the fastest on an already sorted array? a. None of the other answers b. Bubble Sort c. Insertion Sort d. Quicksort Cu 58: Consider the following method: pblic static void foo(int x) {

cout<< + x; if (x > 0) foo(x-3); cout<< + x; } What is the output of the method call foo(6)? a. 0 3 b. 0 3 6 c. 6 3 d. 6 3 0 Cu 59: Consider this binary search tree. Suppose we remove the root, replacing it with something from the left subtree. What will be the root

a. 1 b. 2 c. 4 d. 5 Cu 60: Consider a binary_tree_node implementation with pointers. Which expression indicates that t represents an empty tree? a. (t = = NULL) b. (t->data() = = 0) c. (t->data() = = NULL) d. ((t->left() = = NULL) && (t->right() = = NULL)) Cu 61: # a. Indicates that more will be a pointer to a structure of type cus Type b. Is illegal because you cant use the structures name in a declaration c. Is illegal because you cant have pointers in a structure d. Indicates that more will be of type cus Type Cu 62: # a. A new structure of types cus Type would be created and its address will be placed in mine b. A new structure of type cus Type would be created and assigned a void pointer c. Nothing would happen because declaring mine in this way is illegal d. The variable mine would be declared as a structure of type cus Type and nothing else Cu 63: # a. Computer Distance To Successor b. None of the others answers is an appropriate name c. Number of Nodes

d. Pre Order travelsal methods Cu 64: Consider this AVL tree in picture Suppose we remove the node 8. What will be the new root?

a. 2 b. 10 c. 4 d. 6 Cu 65: Consider this AVL tree in picture Suppose we remove the node 4. What will be the new root?

a. 2 b. 10 c. 8 d. 6 Cu 66: Consider this AVL tree in picture Suppose we remove the node 10. What will be the new root?

a. 2 b. 10 c. 6 d. 4 Cu 67: Data in a queue is accessible a. First in First out b. Last in First out c. First in last out d. None of the above Cu 68: Dau=1; S=0; for (i=1; i<=6; i++) { S=S+Dau*I; Dau= (-Dau); }

Cout<<S<<endl; The result is a. -2 b. -4 c. 4 d. 2 Cu 69: Definitions of member functions for the LinkedList class are contained in a. LinkedList.cpp file b. LinkedListDemo.cpp file c. LinkedList.h file d. LinkedList.txt file Cu 70: deleteNode() function requires the ____ of the data element of the node that is being removed. a. variable b. declaration c. value d. reference Cu 71: Describr the running time of the following pseudocode in Big O notation: for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { a = a+ b; } } a. O(n^2) b. O(n) c. O(1) d. O(0) Cu 72: Draw a binary expression tree that stores the expression: (((a b) / c) + (d * e))

a. a b. c c. b d. d

Cu 73: During one iteration of the outer for loop of the program segment below, how many times is the body of the inner loop executed? # a. n(i-1) b. n - 1 c. i n + 1 d. n i + 1 Cu 74: # a. using over vector, ordered only by social security umber b. using two linked lists, one ordered by social security number and one by zip code c. using one vector, ordered by zip code and by social security number within each zip code d. using one vector, ordered by social security number, with records linked in zip code order Cu 75: Each entry in a linked list is called a ____ a. None of the above b. Node c. Data structure d. Link Cu 76: Entries in a stack are ordered. What is the meaning of this statement? a. A collection of Stack can be sorted b. There is a first entry, a second entry, and so on c. The entries must be stored in a linked list d. Stack entries may be compared with < operation Cu 77: Execute this code with pushes and pop method of stack s: IntStack s = new IntStack( ); push (s, 1); push (s, 2); push (s); push (s, 3); cout<<pop(p ); Value in screen will be: a. 2 b. Program Error when run this segment code c. 3 d. 1 Cu 78: Give the binary tree with root A. The root has left child B and right C. B has left child D and right child E. There are no other nodes in the tree. Which of the following is an inorder traversal of the tree a. ABCDE b. ABDEC c. DEBAC d. DBEAC Cu 79: Execute this code with pushes and pop method of stack s:

IntStack s = new IntStack( ); push (s, 1); push (s, 2); push (s); push (s, 3); push (s, 2); cout<<pop(p ); Value in screen will be: a. 2 b. 1 c. 3 d. program is breaked because of an error by Stack is empty Cu 80: Figure 2 contains two linked lists, A and B. Determine which one of the following five statements is the correct statement.

a. Both A and B can be used for the implementation of queue. A is more efficient than B for removal of data b. Only B can be used in the implementation of a queue c. Both A and B can be used in the implementation of queue. B is more efficient than A for removal of data d. Both A and B can be used in the implementation of queue, with an equivalent effciency for removal of items Cu 81: Give the binary tree with root A. the root has left child B and right child C. B has left child D and right child E. There are no other nodes in the tree. The height of the tree is a. 0 b. 3 c. 1 d. 2 Cu 82: Give the binary tree with root A. the root has left child B and right child C. B has left child D and right child E. There are no other nodes in the tree. Which of the following traversals yields ABCDE? a. All of the others answers b. inorder c. preorder d. None of the others answers Cu 83: Give binary tree and segment to add nodes into tree BinarySearchTree aTree = new BinarySearchTree ();

insert (aTree, M); insert (aTree, C); insert (aTree, A); insert (aTree, F); insert (aTree, R); insert (aTree, O); After buildingthe tree, root node will be: a. R b. A c. O d. M Cu 84: Give tree defined type: # Wich word is missing a. NodeData b. NodeLeft c. K d. NodeRight Cu 85: # a. 2, 4, 6, 8, 10 b. 10, 8, 6, 4, 2 c. 10, 2, 4, 6, 8 d. 2, 10, 8, 4, 6 Cu 86: # a. (8, 9, 2) b. (7, 9, 12) c. (8, 9, 12) d. (7,9, 2) Cu 87: # a. Junk (&1, 2, 3): Junk (fp, Mary, Sue): b. Junk (&Mary, Jules, 6): Junk (ip, Xiaolan, Mary): c. Junk (&1, 2, 3): Junk (&Mary, Jules, 6): d. Junk (fp, Mary, Sue): Junk (&Mary, Jules, 6): Cu 88: # a. logarithmic time b. quadratic time

c. linear time d. constant time Cu 89: # a. Thi will correctly pass the arguments to myProcedure by reference, not value b. The first and third answers are both correct, but not the second anser c. One could have also used myProcedure (data[0]) instead d. None of the others answers Cu 90: Given an Item pointer iptr that points to a dynamically allocated Item object, which of the following would return the dynamically allocated memory to the system? a. delete iptr: b. iptr = NULL: c. iptr->~Item(): d. delete *iptr: Cu 91: Given a 5 element stack S (from top to bottom: 2, 4, 6,8, 10), and an empty queue Q, remove the elements one-by-one from S and insert them into Q as you remove them from S, then remove them one-by-one from Q and re-insert them into S as you remove them from Q. S now looks like (from top to bottom): a. 2, 4, 6, 8, 10 b. 10, 2, 4, 6, 8 c. 2, 10, 8, 4, 6 d. 10, 8, 6, 4, 2 Cu 92: Given the following method: # In the int data type were large enough(had enough bytes) to allow this program to be executed, then at the end of the program, the value of z qould be a. 5! + 2! b. (5! + 2!)! c. (62!)/(2!) d. (7!)! Cu 93: Given an empty queue Q, what does it look like after the following operations? Enqueue (Q, 5) Enqueue (Q, 2) Enqueue (Q) Enqueue (Q, 3) Enqueue (Q) a. 5 b. none of the others c. 9 d. 3 Cu 94: Given an empty queue P, what does it look like after the following operations? Push (P, 225) Push (P, 5) Push (P, 2)

Push (P) Push (P, 3) Push (P) a. none of the others b. 5 c. 3 d. 9 Cu 95: # a. It stores the index of the smallest value of the vector into the variable index b. It stores the smallest value of the vector into the variable smallest c. It stores the index of the smallest value of the vector into the variable smallest d. It stores the smallest value of the vector into the variable index Cu 96: # a. Hooray Hip Hip b. Hooray Hip Hooray c. Hooray d. Hip Horray Cu 97: # a. None of the others answers b. Its stores the smallest value of scores into the variable index c. Its stores the smallest value of scores into the variable smallest d. It stores the index of the smallest value of scores into the variable index Cu 98: # a. Node->Left b. Node->Data c. Node->Right d. K Cu 99: Given the binary tree with root A. The root has left child B and right child C. B has left child D and right child E. there are no other nodes in the tree. The height of the tree is a. 1 b. 3 c. 4 d. 2

Cu 100: Give binary tree and segment to add nodes into tree BinarySearchTree aTree = new BinarySearchTree (); insert (aTree, M); insert (aTree, C; insert (aTree, A; insert (aTree, F; insert (aTree, R; insert (aTree, O; After buildingthe tree, root node will be: a. O b. M c. R d. A Cu 101: # a. NodePtr tmp=new Node: tmp->data = num: afterMe -> link = tmp: tmp->link afterMe -> link: b. afterMe-link = new Node; afterMe->link->data = num: afterMe -> link ->link-afterMe->link: c. NodePtr tmp=new Node: tmp-> data = num: afterMe -> link = tmp: tmp->link =NULL: d. NodePtr tmp=new Node: tmp-> data = num: tmp->link = afterMe ->link: afterMe -> link = tmp: Cu 102: # a. string[j] = = symbol for all j such that i < j b. string[j] ! = symbol for all j such that i < j c. string[j] ! = symbol for all j such that 1<=j<i d. i = = MAX Cu 103: Given the declaration below of a two-dimensional, integer array in C Int dat [3] [3] = { {1, 2, 3}, {10, 20, 30}, {100, 200, 300} }; What further can be said: a. The value *data + 1 points to the next element of the array b. None od the others answers c. The values data + 1 and *data + 1 point to the same location d. The value data + 1 points to the next row of the array Cu 104: Given the following tree. Is it an AVL tree?

a. Yes, it is AVL tree. The AVL property holds at every node b. No, it is not an AVL tree. Node 3 violates the AVL property c. No, it is not an AVL tree. Node 10 violates the AVL property d. No, it is not an AVL tree. Node 46 violates the AVL property Cu 105: # a. ptr = ptr->next: b. ptr++: c. ptr->next = ptr: d. *ptr = ptr->next: Cu 106: Giving a double linked lisy managing by pHead and pTail below: struct NODE { NODE *next; NODE *prev; int Data; }; NODE *pHead, *pTail; You want to make a function DisplayAllNodeFromEnding for display all data in nodes form the end to the begin of of the list. Select valid segment code. a. for(temp = pTail; temp != NULL; temp = temp->next) cout<<temp->Data<< ; b. for(temp = pTail; temp = = NULL; temp = temp->prev) cout<<temp->Data<< ; c. for(temp = pHead; temp != NULL; temp = temp->next) cout<<temp->Data<< ; d. for(temp = pHead; temp = = NULL; temp = temp->prev) cout<<temp->Data<< ; Cu 107: Giving code segment: # Select result after running code segment? a. 1, 2, 5 b. 1, 2, 3 c. 4, 6, 8 d. 2, 3, 5

Cu 108: # a. Code segment have error b. 6 14 c. 1 3 7 d. None of the other answers Cu 109: # a. 1 2 7 b. 2 6 1 4 c. 1 3 7 d. 3 4 5 Cu 110: # a. a=10 b=10 p=7 b. a=10 b=10 p=10 c. a=9 b=10 p=9 d. a=9 b=10 p=7 Cu 111: Giving code segement: s=90; if (s>90) t= A; if (s>=80) t= B; cout<<t; Select result after running code segment? a. A b. AB c. B d. Code segment have error Cu 112: # a. 6 12 b. 6 9 c. 12 6 d. 12 9

Cu 113: Giving code segement: int i-12, j=0; while (i>8) { i = i-1; j = j+1; } cout<<endl; Select result of (j) after running code segment? a. 11 b. 38 c. 45 d. 21 Cu 114: Giving code segement: #include <iostream.h> Void mangle_numbers(int &a, int b) { int c, d, e; a = 3; a = a+2; a = b++; a = ++b; a = a+5; e *=5; } void main() { int sum, x=5, y=7; mangle_numbers (x, y); sum=x+y; } After running code segment, value of sum is: a. 9 b. 8 c. 12 d. 10 Cu 115: Here is a small binary tree of integers. The left-most node of the right node of the root node of the tree has value. a. 40 b. 1 c. 12 d. 15

Cu 116: # a. (()())) b. (()))() c. ())(() d. ((()) Cu 117: How do you assign an address to an element of a pointer array? a. by using the address operator, which is the Double-asterisks (**), in an assignment statement b. by using the address operator, which is the ampersand (&), in an assignment statement c. Nonde of the above d. by using address operator, which is the asterisks (*), in an assignment statement Cu 118: How many parts are there in a declaration statement? a. 2 b. 4 c. 1 d. 3 Cu 119: How many times would the line do_bench () run in the following looping example: For (3 sets) { For (5 repetitions) { do_bench (); } } a. 8 b. 5 c. 15 d. 3 Cu 120: How can a node be inserted in the middle of a linked list? a. by repointing only the next elements of existing node to the new node b. by repointing the previous and the next element of existing nodes to the new node c. None of the above d. by repointing only the Previous elements of existing node to the new node Cu 121: How many swaps occur when doing an Insertion sort (to sort the values in increasing order) on the array storing 8, 7, 6, 5, 4, 3, 2, 1 and 2? a. 26 b. None of the others answers c. 27 d. 28

Cu 122: I have implemented the queue with a linked list, keeping track of a front node and a rear node with two reference variables. Which of there reference variables will change during an insertion into an EMPTY queue? a. Neither changes b. Both change c. Only front changes d. Only rear changes Cu 123: I have implemented the queue with a linked list, keeping track of a front node and a rear node with two reference variables. Which of there reference variables will change during an insertion into an NONEMPTY queue? a. Both change b. Only rear changes c. Neither changes d. Only front changes Cu 124: If Node A is proper ancestor of Node # a. Node B is inserted before Node A b. Node B is larger than Node A c. Node A is inserted before Node B d. Node A is larger than Node B Cu 125: If algorithm A has running time 7n^2 + 2n + 3, and algorithm B has running time 2n^2, and algorithm C has running time 2n^3, and algorithm D has running time 7log(n), then which algorithms have the same asymptotic time complexity. a. A and B and C b. C and D c. B and C d. A and B Cu 126: If I insert the integers 1 through # the height of the tree? a. O(n) b. O(log n) c. O(n*log n) d. O(n^1/2) Cu 127: If b is a boolean variable, then the statement b = b = = false; has what effect? a. it causes a run-time error message b. it causes a compile-time error message c. it changes the value of b if and only if b had value true just before the statement was executed d. it always changes the value of b

Cu 128: If this code fragment were executed in an otherwise correct and complete program, what would the output be? int a = 3, b = 2, c = 5 if (a > b) a = 4; if (b >c) a = 5; else a = 6; cout << a << endl; a. 4 b. 3 c. 6 d. 5 Cu 129: If the value of f(x, y, z) is always an integer, which of the following conditions ensures that the loop below terminates? while ( (f(x, y, z) != 0) <some computation> a. the value of(x, y, z) is decreased during each iteration b. x, y and z are each decreased during each iteration c. x, y and z are each increased during each iteration d. the sum of x, y, and z is decreased during each iteration Cu 130: If the characters D, C, B, A are placed in a queue (in that order), and then removed one at a time, in what order will they be removed? a. DCAB b. DCBA c. ABDC d. ABCD Cu 131: If the amout of data to be stored in a stack cannot be predicted, the best data structure to implement the stack is: a. linked list b. binary search tree c. unordered array d. None of the other answers Cu 132: If you want quick access to your data, a linked list will not be that helpful when the size of the collection is ____ a. in file b. unknow c. big d. small

Cu 133: If the depth of a tree is 3 levels, then what is the Size of the Tree? a. 8 b. 6 c. 10 d. None of the above Cu 134: If you have a node pointer named head, which is pointing to a valid node, how do you access the member variable in the node named item? a. head.item b. head->item c. (*head).item d. *head.item Cu 135: If there is a NodePtr named toDelete whose value points a valid node in the list, which of the following statements would remove the node that follows toDelete from the list and return that memory to the freestore? a. toDelete -> link = toDelete ->link ->link: delete toDelete->link: b. tmp = toDelete link: toDelete -> link = tmp -> link: delete tmp: c. tmp = toDelete link: toDelete -> link = toDelete->link->link: delete tmp: d. All of the other answers Cu 136: If p a pointer to a node in a list (node contains value 31), provide the code that would remove this node (31) from the doubly linked list freeing up the memory that is currently held. (Assume next points to the right and prev points to the left). (3 lines of code) a. delete p: p->prev->next = p->next: p->next->prev = p->prev: b. p->prev->next = p->next: p->next->prev = p->prev: delete p: c. p->prev->next = p->next: delete p: p->next->prev = p->prev: d. p->next->prev = p->prev: delete p: p->prev->next = p->next:

Cu 137: If 8 3 12 2 9 are stored in a binary search tree, the postorder traversal of that tree would be a. 12 9 8 3 2 b. 2 3 9 12 8 c. 8 3 9 2 12 d. 2 3 8 9 12 Cu 138: In a Binary Search Tree with root->element a. replace the root b. none of the other answers c. follow the right pointer d. follow the left lointer Cu 139: In the following code fragment, the programmer mistakenly placed a semicolon at the end of the For statement heading. What is the result? cout << A; for (count = 1; count <= 3; count++); count << B; count << C; a. the output ABC b. the output ABBC c. the output ABBBC d. an infinite loop Cu 140: In a Binary Search Tree, the largest element must a. have at most one child b. be a leaf c. have no child d. be the root Cu 141: In an array queue, data is stored in an ____ element. a. constructor b. array c. Node d. linked list Cu 142: In a certain card game, cards are distributed into seven separate piles. The rules of the game permit selecting a card in one pile and moving it, together with all cards on top of it, to the top of another pile. The cards that are moved are not to be reordered. Of the following data structures, which would be most appropriate to use in simulating this aspect of such a game? a. seven sets b. seven queues c. seven stacks d. seven one-dimensional vectors

Cu 143: In a quick sort, what is the distinguished item called that the list surrounds once divided into two parts? a. pivot b. center c. button d. obstruction Cu 144: Insert the following values into an initially empty # 5 12 9 13 26 8 1 6 14 23 15 Which node is the left child of the root? a. 12 b. 6 c. 5 d. 9 Cu 145: Insert the following values into an initially empty # 5 12 9 13 26 8 1 6 14 23 15 Which is the length of the path between the root and node 23? a. 1 b. 2 c. 3 d. 4 Cu 146: Insert the following values into an initially empty # 5 12 9 13 26 8 1 6 14 23 15 What are the values of the chilldren # a. null, 13 b. 6, null c. 5, null d. null, 14 Cu 147: Insert the following values into an initially empty # 5 12 9 13 26 8 1 6 14 23 15 Which many nodes have only one child? a. 5 b. 4 c. 3 d. 2 Cu 148: int j; Char c=1; j=(c<=9) && (c>=0); The value of j after running a. 3 b. 0 c. 2 d. 1 Cu 149: int result (int m, int n)

{ int j, temp = 1; for (j=1; j<=n; j++) temp *= m; return temp; } What does this method do? a. it computes the roots of a quadratic with positive coefficients and with leading coefficient 1 b. it approximates the n (th) root of m c. it computes the m (th) power of n d. it computes the n (th) power of m Cu 150: int Woe (int n, m) { if (m = = 1) return n; if (n = =m) return 1; return (Wow(n 1, m 1) + Wow (n 1, m); } Wow(5 , 2) will return which of the following? a. 1 b. 8 c. 10 d. 6 Cu 151: It is important to learn different sorting methods # a. depending on your teacher, you may have to use his/her favorite b. It isnt important, they all get the same end result c. its fun to sort using different methods d. some ways of sorting are faster then others Cu 152: It would be most appropriate to use a recursive method to solve a problem that a. involes storing data in a two-dimensional vector b. requires a lot of memory c. involves a substantial number of conditionals and nested loops d. involves evaluation of the factorial method Cu 153: Jobs sent to a printer are generally placed on a a. stack b. priority queue c. binary search tree d. queue

Cu 154: Let x and y be variables of type double with only positive values. Of the following, which best describes the condition under which the boolean expression, x + y = = x, can have the value true? a. only when x is much greater than y b. only when y > x c. only when the computer has 16-bit words d. it can never have the value true Cu 155: Let the following struct be used to create linked lists: struct listnode { int data; listnode* next; }; Let p point to the head of an existing linked list with more than one element. The following code segment is supposed insert the node pointed to by q at the end of the linked list pointed to by p? listnode* temp; temp = p; while (temp != NULL) while = temp ->next; __________= q; a. temp->data b. q->next c. temp->next d. NULL Cu 156: # a. 1 4 6 10 11 12 15 20 30 b. 15 10 4 1 6 12 11 20 30 c. 15 10 20 4 12 30 1 6 11 d. 30 20 15 10 12 11 4 6 1 Cu 157: Let C(X) be the number of leaves in a binary tree rooted at T. Assume that IsLeaf returns 1 if T is a leaf. Which of the following observations leads to a recursive implementation? a. C(T)=C(T.LEFT) + C(T.RIGHT) b. C(T)=C(T.LEFT) + C(T.RIGHT) + 1 c. C(T)=C(T.LEFT) + C(T.RIGHT) + IsLeaf(T)+1 d. C(T)=C(T.LEFT) + C(T.RIGHT) +IsLeaf(T) Cu 158: a. b. c. d. Cu 159: Let the following struct be used to create linked lists:

Struct treenode { int data; treenode* left; treenode* right; }; And function printNODE print all data in tree void printNODE(treenode *top) { if (top != ______) { printNODE (top->right); cout << top->data; printNODE(top->left); } } The missing word is: a. top b. top-right c. top->left d. NULL Cu 160: Linked list C++ application is organized into three files. They are ____, ____ and ____ a. header file, source code file, application file b. header file, footer file, source code file c. Both a) and b) d. Neither a) nor b) Cu 161: New nodes are added to the ____ of the queue. a. back b. middle c. front d. None of the above Cu 162: One difference between a queue and a stack is: a. Queues require linked lists, but stacks do not b. Queues use two ends of the structure; stacks use only one c. Satcks use two ends of the structure, queues use only one d. Stacks require linked lists, but queues do not Cu 163: ow is the front of the queue calculated? a. None of the above b. front = (front+1) % size c. front = (front+1)/size d. front = front % size

Cu 164: Parent Node is also called as ____ Node a. Branch b. Stem c. Main d. Root Cu 165: public int mystery(int k, int n) { if (n= =k) return k; else if (n > k) return mystery(k, n-k); else return mystery(k-n, n); } Based on the method defined, what is the value of mystery(6, 8)? a. 3 b. 4 c. 2 d. 8 Cu 166: Queues are referred to as ____ data structures? a. IFOF b. FIFO c. LIFO d. FILO Cu 167: Recursion has a serious disadvantage of using large amount of memory. Moreover, for most programming languages, recursion use stack store states of all currently active recursive calls. The size of a stack may be quite large, but limited. Therefore too deep recursion can result in ____ a. Memmory Overflow b. Stacks Overflow c. Haft Infinity Loop d. Out of Memmory Cu 168: Refer to this binary expression tree. Choose the algebraic expression stored in the tree

a. * + / - a b c d e b. + / a b c * d e c. + / - a b c * d e d. a b / c + * d e

Cu 169: Select INVALID way to calculate the sum of the first n even numbers (that is, 2 + 4 +6 + + 2*n) a. int sum = 0; for(int i = 1; i<=2*n; i+=1){ if(i % 2 = =0){ sum += i; } } b. int sum = 0; int i = 2; while(i%2 = =0 && i<= 2n){ sum += i; } c. int sum = 0; for(int i = 1; i<=2*n; i+=1){ if(i / 2 = =0){ sum += i; } } d. int sum = 0; for(int i = 1; i<=2*n; i+=1){ sum += i; } Cu 170: Select value of x after running code segment: void main( ) { float a[5] = {5, 4, 3, 2, 1}; float x; int i; for (i = 0; i < 5; i++) a[i] += a[0]; x = a[1] + a[4]; } a. 100 b. 25 c. 5 d. 125

Cu 171: Select result after running code segment? int i = 1; while (i <= 10) { Cout << X; i = i +3; } a. XXXX b. 1 4 7 10 X c. 1 4 7 10 d. X 1 4 7 Cu 172: Select code segment values 0 to 15 on screen a. for (int i=0; i < 15; i++) cout<<i<<endl; b. for (int i=0, i < 15; i++) cout<<i<<endl; c. for (int i=0, i <= 15; i++) cout<<i<<endl; d. for (int i=0; i <= 15; i++) cout<<i<<endl; Cu 173: Select result after running code segment? int grade1 = 75, grade2 = 85, grade3 = 95; if (grade1 <= grade2 && grade3 <= grade2) cout << A; else if (grade1 <= grade2 || grade3 <= grade2) cout <<B; else cout << C; a. B b. None of other answers c. A d. C Cu 174: Select the one FALSE statement about binary trees: a. Every node has at most two children b. Every non-root node has exactly one parent c. Every binary tree has at least one node d. Every non-empty tree has exactly one root node

Cu 175: Show the array as it is sorted in ascending order, step by step ________ 3, 2, 7, 9, 1, 6 1, 2, 7, 9, 3, 6 1, 2, 3, 9, 7, 6 1, 2, 3, 6, 7, 9 a. by Bubble sort b. by Selection sort c. by Quick sort d. by Insertion sort Cu 176: Show the array as it is sorted in ascending order, step by step ________ 3, 2, 7, 9, 1, 6 3, 3, 7, 9, 1, 6 1, 2, 3, 7, 9, 6 1, 2, 3, 6, 7, 9 a. by Bubble sort b. by Insertion sort c. by Selection sort d. by Quick sort Cu 177: Show the array as it is sorted in ascending order, step by step ________ 12, 2, 8, 5, 1, 6, 4, 15 4, 2, 8, 5, 1, 6, 12, 15 4, 2, 1, 5, 8, 6, 12, 5 1, 2, 4, 5, 6, 8, 12, 15 a. by Selection sort b. by Bubble sort c. by Quick sort d. by Insertion sort Cu 178: Show the array as it is sorted in ascending order, step by step ________ 3, 2, 7, 9, 1, 6 2, 3, 7, 9, 1, 6 1, 3, 7, 9, 2, 6 1, 2, 7, 9, 3, 6 1, 2, 3, 9, 7, 6 1, 2, 3, 7, 9, 6 1, 2, 3, 6, 9, 7 1, 2,3 , 6, 7, 9 a. by Insertion sort b. by Bubble sort c. by interchange sort d. by Selection sort

Cu 179: Show the array as it is sorted in ascending order, step by step ________ 3, 2, 7, 9, 1, 6 3, 2, 7, 1, 9, 6 3, 2, 1, 7, 9, 6 3, 1, 2, 7, 9, 6 1, 3, 2, 7, 9, 6 1, 3, 2, 7, 6, 9 1, 3, 2, 6, 7, 9 1, 2, 3 , 6, 7, 9 a. by Quick sort b. by Bubble sort c. by Insertion sort d. by Selection sort Cu 180: Suppose we have the following declarations: int x =0, y = 2; &z = y; int * p = &z; Which of the following statements is illegal? a. * p = &z: b. * p = y: c. z = *p: d. x = *p: Cu 191: Suppose we have the following declarations: const int x = 1; int y = 2; int * p = &y; const int * q = &x; Which one of the following statement is illegal? a. *p = 3: b. q = &y: c. q = p: d. p = q: Cu 182: Suppose we have the following declarations: int a [ ] = {1, 2, 3, 4}; int b [ ] = {0, 3, 6, 9}; int * p = a, *q; Which of the following assigments is illegal? a. * p = b[2]: b. q = p + 2: c. a = b: d. b[1] = p[2]:

Cu 183: # a. for (row=0; row<n-1; row++) for (colm=row; colm<n; colm++) swap(Grid, row, colm): b. for (row=0; row<n-1; row++) for (for=row+1colm<n; colm++) swap(Grid, row, colm): c. for (row=0; row<n-1; row++) for (colm=row+1; colm<n; colm++) swap(Grid, row, colm): d. for (row=0; row<n-1; row++) for (colm=0; colm<row; colm++) swap(Grid, row, colm): Cu 184: # a. f(y, x): b. f(y, &x): c. f(x, &x): d. f(&x, &y): Cu 185: Suppose that the following function. int sss(int x) { if (x % 2 = = 0) return x+1; else return (x 1)*sss(x + 1); } Determine the output of the following statement. println(sss(3)); a. 8 b. 10 c. 12 d. 9 Cu 186: Suppose cursor refers to a node in a linked list (using the IntNode struct with instance variables called data and link). What statement changes cursor so that it refers to the next nodes? a. vursor = link: b. cursor++: c. cursor = cursor.link: d. cursor += link:

Cu 187: Suppose cursor refers to a node in a linked list (using the IntNode struct with instance variables called data and link). What boolean expression will be true when cursor refers to the tail node of the list? a. (cursor.data = = null) b. (cursor.link = = null) c. (cursor = = null) d. (cursor.data = = 0.0) Cu 188: Suppose T is a binary tree with 14 nodes. What is the minimum possible depth of T? a. 4 b. 5 c. 3 d. 0 Cu 189: The following items are inserted into a AVL tree: 12, 10, 8, 5 # a. 8 b. 5 c. 10 d. 10 Cu 190: The address of the first element of an array is called the ____ of the array and the name of the array is actually a ____ to this element a. Both a) and b) b. constant pointer, base address c. base address, constant pointer d. Neither a) nor b) Cu 191: The following items are inserted into a AVL tree: 6, 2, 4, 8, 10 # a. 4 b. 2 c. 8 d. 10 Cu 192: The integer range of standard ASCII codes is: a. -128 to +127 b. 0 to 65,535 c. 0 to 127 d. 0 to 270 Cu 193: The Data type of a declaration statement tells how much ____ to reserve and the kind of ____that will be stored in that ____ location a. Memory, Data, Memory b. Address, Data, Memory c. Both a) and b) d. Neither a) nor b) Cu 194: The dereferencing operator *:

a. dereferences a pointer so that one is manipulating the value the pointer points to b. must be used to indicate the value whose address is held in a pointer c. allows one to use a pointer to gain indirect access to a value d. All of the others answers Cu 195: The type of data pointers hold is a. characters b. floating point numbers c. memory addresses d. integers Cu 196: The standard stack operation ____ adds a value to the top a stack while the standard stack operation ____ removes the top value of a stack. a. pop().push() b. push(). pop() c. new().delete() d. malloc().free() Cu 197: The ____ process places data at the back of the queue a. enqueue b. dequeue c. priority queue d. All of the above Cu 198: The pop ( ) member function determines if the stack is empty by calling the ____ member function # a. None of the others b. removeback() c. isEmpty() d. removedfront() Cu 199: The front of the stack in a stack-linked list ______ a. None of the above b. Back of the linked list c. Middle of the Linked list d. Front of the linked list Cu 200: The two operations used most commonly with a stack are _______ a. Enqueue and Dequeue b. DisplayList and Get c. Pop and Get d. Pop and Push

Cu 201: The operation for removing an entry from a stack is traditionally called: a. peek b. remove c. delete d. pop Cu 202: The isFull ( ) member method is called within the enqueue process to determine a. None of the above b. if there is room to place another item in the queue c. if there is an item in the queue to be removed d. if there is an iem the queue to be locked Cu 203: The following function. int W(int x) { if ((x % 3 = = 0) && (x > 0)) return 1 + W(4 + W(x- 3)); else if (x % 2 = = 0) return W(x + 1); return x + 2; } What value would the call W(2) return? a. 7 b. 10 c. 6 d. 8 Cu 204: The following function. public static int ttt(int x, int y) { if (x % y = = 0) return x/y + 2; else return x ttt(y, x + 1); } Determine the output of the following statement. Println(ttt(7, 3)); a. 6 b. 2 c. 15 d. 8 Cu 205: The destructor is responsible for allocating all the memory that was allocated for the linked list. a. True b. False c. Neither a) nor b) d. None of the above

Cu 206: The following function. int kkk(int x){ if((x % 3 = = 0) && (x > 0)) return 1 + kkk(4 + kkk(x 3)); else if(x % 2 = = 0) return kkk(x + 1); return x + 2; } What value would the call kkk(2) return? a. 10 b. 6 c. None of the others answers d. 8 Cu 207: The following function. int add(int x, int y) { if (x*y = = 0) return x + y; else return (x y) + add(x + 1, y-1); } Determine the output of the following statement. cout<<add(5, 3); a. 6 b. 8 c. None of the others answers d. 10 Cu 208: The meaning of the insertFirst(e) method of the List ADT is a. replace the element of the Node at the front of the List with e b. replace the node at the front of the List with Node e c. add the new Node e to the front of the List d. add a new Node with data element e at the front of the List Cu 209: The variable varFirst is a LinkNode object of a linked list. varFirst refferenced to the first node. You want to build function to check this list is empty /* @returns true if this list is empty. */ Boolean isEmpty ( ) { Return varFirst = = ______; } The missing word is: a. nothing b. varFirst.Next c. new LinkNode(); d. NULL Cu 210: The last member function is _____

a. displayNode() b. destroyList() c. tNode() d. appendNode() Cu 211: The ____ function retrieves the value of the size member of the LinkedList class a. giveSize() b. seeSize() c. getSize() d. addSize() Cu 212: The benefit of using a linked list is to ____ large amounts of data a. Integer b. Join together c. Float d. None of the above Cu 213: The following function. static int ttt(int x, int y) { if (x % y = = 0) return x/y + 2; else return x ttt(y, x + 1); } Determine the output of the following statement. println(ttt(7, 3)); a. 8 b. None of the others answers c. 10 d. 6 Cu 214: The picture is presented for one step of:

a. Quick Sort b. Selection Sort c. Bubble Sort d. Insertion Sort Cu 215: the number of swappings needed to short the numbers 8 ,22, 7, 9, 31, 5, 13 in ascending order using bubble sort is

a. 12 b. 11 c. 13 d. 14 Cu 216: the way a card game player arranges his cards as he picks them up one by one, is an example of a. merge sort b. selection sort c. insertion sort d. bubble sort Cu 217: The depth of a tree is the ____ of a tree a. Number of branches b. number of nodes on the tree c. number of levels of a tree d. All of the above Cu 218: The characters E, D, C, B, A are inserted into a queu (in the order given, E first followed by D etc), and then removed one at a time. In what order are they removed? a. A B C D E b. E A D B C c. C B D A E d. E D C B A Cu 219: # a. could be either; depends on actual placement of p is memory b. true c. false d. statement will not compile Cu 220: The root node is to be deleted from the binary search tree given figure. Which node from the left-hand subtree of node 30 would be used to replace the deleted node?

a. 27 b. 20 c. 28 d. # Cu 221: The first step in a very efficient search method to find the pattern ABCDE in a vector of single-character uppercase Strings is to look at Strings with index

a. 5,10,15. until an E is encountered b. 1,2,3. until any letter in AE is encountered c. 5,10,15. until any letter in AE is encountered d. 5,10,15. until any letter inFZ is encoutered Cu 222: The following items are inserted into a binary search tree: 8, 3, 4, 9, 5, 6, 2, 1, 7. Which item is placed at a root? a. 6 b. 7 c. 5 d. 8 Cu 223: The second item of list when traverse the tree with preorder is item:

a. E b. B c. C d. H Cu 224: The following code is binary search, to find value KEY in array # a. None of the others b. Right c. Left d. mid Cu 225: The following items are inserted into a binary search tree: 3, 6, 5, 2, 4, 7, 1. Which node is the deepest? a. 4 b. 3 c. 1 d. 7 Cu 226: The operation for adding an entry to a stack is traditionally called: a. append b. add c. insert d. push Cu 227: The tree in picture is traversed using preorder traversal, and each time a node is visited, the label for that node is printed. Which of the following would be the resulting output?

a. a b c * + b. a* + b c c. + * a b c d. + a * b c Cu 228: The following items are inserted into a AVL tree: 10, 5, 8, 12 Which item is placed at a root? a. 5 b. 12 c. 8 d. 10 Cu 229: The following items are inserted into a AVL tree: 5, 8, 10, 12 Which item is placed at a root? a. 5 b. 12 c. 10 d. 8 Cu 230: The minimem height of a binary search tree containing n nodes is: a. (int) log2 (n) b. n c. n - 1 d. no. levels + 1 Cu 231: The following items are inserted into a AVL tree: 10, 2, 4, 6, 8 Which item is placed at a root? a. 4 b. 2 c. 8 d. 10 Cu 232: a. b. c. d. Cu 233: This function use to find max in 3 integers a,b,c int findMax(int a, int b, int c) { int temp;

if (a>b) temp=a; else temp=b; if (c>______) temp=c; return temp; } The missing word is: a. temp b. a c. 0 d. b Cu 234: The isFull ( ) member method is called within the enque process to determine a. if there is an item queue to be removed b. if there is an item in the queue to be locked c. if there is room to place another item in the queue d. None of the above Cu 235: This program use to remove a element in linked list at position removalIndex # The missing word is: a. next b. pre c. ref d. data Cu 236: This segment of function Adding Elements to a Linked Structure using to add a item First into a linked lis Mylst of LinkNode type with head variable is varFirst: # a. varFirst b. element c. LinkNode d. temp Cu 237: The question are based on the following program segement that searches a vector. This vector is sorted in increasing order and contains num elements, where num is non-negative. # a. last b. first c. middle d. item Cu 238: # a. five b. four c. three d. six

Cu 239: # a. first<last b. first<=middle<=last c. (item = = list[middle]) && found d. (item = = list[middle]) | | found Cu 240: To represent hierarchical relationship between elements, which data structure is not suitable? a. Tree b. Prionrity c. Deque d. I of above Cu 241: Top-down programming is illustrated by which of the following? a. writing a program without using gotos b. writing the first lines of a program before writing the last lines c. writing and testing the lowest-level routines first and then combining these routines to form appropriate abstract operations d. writing the program in terms of abstract operations and then refining those abstract operations Cu 242: Traverse the tree with preorder.

a. A B D C E H I G F b. A D B C E G H I F c. A B D C E G H I F d. A B D C G H I E F Cu 243: # a. p = p->next; b. temp = temp.next; c. temp = temp -> next; d. temp ++;

Cu 244: #

a. afternode-prev b. afternode-next c. afternode d. newnode->next Cu 245: # a. 8 b. 5 c. 7 d. 4 Cu 246: # a. T->Left. T->Data b. T->Left. T->Right c. T->Right. T->Left d. T->Data. T->Right Cu 247: #

a. 28 b. 38 c. 25 d. 27 Cu 248: # a. cout<<temp->Data<< ;

DisplayTree(temp->Right); DisplayTree(temp->Left); b. all of the other answers c. DisplayTree(temp->Right); cout<<temp->Data<< ; DisplayTree(temp->Left); d. DisplayTree(temp->Left); cout<<temp->Data<< ; DisplayTree(temp->Right); Cu 249: Value of the first linked list index is ____ a. Zero b. -1 c. One d. None Cu 250: void tam ( ) { int i=0, n=33; While (i<n-1) { i++ if (n % i = = 0) cout<< <<I; } } The result of program is a. 11 33 b. 3 5 c. 5 11 d. 3 11 Cu 251: void tam ( ) a. 7137 b. 7731 c. 7337 d. 7645 Cu 252: We say postorder traversal of a tree when we # a. none of the others b. after we visit all its children c. in the middle of visiting all its children d. before we visit all its children Cu 253: void AlgorithmSort (int arr[], int n) { int i, j, minIndex, tmp; for (i = 0; i < n 1; i++) {

minIndex = 1; for (j = i + 1; j < n; j++) if (arr[j] < arr[minIndex]) minIndex = j; if (minIndex != i) { tmp = arr[i]; arr[i] = arr[minIndex]; arr[minIndex] = tmp; } } } The algorithm is: a. Quick sort b. Bubble sort c. Selection Sort d. Insertion Sort Cu 254: void AlgorithmSort (int arr[], int n) { Bool swaped = true; int j = 0; int tmp; while (swapped_ { swapped = false; j++; for (int i = 0; i < n j; i++) { if (arr[i] > arr[i + 1]) { tmp = arr[i]; arr[i] = arr[i + 1]; arr[i + 1] = tmp; swapped = true; } } } } The algorithm is: a. Selection Sort b. Quick sort c. Insertion Sort d. Bubble sort

Cu 255: void AlgorithmSort (int arr[], int length) { int i, j, tmp; for (i = 1; i <lengh; i++) { j = 1; while (j > 0 && arr[j 1] >arr[j]) { tmp = arr[j]; arr[j] = arr[j 1]; arr[j 1] = tmp; j--; } } } The algorithm is: a. Selection Sort b. Bubble sort c. Quick sort d. Insertion Sort Cu 256: We wish to simulate the idea of customers # fair, then best way to model this situation would # a. Both a stack *and* a Queue will work b. none of the others c. Stack d. Queue Cu 257: What is one disadvantage of representing stacks as arrays rather # a. basic operations are faster on the linked list implementation b. Pop() is an unnecessary procedure for stacks represented as arrays c. the running time of a Push() operation is slower d. if you have filled up the arraym extending its size is more of a hassle than adding a new node to # Cu 258: What will be the output of the following code? int x, y, z; x=1; y=2; z=3; int* a= &x; *a = y; cout << x << endl; a. 1 b. a memory address c. 2 d. 3

Cu 259: What is the time complexity for the following algorithm, in terms of the number of comparisons performed? if (n > 0) while (n > 0) n--; a. O(n^n) b. cannot be determined c. O(n) d. O(1) (constant time complexity) Cu 260: What is the output of the following code fragment? (loopCount is of type int.) for (loopCount = 1; loopCount > 3; loopCount++) cout << loopCount << ; cout << Done << endl; a. 1 2 3 Done b. 1 Done c. Done d. 1 2 Done Cu 261: # a. LOORX b. ROOLX c. ROOX d. LOOX Cu 262: What kind of value is assigned to the top attribute? a. Variable b. Index c. Character d. Float Cu 263: What is the value of sum after execution of the following code? (All variables are of type int.) sum = 0; for (counter = 2; counter <=5; counter++) sum = sum + 2 * counter; a. 28 b. 30 c. 10 d. 18 Cu 264: # a. 1 3 4 b. XXX c. XXXXX d. X 1 3 4 Cu 265: #

a. i = 10, j = 5 b. i = 5, j = 10 c. Nothing. The program will most likely crash d. i = 5, j =5 Cu 266: What is the least order of execution time for the following code segment, if the segment terminates without error? int i = 0, count = 0; while (i < N) { current = A[i]; while (i < N && current = = A[i]) { i++; count++ } } a. O (SQRT(N)) b. O (N) c. O (N^2) d. O (N log N) Cu 267: What is the time complexity for the following algorithm, in terms of the number of additions performed? /* assume that n is greater than 0 */ int x = 0; for(int I = (int)sqrt(n); i<n*n; i++) x = x + i; a. O(n^2log(n)) b. O(1) c. O(n^2) d. O(n) Cu 268: What is the time complexity for the following algorithm, in terms of the number of multiplications performed? a. None of the others answers b. O(nlog(n)) c. O(log(n)) d. O(log(log(n))) Cu 269: # a. creates a copy of the array a b. None of the others answers c. sorts the array a d. dynamically enlarges the array a, adding 7 to the end

Cu 270: What is the time complexity for the following algorithm, in terms of the number of additions performed? int x = 0; for (int i = n; i > 1; i = i/2) for (int j = 0; j < n*n; j++) x = x + 10; a. O(log(n)) b. None of the others answers c. O(n^2log(n)) d. O(n^4) Cu 271: : What is the time complexity for the following algorithm, in terms of the number of additions performed? int x = 0; for (int i = 0 i <n*n; i++) for (int j = 0; j < i; j++) x = x + i + 1; a. O(n^2) b. O(n^3) c. O(n^4) d. Noe of the others answers Cu 272: # a. 2200 b. 2202 c. 2020 d. 2222 Cu 273: What is least order of execution time for the following code segment, if the segment terminates without error? int i = 0, count = 0; while (i < N) { current = A[i]; while (i < N && current = = A[i]) { i++; count++ } } a. O (N log N) b. O (SWRT(N)) c. O (N^2) d. O (N)

Cu 274: # a. 11 2 52 b. 2 11 25 c. 2 5 11 2 d. 11 2 25 Cu 275: # a. 2553 b. 3335 c. 3355 d. 3553 Cu 276: What is a queue? a. Linked list b. None of the above c. A Queue is a sequential organization of data d. Array Cu 277: What is a queue? a. A Queue is a sequential organization of data b. A Queue is a non sequential organization of data c. Both a) and b) d. Neither a) nor b) Cu 278: What happends when you push a new node onto a stack? a. the new node is placed at the back of the linked list b. No Changes happends c. the new node is placed at the front of the linked list d. the new node is placed at the middle of the linked list Cu 279: What is the formula used to calculate the back of the queue? a. The back of the queue is calculated by using the following formula: back = (back+1) % size-1 b. The back of the queue id calculated by using the following formula: back = back % size c. The back of the queue is calculated by using the following formula: back = (back+1) % size d. None of the others

Cu 280: What will be the output of the following code? int x, y, z; x=1; y=2; z=3; int* a = &x; *a = y; cout << x <<endl; a. 0 b. 2 c. Unknow value d. 3 Cu 281: What kind of list is best to answer questions such as What is the item at position n? a. Doubly-linked lists b. Singly-linked lists c. Doubly-linked or singly-linked lists are equally best d. Lists implemented with an array Cu 282: What is the return value of the findNode ( ) function? a. The return value of the findNode()function is the index position of the node b. The return index of the findNode()function is the index position of the node c. Both a) and b) d. Neither a) nor b) Cu 283: What member function places a new node at the end of the linked list? a. addNode() b. displayNode() c. structNode() d. appendNode() Cu 284: What is the best case run time order of insertion sort: a. O(n^2) b. O(log n) c. O(n * log n) d. O(n) Cu 285: What is a leaf node? a. A leaf node is the last node on a branch b. A leaf node is the first node on a branch c. Both a) and b) d. Neither a) nor b) Cu 286: What is the worst-case time for binary search finding a single item in an array? a. Constant time O(1) b. Lofarithmic time O( lg n) c. Quadratic time O(n^2) d. Linear time O(n) Cu 287: What is the purpose of a left child node and right child node?

a. e left child node has a key that is less than the key of its parent node. The right child node has a key that is greater than the key of its parent node b. e left child node has a key that is greater than the key of its parent node. The right child node has a key that is less than the key of its parent node c. Both a) and b) d. Neither a) nor b) Cu 288: What is the worst-case time for serial search finding a single item in an array? a. Constant time O(1) b. Lofarithmic time O( lg n) c. Quadratic time O(n^2) d. Linear time O(n) Cu 289: # a. Counts the number of children in a binary tree b. Counts the number of leaves in a binary tree c. Determines the height of a binary tree d. Counts the number of nodes in a binary tree Cu 290: # a. postorder traversal b. nothing useful c. bylevel trversal d. inorder traversal Cu 291: What is the effect of the following statement on the linked list as given in figure. P = P->Link

a. The statement is invalid and will cause a syntax error during compilation b. The statement is valid and after the execution of the statement the link field of the node will point back to itself c. The statement is valid and after the execution of the statement p will be assigned the value null d. The statement is valid and after the execution of the statement the linked field of the node will poinnt to p Cu 292: # a. It searches the array in column order for the last occurrence of searchValue b. It searches the array in row order for the last occurrence of searchValue c. It searches the array in column order for the first occurrence of searchValue d. It searches the array in row order for the first occurrence of searchValue Cu 293: What is the effect of applying the following recursive algorithm Select to the singly linked list given in figure?

Secret (Head : NodePtr) if (Head = num) then answer is 0 else answer is 1 + Secret(Head->Link) end if end

a. The final answer is zero b. This is a traversal algorithm it only traverses the singly linked list c. The final answer is 17 the algorithm finds the total value of the data items stored in the singly linked list d. The final answer is 1 Cu 294: What is the maximum number of nodes in a binary tree with L leaves? a. 2^L b. 2^(L+1) c. None of the others answers d. there is no maximum Cu 295: What is the minimum height of a binary tree with 31 nodes? a. 3 b. 7 c. 2 d. 5 Cu 296: What is the minimum height of a binary tree with 31 nodes? a. 5 b. 6 c. None of the above d. 4

Cu 297: What is the depth of node E?

a. 4 b. 3 c. 1 d. 2 Cu 298: What is the effect of the following statement on the linked list as given in figure. P = P->Link

a. The statement is invalid and will cause an error at rum-time b. The statement is invalid and will cause a syntax error during complilation c. The statement is valid and after execution of the statement p will be assigned the value null d. The statement is valid and after execution of the statement the link field of the node will point back to itself Cu 299: When using delete newPtr: a. None of the others answers b. The newPtr itself is deleted c. The space newPtr points to is deleted d. Both are right Cu 300: When deciding on a particular algorithm to use in a program, which of the following should be taken into consideration? I. The speed of implementation for the algorithm. II. The space requirements of the algorithm. III. The ease with which the logic of the algorithm can be understood. a. III only b. I and II only c. II and III only d. I, II, and III

Cu 301: Which of the following abstract data types are NOT used by Integer Abstract Data type group? a. long b. float c. Short d. Int Cu 302: Which of the following about the above tree is # a. 5 was inserted earlier than 8 b. The height will be increased if we insert 10 c. The preorder traversal is 5 3 1 2 4 8 7 6 9 d. # Cu 303: Which of the following is not a control structure used in developing structured algorithms? a. Repetition b. Goto c. Sequence d. Selection Cu 304: Which of the following traversals alway a. depends on how the elements are inserted b. Inorder c. Preorder d. Postorder Cu 305: # a. for (count = -5; count <=5; count++) { count++; sum = sum + count; b. for (count = -5; count <=5; count++) { sum = sum + count; count++; c. for (count = 1; count <=21; count++) sum = sum + count; d. for (count = -5; count <=15; count++) sum = sum + count;

Cu 306: Which of the following statements is not true? a. Singly linked liete can Increase their sizes faster than arraays can Increase their # b. The singly-linked list does not allow you to access the nth element in constant # c. You can search for and find a value in an array in constant time d. If you mistakingly mis-assign the head pointer to NULL, you will lose the entire # Cu 307: Which data structure is used by the compiler to implement recursion? a. search tree b. queue c. stack d. priority queue Cu 308: Which of the following is not # a. Tree: root: 4 children of 4: 3,5 children 3: 2,null children of 5: null,6 b. Tree: root: 4 children of 5: null,6 c. Tree: root: 4 children of 6: 4,9 children 9: 7,null d. Tree: root: 6 children of 6: 8,9 children 9: 7,null Cu 309: Which of the following statements will not affect the value of x? a. x = x++; b. x += x--; c. x++; d. x = --x + 1; Cu 310: Which of the following returns the object pointed to by an int pointer iptr? a. &iptr b. *iptr c. iptr d. reinterpret_cast<int>(iptr) Cu 311: Which statement is correct? a. Once a tree is created, the root element cannot be deleted. b. An element can be inserted anywhere in a linked list c. An element can be inserted anywhere in a binary search # d. An element can be inserted anywhere in a stack Cu 312: Which one of the following lines of code has a run-tim error?

a. int x = 1; int *p; p =* x; b. int x, *p = &x; *p = 1; c. int x = 1; int *p = &x; d. int x = 1; int *p; p = &x; Cu 313: Which of the following returns the memory address of an int object anInt? a. anInt b. *anInt c. &anInt d. addrof(anInt) Cu 314: # a. add_weight(). add_weight(). add_weight(). do_bench().do_bench().do_bench(). do_bench().do_bench().do_bench().stretch().stretch().stretch() b. add_weight().do_bench().do_bench().do_bench().stretch(): add_weight().do_bench().do_bench().do_bench().stretch(): c. add_weight().do_bench().stretch(): add_weight().do_bench().stretch(): d. add_weight().add_weight().do_bench().do_bench().stretch(): do_bench().do_bench().do_bench().stretch().stretch(): Cu 315: Which of the following is referred to as a last-in, first-out (LIFO)? a. Linked List b. Queue c. Stack d. Tree Cu 316: Which data structure allows deleting data elements from front and inserting at rear? a. Deques b. Stacks c. Queues d. Binary search tree Cu 317: Which of the following acronyms describe the behaviour of a stack? a. FIFI b. LIFO c. LIFER d. FIFO

Cu 318: Which of the following statements is true regarding a queue? a. It may be implemented by a linked list because insertions and deletions may be from the same end b. It may be implemented by an array without providing for wrap-around c. It may be implemented by a heap because first in is first out d. It may be implemented either by an array or a linked list Cu 319: Which of the following is true of stacks and queues? a. A stack is a last-in, first-out structure, and queue is a random access structure b. A queue is a last-in, first-out structure, and stack is a first-in, first-out structure c. A stack is a last-in, first-out structure, and queue is a first-in, first-out structure d. A stack is a last-in, first-out structure, and both structures are random access structures Cu 320: Which data structure is used to check for balanced parentheses? a. priority queue b. queue c. stack d. binary search tree Cu 321: Which of the following stack operations could result in stack underflow? a. All of the others answers b. push c. pop d. is_empty Cu 322: Which of the following best describes the data structure used to keep track of function calls as your program is run? a. array b. queue c. linked list d. stack Cu 323: Which of the following operations is not effeciently supported by a singly linked list? a. accessing thr element in the current position b. insertion before the current position c. insertion after the current position d. moving to the position immediately following the current position Cu 324: Which boolean expression indicates whether the numbers intwo IntNodes (p and q) are the same? Assume that neither p nor q is null a. p = = q b. p.data = = q.data c. None of the others answers d. p.link = = q.link

Cu 325: # a. int size(Node* n) { if (n = = NULL) return 0: return 1 + size(n>pre): } b. int size(Node* n) { if (n = = NULL) return 0: return 1 + size(n: } c. int size(Node* n) { if (n = NULL) return 0: return 1 + size(n->next): } d. int size(Node* n) { if (n = = NULL) return 0: return 1 + size(n->next): } Cu 326: Which is not considered a variation of a sequential search? a. Searching an unsorted list for the first occurrence of a value b. Searching a sorted list fot the first occurrence of a value c. Searching a sorted list for all occurrences of a value d. Searching an unsorted list for the last occurrence of a value Cu 327: Which of the following algorithms, implemented as in the text, runs in O(n) time the presented with an array of n identical elements? a. All of the above b. insertion sort c. merge d. quicksort Cu 328: Which one of the following applications would not be suitable to implement using a Stack? a. A program to keep track of patients as they check into a hospital clinic, assigning each to a doctor on a first-come, first-served bases b. A program to solve a maze is to backtrack to an earlier position (the last place where a choice of direction taken was made) when a dead-end position is reached c. A program to receive a set of data that is to be saved and processed in the reverse order d. A program ro determine whether pairs of brakets in an arithmetic expression mathched

Cu 329: Which of the following are Binary Search Trees:

a. 3, 4, 5 b. 4,, 2, 7 c. 1, 2, 8 d. # Cu 330: Which of the following is true about the height of a node? a. The height of a leaf is 0 b. all of the others answers are true c. The height of an empty tree is 0 d. The height of a node is one less than the height of its parent Cu 331: Which traversal does not use a stack? a. preorder b. all of these traversals uses a stack c. posorder d. level order Cu 332: Which of the following is true about the height of a node? a. all of the others answers are true b. The height of an empty tree is 0 c. The height of a node is one less than the height of its parent d. The height of a leaf is 0 Cu 333: ____ is the way you groups things together by placing one thing on top of another and then removing things one at a time from the top a. Pointer b. Array c. All of the above d. Stack Cu 334: Which of the following data structures requires more than constant average time for insertions? a. queue b. all of the others answers have constant time insertion algorithms c. search tree d. stack

Cu 335: Which of the following statements is true about deleting the root of a binary search tree? a. the root pointer changes if it does not have two children b. the root pointer always changes c. if the root has two children, its item is replaced by the largest element in the right subtree d. All of the others answers Cu 336: Why do built-in strings in C/C++ have the type char*? a. A string is a array of characters; tha char* variable holds the starting address of the array b. char* is a sprecial expression that is understood to mean string c. A strings chracters are accessed by changing the value in the char* variable to refer to different characters in the string d. The expression char* means many characters Cu 337: Why would you use a structure? a. You use a structure to declare an instance of data group b. All of the above c. You use a structure to access parts of a data d. You use a structure to group together related data Cu 338: Why is the constructor of the QueueLinkedList class empty? a. because initialization of data members of the QueueLinkedList class is performed by the constructor of the LinkedList class. b. because initialization of data members of the QueueLinkedList class is performed by the destructor of the LinkedList class. c. because initialization of data members of the LinkedList class is performed by the destructor of the LinkedList class. d. because initialization of data members of the LinkedList class is performed by the constructor of the LinkedList class. Cu 339: You want to remove 12 from a BST. After that, the node on the right of node 5 is:

a. 19 b. 25 c. null d. 21

Cu 340: a. (data[i] != 42) && (i<n) b. (i<n) && (data[i] != 42) c. (data[i]!= 42) || (i<n) d. (i<n) ||(data[i]!= 42) Cu 341: You have random access in O(1) to every element of an _______ a. queue b. stack c. linked list d. array Cu 342: You are given a stack that holds data of type char, operations 1 and 2 where 1=Push and 2=Push and the input sequence as abcdef. What are the contents of the stack after the operation sequence: 11121221122. (Note: First element is a the bottom). a. a b. db c. ab d. The stack underflows Cu 343: You are given a sorted list. Which method is likely to give the best pefromance in sorting the numbers in the same order as they are already sorted: a. Selection Sort b. Move list to Binary Tree c. All methods have the same performance d. Insertion Sort

You might also like