361 Final Multiple Choice X

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Consider the worst-case time complexity of a pointer-based double linked list. __ a) Insert/delete at the beginning: O(n/2) Insert/delete at the end: O(n) Insert/delete in the middle: O(1) Structure traversal: O(1) __ b) Insert/delete at the beginning: O(n) Insert/delete at the end: O(n/2) Insert/delete in the middle: O(n) Structure traversal: O(1) __ c) Insert/delete at the beginning: O(1) Insert/delete at the end: O(1) Insert/delete in the middle: O(n/2) Structure traversal: O(1) __ d) Insert/delete at the beginning: O(n) Insert/delete at the end: O(n) Insert/delete in the middle: O(1) Structure traversal: O(n/2) __ e) Insert/delete at the beginning: O(1) Insert/delete at the end: O(1) Insert/delete in the middle: O(n/2) Structure traversal: O(n)

Insert/delete at the beginning: O(1) Insert/delete at the end: O(1) Insert/delete in the middle: O(n/2) Structure traversal: O(n)

What is the best definition of a collision in a hash table? __ a) Two entries are identical except for their keys. __ b) Two entries with different data have the exact same key. __ c) Two entries with different keys have the same exact hash value. __ d) Two entries with the exact same key have different hash values.

__ c) Two entries with different keys have the same exact hash value.

When a method call is executed, which information is not saved in the activation record? __ a) Current depth of recursion. __ b) Formal parameters. __ c) Location where the method should return when done. __ d) Local variables. __ d) All of the above

a) Current depth of recursion

The array 10 8 6 2 1 4 5 is organized into a heap (priority queue). The following array represents the heap after two delete operations have been performed __ a) 6, 5, 4, 2, 1 __ b) 6, 4, 5, 2, 1 __ c) 6, 4, 5, 1, 2 __ d) 6, 5, 4, 1, 2, __ e) None of the above

a)6, 5, 4, 2, 1

When a method call is executed, which information is not saved in the activation record? a)Current depth of recursion. b) Formal parameters. c) Location where the method should return when done. d) Local variables.

a)Current depth of recursion.

Who needs to know about the invariant of an ADT? a)Only the programmer who implements the class for the ADT. b) Only the programmer who uses the class for the ADT. c) Both the programmer who implements the class and the programmer who uses the class. d) Neither the programmer who implements the class nor the programmer who uses the class.

a)Only the programmer who implements the class for the ADT.

An array of queues can be used to implement a priority queue, with each possible priority corresponding to its own element in the array. When is this implementation not feasible? a)When the number of possible priorities is huge. b) When the number of possible priorities is small. c) When the queues are implemented using a linked list. d) When the queues are implemented with circular arrays.

a)When the number of possible priorities is huge.

Suppose that the Foo class does not have a copy constructor method. What happens when an assignment x=y; is given for two Foo objects? a)x is set to refer to a copy of y's object b) x is set to refer to the same object that y refers to c) Compiler error d) Run-time error

a)x is set to refer to a copy of y's object

Given the following array of 10 integers: 5 3 8 9 1 7 0 2 6 4. Suppose we partition this array using quick sort's partition function and using 5 fro the pivot. The result array after this partition step is: __ a) 5 3 4 2 1 0 7 9 6 8 __ b) 0 3 4 2 1 5 7 9 6 8 __ c) 3 1 0 2 4 5 8 9 6 7 __ d) 3 1 0 2 4 5 8 9 7 6 __ e) None of the above

b) 0 3 4 2 1 5 7 9 6 8

Consider the implementation of the Stack using a partially-filled array. What goes wrong if we try to store the top of the Stack at location [0] and the bottom of the Stack at the last used position of the array? __ a) Both top and pop would require linear time. __ b) Both push and pop would require linear time. __ c) The Stack could not be used to check balanced parentheses. __ d) The Stack could not be used to evaluate postfix expressions.

b) Both push and pop would require linear time.

Consider the implementation of the Queue using a circular array. What goes wrong if we try to keep all the items at the front of a partially-filled array (so that data[0] is always the front). a) The constructor would require linear time. b) The pop method would require linear time. b) The push method would require linear time. c) The empty method would require linear time.

b) The pop method would require linear time.

Suppose that some node X of a tree contains the value 1, and that the right child of node X contains the value 0, and the node X has no left child.Which of the following statements is true? a) This tree could be a binary search tree __ b) This tree could be a (MAX) heap __ c) Both A and B above __ d) Neither A nor B above

b) This tree could be a (MAX) heap

Suppose you have a list of names sorted in alphabetical order, already sorted in one of the data types below. The easiest way to print the names in reverse alphabetical order would be to use __ a) a BST __ b) a stack __ c) a queue __ d) a circular, single linked list

b) a stack

How many linked lists are used to represent a graph with n nodes and e edges, when using an edge list representation: __ a) e __ b) n __ c) e + n __ d) e * n __ e) None of the above

b) n

What is the worse case time complexity for search in a general tree? __ a) log(n) __ b) n __ c) n log(n) __ d) n2 __ e) None of the above

b) n

Consider a hash table with linear probing and a size of 9. Use the hash function "k%9". Insert the keys: 5, 29, 20, 0, 27 and 18 into the hash table in that order. The resulted table is: __ a) 0, 27, 29, 20, 5, 18 __ b)0, 27, 29, 20, 18, 5 __ c)0, 27, 29, 18, 20, 5 __ d)5, 29, 20, 0, , , 27, , 18 __ e) None of the above

b)0, 27, 29, 20, 18, 5

Which of the following stack operations could result in stack underflow? a) empty b)pop c) push d) Two or more of the above answers

b)pop

Suppose the height of a binary tree with one node is defined to be 0. A full complete binary tree of height h has __ a) 2h+1 edges. __ b) 2h+1 − 1 edges. __ c) 2h+1 − 2 edges. __ d) 2h+1 + 2 edges. __ e) None of the above

c) 2h+1 − 2 edges.

Consider this method declaration: void quiz(int i) { if (i > 1) { quiz(i / 2); quiz(i / 2); } cout << "*"; } How many asterisks are printed by the method call quiz(5)? __ a) 3 __ b) 4 __ c) 7 __ d) 8 __ d) None of the above

c) 7

Suppose f(n) = 3n3 + 2n2 + n. Consider these statements: I f(n) = O(n3). II f(n) = O(n4). __ a) Only I is true. __ b) Only II is true. __ c) I and II are both true. __ d) I and II are both false. __ e) None of the above

c) I and II are both true

Which of the following sorting algorithms does not require O(n2) steps in the worst case? __ a) insertion sort __ b) selection sort __ c) heap sort __ d) shell sort __ e) quicksort

c) heap sort

You are the county clerk. You receive death records from the towns in the county in batches throughout the year. Which is the best sort to use: __ a) insertion sort __ b) quicksort __ c) mergesort __ d) heap sort

c) mergesort

Suppose that the Foo class does not have an equals method. What happens when an expression x==y; is evaluated for two Foo objects? a) The expression is true if x and y refer to the same object b) The expression is true if x and y refer to objects with the same values c)Compiler error d) Run-time error

c)Compiler error

What is the primary purpose of a constructor? a) To allow multiple classes to be used in a single program. b) To copy an actual argument to a method's parameter. c)To initialize each object as it is declared. d) To maintain a count of how many objects of a class have been created.

c)To initialize each object as it is declared.

A complete graph with 5 vertices has the following number of edges: __ a) 5 __ b) 6 __ c) 8 __ d) 10 __ e) 11

d) 10

What is the minimum number of nodes in a complete binary tree of height k? __ a) 2k-1 __ b) 2k-1+1 __ c) 2k-1 __ d) 2k __ e) 2k+1-1

d) 2k

Here is an infix expression: 4+3*(6*3-12). Suppose that we are using the usual Stack algorithm to convert the expression from infix to postfix notation. What is the maximum number of symbols that will appear on the stack AT ONE TIME during the conversion of this expression? a) 1 b) 2 c) 3 d) 4 e) 5

d) 4

In listing nodes in topological ordering, which is NOT a step of the algorithm. __ a) Get the indegree count for each node __ b) Verify that the node has been listed __ c) Decrement the indegree count of all a node's successors __ d) List the node that has zero indegree __ e) All of the above

d) List the node that has zero indegree

In a real computer, what will happen if you make a recursive call without making the problem smaller? a) The operating system detects the infinite recursion because of the "repeated state" b) The program keeps running until you press Ctrl-C c) The results are nondeterministic d)The run-time stack overflows, halting the program

d)The run-time stack overflows, halting the program

Suppose cursor refers to a node in a linked list (each node has data field (data) and the pointer next). What statement changes cursor so that it refers to the next node? a) cursor++; b) cursor = next; c) cursor += next; d)cursor = cursor->next;

d)cursor = cursor->next;

In the array version of the Stack class, which operations require linear time for their worst-case behavior? a) empty b) top c) pop d) push when the stack is below capacity e)None of these operations require linear time.

e)None of these operations require linear time.

In the linked-list version of the Stack class, which operations require linear time for their worst-case behavior? a) empty b) top c) pop d) push e)None of these operations require linear time.

e)None of these operations require linear time.

Order the following algorithms from best to worst in terms of their worst-case complexity (use < if the complexity is lower and <= if they are the same): selection sort, quicksort, heap-sort

heap-sort < quicksort <= selection sort

Consider the following pseudocode: declare a stack of characters while ( there are more characters in the word to read ){ read a character push the character on the stack } while ( the stack is not empty ){ pop a character off the stack write the character to the screen } What is written to the screen for the input "carpets"?

steprac


Ensembles d'études connexes

MCB chapter 12 DNA replication and mainpulation

View Set

Fundamental of Nursing Ch7: Legal Dimensions of Nursing Practice

View Set

Contracts Administration Mid-Term Review

View Set