Data Structures Final

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Suppose you run a O(log n) algorithm with an input size of 1000 and the algorithm requires 110 operations. When you double the input size to 2000, the algorithm now requires 120 operations. What is your best guess for the number of operations required when you again double the input size to 4000? a. 130 b. 140 c. 150 d. 160 e. 170

a. 130

There is a tree in the box at the top of this section. How many children does the root have? 14 / \ 2 11 / \ / \ 1 3 10 30 / / 7 40 a. 2 b. 4 c. 6 d. 8 e. 9

a. 2

How are loops represented in an edge-list representation of a graph? a. A vertex will be on its own edge-list. b. The edge-list will be a circular linked list. c. The edge-list will be empty for that particular vertex. d. The edge-list will be full for that particular vertex.

a. A vertex will be on its own edge-list.

Suppose that X is a B-tree leaf containing 41 entries and having at least one sibling. Which statement is true? a. Any sibling of X is also a leaf. b. Any sibling of X contains at least 41 entries. c. The parent of X has exactly 42 entries. d. X has at least 41 siblings.

a. Any sibling of X is also a leaf.

What graph traversal algorithm uses a queue to keep track of vertices which need to be processed? a. Breadth-first search. b. Depth-first search.

a. Breadth-first search.

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

a. Current depth of recursion.

Select the one FALSE statement about binary trees: a. Every binary tree has at least one node. b. Every non-empty tree has exactly one root node. c. Every node has at most two children. d. Every non-root node has exactly one parent.

a. Every binary tree has at least one node.

This question is appropriate if you studied a flood fill (which was not part of the text). Suppose that a flood fill starts at the point marked with an o in this diagram: XXXXXXXXXX XX XXXX This is row number 1 XX XX XXXX This is row number 2 XX o XXX This is row number 3 XXXXXXXXXX Suppose that the first recursive call is always left; the second recursive call is always right; the third recursive call is always up; the fourth recursive call is always down. How will the rows be completely filled? a. Row 1 is filled first, then row 2, then row 3 b. Row 1 is filled first, then row 3, then row 2 c. Row 2 is filled first, then row 3, then row 1 d. Row 3 is filled first, then row 1, then row 2 e. Row 3 is filled first, then row 2, then row 1

a. Row 1 is filled first, then row 2, then row 3

Suppose we are sorting an array of ten integers using a some quadratic sorting algorithm. After four iterations of the algorithm's main loop, the array elements are ordered as shown here: 1 2 3 4 5 0 6 7 8 9 Which statement is correct? (Note: Our selectionsort picks largest items first.) a. The algorithm might be either selectionsort or insertionsort. b. The algorithm might be selectionsort, but could not be insertionsort. c. The algorithm might be insertionsort, but could not be selectionsort. d. The algorithm is neither selectionsort nor insertionsort.

a. The algorithm might be either selectionsort or insertionsort.

Tree algorithms typically run in time O(d) . What is d? a. The depth of the tree. b. The number of divisions at each level. c. The number of entries in each node. d. The number of nodes in the tree. e. The total number of entries in all the nodes of the tree.

a. The depth of the tree.

Consider the binary tree in the box at the top of this section. Which statement is correct? a. The tree is neither complete nor full b. The tree is complete but not full c. The tree is full but not complete d. The tree is both full and complete

a. The tree is neither complete nor full

A heap is implemented using a partially filled array called data, and the array contains n elements (n > 0), where is the entry with the greatest value? a. data[0] b. data[n-1] c. data[n] d. data[2*n + 1] e. data[2*n + 2]

a. data[0]

Which formula is the best approximation for the depth of a heap with n nodes? a. log (base 2) of n b. The number of digits in n (base 10) c. The square root of n d. n e. The square of n

a. log (base 2) of n

Consider the following function: void super_write_vertical(int number) // Postcondition: The digits of the number have been written, // stacked vertically. If number is negative, then a negative // sign appears on top. // Library facilities used: iostream.h, math.h { if (number < 0) { cout << '-' << endl; super_write_vertical(abs(number)); } else if (number < 10) cout << number << endl; else { super_write_vertical(number/10); cout << number % 10 << endl; } } Which call will result in the most recursive calls? a. super_write_vertical(-1023) b. super_write_vertical(0) c. super_write_vertical(100) d. super_write_vertical(1023)

a. super_write_vertical(-1023)

There is a tree in the box at the top of this section. What is the order of nodes visited using an in-order traversal? a. 1 2 3 7 10 11 14 30 40 b. 1 2 3 14 7 10 11 40 30 c. 1 3 2 7 10 40 30 11 14 d. 14 2 1 3 11 10 7 30 40

b. 1 2 3 14 7 10 11 40 30

Suppose we are sorting an array of eight integers using heapsort, and we have just finished one of the reheapifications downward. The array now looks like this: 6 4 5 1 2 7 8 How many reheapifications downward have been performed so far? a. 1 b. 2 c. 3 or 4 d. 5 or 6

b. 2

Suppose T is a binary tree with 14 nodes. What is the minimum possible depth of T? a. 0 b. 3 c. 4 d. 5

b. 3

There is a tree in the box at the top of this section. What is the depth of the tree? 14 / \ 2 11 / \ / \ 1 3 10 30 / / 7 40 a. 2 b. 3 c. 4 d. 8 e. 9

b. 3

There is a tree in the box at the top of this section. How many leaves does it have? 14 / \ 2 11 / \ / \ 1 3 10 30 / / 7 40 a. 2 b. 4 c. 6 d. 8 e. 9

b. 4

There is a tree in the box at the top of this section. How many of the nodes have at least one sibling? 14 / \ 2 11 / \ / \ 1 3 10 30 / / 7 40 a. 5 b. 6 c. 7 d. 8 e. 9

b. 6

Which statement is true for a B-tree? a. All entries of a node are greater than or equal to the entries in the node's children. b. All leaves are at the exact same depth. c. All nodes contain the exact same number of entries. d. All non-leaf nodes have the exact same number of children.

b. All leaves are at the exact same depth.

Mergesort makes two recursive calls. Which statement is true after these recursive calls finish, but before the merge step? a. The array elements form a heap. b. Elements in each half of the array are sorted amongst themselves. c. Elements in the first half of the array are less than or equal to elements in the second half of the array. d. None of the above.

b. Elements in each half of the array are sorted amongst themselves.

Which of the following statements is true? a. A graph can drawn on paper in only one way. b. Graph vertices may be linked in any manner. c. A graph must have at least one vertex. d. A graph must have at least one edge.

b. Graph vertices may be linked in any manner.

What feature of heaps allows them to be efficiently implemented using a partially filled array? a. Heaps are binary search trees. b. Heaps are complete binary trees. c. Heaps are full binary trees. d. Heaps contain only integer data.

b. Heaps are complete binary trees.

What is the worst-case time for binary search finding a single item in an array? a. Constant time b. Logarithmic time c. Linear time d. Quadratic time

b. Logarithmic time

What is the expected number of operations needed to loop through all the edges terminating at a particular vertex given an adjacency matrix representation of the graph? (Assume n vertices are in the graph and m edges terminate at the desired node.) a. O(m) b. O(n) c. O(m²) d. O(n²)

b. O(n)

What kind of initialization needs to be done for an open-address hash table? a. None b. The key at each array location must be initialized. c. The head pointer of each chain must be set to NULL. d. Both B and C must be carried out.

b. The key at each array location must be initialized.

In an open-address hash table there is a difference between those spots which have never been used and those spots which have previously been used but no longer contain an item. Which function has a better implementation because of this difference? a. insert b. is_present c. remove d. size

b. is_present

How many linked lists are used to represent a graph with n nodes and m edges, when using an edge list representation, a. m b. n c. m + n d. m * n

b. n

In a selection sort of n elements, how many times is the swap function called in the complete execution of the algorithm? a. 1 b. n - 1 c. n log n d. n²

b. n - 1

Consider the following function: void super_write_vertical(int number) // Postcondition: The digits of the number have been written, // stacked vertically. If number is negative, then a negative // sign appears on top. // Library facilities used: iostream.h, math.h { if (number < 0) { cout << '-' << endl; super_write_vertical(abs(number)); } else if (number < 10) cout << number << endl; else { super_write_vertical(number/10); cout << number % 10 << endl; } } What values of number are directly handled by the stopping case? a. number < 0 b. number < 10 c. number >= 0 && number < 10 d. number > 10

b. number < 10

Suppose that a selectionsort of 100 items has completed 42 iterations of the main loop. How many items are now guaranteed to be in their final spot (never to be moved again)? a. 21 b. 41 c. 42 d. 43

c. 42

Consider this function declaration: void quiz(int i) { if (i > 1) { quiz(i / 2); quiz(i / 2); } cout << "*"; } How many asterisks are printed by the function call quiz(5)? a. 3 b. 4 c. 7 d. 8 e. Some other number

c. 7

What is the minimum number of nodes in a complete binary tree with depth 3? a. 3 b. 4 c. 8 d. 11 e. 15

c. 8

Select the one true statement a. Every binary tree is either complete or full. b. Every complete binary tree is also a full binary tree. c. Every full binary tree is also a complete binary tree. d. No binary tree is both complete and full.

c. Every full binary tree is also a complete binary tree.

Selectionsort and quicksort both fall into the same category of sorting algorithms. What is this category? a. O(nlogn) sorts b. Divide-and-conquer sorts c. Interchange sorts d. Average time is quadratic.

c. Interchange sorts

What is the worst-case time for serial search finding a single item in an array? a. Constant time b. Logarithmic time c. Linear time d. Quadratic time

c. Linear time

What is the worst-case time for heapsort to sort an array of n elements? a. O(log n) b. O(n) c. O(n log n) d. O(n²)

c. O(n log n)

What is the worst-case time for mergesort to sort an array of n elements? a. O(log n) b. O(n) c. O(n log n) d. O(n²)

c. O(n log n)

Suppose we are sorting an array of eight integers using a some quadratic sorting algorithm. After four iterations of the algorithm's main loop, the array elements are ordered as shown here: 2 4 5 7 8 1 3 6 Which statement is correct? (Note: Our selectionsort picks largest items first.) a. The algorithm might be either selectionsort or insertionsort. b. The algorithm might be selectionsort, but it is not insertionsort. c. The algorithm is not selectionsort, but it might be insertionsort. d. The algorithm is neither selectionsort nor insertionsort.

c. The algorithm is not selectionsort, but it might be insertionsort.

When is insertionsort a good choice for sorting an array? a. Each component of the array requires a large amount of memory. b. Each component of the array requires a small amount of memory. c. The array has only a few items out of place. d. The processor speed is fast.

c. The array has only a few items out of place.

What additional requirement is placed on an array, so that binary search may be used to locate an entry? a. The array elements must form a heap. b. The array must have at least 2 entries. c. The array must be sorted. d. The array's size must be a power of two.

c. The array must be sorted.

Suppose that a B-tree has MAXIMUM of 10 and that a node already contains the integers 1 through 10. If a new value, 11, is added to this node, the node will split into two pieces. What values will be in these two pieces? a. The first piece will have only 1 and the second piece will have the rest of the numbers. b. The first piece will have 1 through 5 and the second piece will have 6 through 11. c. The first piece will have 1 through 5 and the second piece will have 7 through 11. d. The first piece will have 1 through 6 and the second piece will have 7 through 11. e. The first piece will have 1 through 10 and the second piece will have only 11.

c. The first piece will have 1 through 5 and the second piece will have 7 through 11.

What kind of initialization needs to be done for a chained hash table? a. None. b. The key at each array location must be initialized. c. The head pointer of each chain must be set to NULL. d. Both B and C must be carried out.

c. The head pointer of each chain must be set to NULL.

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.

If G is an directed graph with 20 vertices, how many boolean values will be needed to represent G using an adjacency matrix? a. 20 b. 40 c. 200 d. 400

d. 400

Suppose that a non-leaf node in a B-tree has 41 entries. How many children will this node have? a. 2 b. 40 c. 41 d. 42 e. 82

d. 42

Suppose we remove the root, replacing it with something from the left subtree. What will be the new root? a. 1 b. 2 c. 4 d. 5 e. 16

d. 5

There is a tree in the box at the top of this section. How many descendants does the root have? 14 / \ 2 11 / \ / \ 1 3 10 30 / / 7 40 a. 0 b. 2 c. 4 d. 8

d. 8

Suppose you have a directed graph representing all the flights that an airline flies. What algorithm might be used to find the best sequence of connections from one city to another? a. Breadth first search. b. Depth first search. c. A cycle-finding algorithm. d. A shortest-path algorithm.

d. A shortest-path algorithm.

Select the true statement about the worst-case time for operations on heaps. a. Neither insertion nor removal is better than linear. b. Insertion is better than linear, but removal is not. c. Removal is better than linear, but insertion is not. d. Both insertion and removal are better than linear.

d. Both insertion and removal are better than linear.

A simple graph has no loops. What other property must a simple graph have? a. It must be directed. b. It must be undirected. c. It must have at least one vertex. d. It must have no multiple edges.

d. It must have no multiple edges.

When the compiler compiles your program, how is a recursive call treated differently than a non-recursive function call? a. Parameters are all treated as reference arguments b. Parameters are all treated as value arguments c. There is no duplication of local variables d. None of the above

d. None of the above

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

In a single function declaration, what is the maximum number of statements that may be recursive calls? a. 1 b. 2 c. n (where n is the argument) d. There is no fixed maximum

d. There is no fixed maximum

What is the maximum depth of recursive calls a function may make? a. 1 b. 2 c. n (where n is the argument) d. There is no fixed maximum

d. There is no fixed maximum

What is the minimum number of nodes in a full binary tree with depth 3? a. 3 b. 4 c. 8 d. 11 e. 15

e. 15

Consider the following function: void test_a(int n) { cout << n << " "; if (n>0) test_a(n-2); } What is printed by the call test_a(4)? a. 0 2 4 b. 0 2 c. 2 4 d. 4 2 e. 4 2 0

e. 4 2 0

Suppose that we have implemented a priority queue by storing the items in a heap. We are now executing a reheapification downward and the out-of-place node has priority of 42. The node's parent has a priority of 72, the left child has priority 52 and the node's right child has priority 62. Which statement best describes the status of the reheapification. a. The reheapification is done. b. The next step will interchange the two children of the out-of-place node. c. The next step will swap the out-of-place node with its parent. d. The next step will swap the out-of-place node with its left child. e. The next step will swap the out-of-place node with its right child.

e. The next step will swap the out-of-place node with its right child.

A chained hash table has an array size of 512. What is the maximum number of entries that can be placed in the table? a. 256 b. 511 c. 512 d. 1024 e. There is no maximum

e. There is no maximum

Suppose you place m items in a hash table with an array size of s. What is the correct formula for the load factor? a. s + m b. s - m c. m - s d. m * s e. m / s

e. m / s


Kaugnay na mga set ng pag-aaral

Chapter 13: Geometric Dimensioning and Tolerancing

View Set

Mood, Adjustment, and Dementia Disorders

View Set

mgt 4335 exam 2 practice questions

View Set

CHEM 1331 - Exam 1 - Study Material - Rapid Fire - No Math To Speak of

View Set