Data Structures

¡Supera tus tareas y exámenes ahora con Quizwiz!

The following items are inserted into a binary search tree: 3, 6, 5, 2, 4, 7, 1. Which node is the deepest? (a) 1 (b) 3 (c) 4 (d) 7 (e) none of the above

4

An algorithm takes 10 seconds for an input size of 50. If the algorithm is quadratic, approximately how long does it take to solve a problem of size 100?

40 seconds

Suppose a disk block stores 4096 bytes and the basic key size is 96 bytes. Assuming that pointers cost 4 bytes, what is the correct choice of M for a B-tree? (a) 41 (b) 42 (c) 43 (d) 96 (e) none of the above

41

Graph: V = {V0; V1; V2; V3; V4; V5; V6}. Edges: E = { (V0; V2; 4); (V1; V0; 2); (V1; V3; 3); (V3; V0; 1); (V3; V2; 2); (V3; V5; 8); (V3; V6; 4); (V4; V1; 10); (V4; V3; 2); (V4; V6; 7); (V5; V2; 2); (V6; V5; 1) } The shortest weighted path from V4 to V5 has weight (a) 2 (b) 4 (c) 7 (d) 8 (e) none of the above

7

Which of the following statements about sorting five elements is the strongest statement that is directly implied by the information-theoretic lower bound? (a) 6 comparisons are sufficient (b) 6 comparisons are necessary and sufficient (c) 7 comparisons are necessary (d) 7 comparisons are sufficient (e) 7 comparisons are necessary and sufficient

7 comparisons are necessary

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) 1 (b) 4 (c) 8 (d) 9 (e) none of the above

8

What is the range of values computed by the hash function H ash(X) = X mod 100? (a) 0 to 99 (b) 0 to 100 (c) 1 to 99 (d) 1 to 100 (e) none of the above

0 to 99

In a separate chaining hash table with load factor = 0:8, what is the average length of a list? (a) 0.8 (b) 1.0 (c) 1.25 (d) there is not enough information (e) there is enough information, but none of the above are correct

0.8

For an insertion of a single item into an n-item AVL tree, the maximum number of rotations (double rotations count as one rotation) is (a) 1 (b) 2 (c) approximately log n (d) approximately 1.44 log n (e) none of the above

1

How many n node binary trees with items 1, 2, ..., n have identical postorder and inorder traversals? (a) 0 (b) 1 (c) n (d) n! (e) none of the above

1

Using the text implementation, if Front and Rear have identical values, what is the size of the queue? (a) 0 (b) 1 (c) 2 (d) the answer cannot be determined

1

The following items are inserted into an AVL tree: 1, 2, 3, 8, 6. How many rotations are performed? (a) no rotations (b) 1 single rotation only (c) 1 double rotation only (d) 1 single rotation and 1 double rotation (e) none of the above

1 single rotation and 1 double rotation

Graph: V = {V0; V1; V2; V3; V4; V5; V6}. Edges: E = { (V0; V2; 4); (V1; V0; 2); (V1; V3; 3); (V3; V0; 1); (V3; V2; 2); (V3; V5; 8); (V3; V6; 4); (V4; V1; 10); (V4; V3; 2); (V4; V6; 7); (V5; V2; 2); (V6; V5; 1) } If the above graph were undirected, then what would be the cost of its minimum spanning tree? (a) 1 (b) 10 (c) 11 (d) 12 (e) none of the above

10

A / \ B C /\ D E The height of the tree is (a) 0 (b) 1 (c) 2 (d) 3 (e) none of the above

2

Insertion of a node into a doubly linked list requires how many changes to various Next and Prev pointers?

2 Next, 2 Prev

An algorithm takes 30 seconds for an input of size 1000. If the algorithm is quadratic, how large a problem can be solved in two minutes?

2000

Which of the following functions grows fastest? - n log n - 2^n - log n - n^2 - n^20

2^n

Suppose we are implementing quadratic probing with a hash function H ash(X) = X mod 100. If an element with key 4594 is inserted and the rst three locations attempted are already occupied, then the next cell that will be tried is (a) 2 (b) 3 (c) 9 (d) 97 (e) none of the above

3

Which of the following data structures has the strongest height guarantee? (a) AVL tree (b) B-tree of order 3 (c) B-tree of order 5 (d) splay tree (e) 2-3 tree

B-tree of order 5

What operation is supported in constant time by the doubly linked list, but not by the singly linked list? (a) Advance (b) Backup (c) First (d) Retrieve (e) all of the above are always constant time

Backup

Let C(X) be the number of leaves in a binary tree rooted at T. Assume that IsLeaf(T) 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) (d) C(T):=C(T.Left)+C(T.Right)+IsLeaf(T)+1 (e) none of the above

C(T):=C(T.Left)+C(T.Right)+IsLeaf(T)

Which algorithm is used to compute minimum spanning trees? (a) breadth rst search (b) depth rst search (c) Dijkstra's (d) Kruskal's (e) none of the above

Kruskal's

Which of the four operations below can be used to implement the other three for the skew heap? (a) Decrease Key (b) Delete Min (c) Insert (d) Merge (e) none of the above

Merge

A / \ B C /\ D E Which of the following is an inorder traversal of the tree? (a) ABCDE (b) ABDEC (c) DBEAC (d) DEBAC (e) none of the above

DBEAC

Which of the following algorithms solves the positive weighted single-source shortest path problem? (a) breadth-first search (b) depth-first search (c) Dijkstra's algorithm (d) Kruskal's algorithm (e) Prim's algorithm

Dijkstra's algorithm

For the linked list implementation of the queue, where are the enqueue and dequeues performed? (a) Enqueue in front of the first element, dequeue the first element (b) Enqueue after the last element, dequeue the last element (c) Enqueue after the last element, dequeue the first element (d) Enqueue in front of the first element, dequeue the last element (e) Enqueue after the first element, dequeue the first element

Enqueue after the last element, dequeue the first element

For quicksort, what do I and J do when they see keys equal to the pivot? (a) I stops, J stops (b) I stops, J goes (c) I goes, J stops (d) I goes, J goes (e) I and J alternate between stopping and going

I stops, J stops

The running time of Build Heap is (a) O(n) worst case and O(n) average case (b) O(n) worst case and O(log n) average case (c) O(n) worst case and O(n log n) average case (d) O(n log n) worst case and O(n) average case (e) O(n log n) worst case and O(n log n) average case

O(n) worst case and O(n) average case

Suppose T1(n) = O(F (n)) and T2(n) = O(F (n)). Which of the following are true? (a) T1(n) + T2(n) = O(F (n)) (b) T1(n) * T2(n) = O(F (n)) (c) T1(n)/T2(n) = O(1) (d) T1(n) = O(T2(n)) (e) none of the above

T1(n) + T2(n) = O(F (n))

Which of these is false about the binary search? (a) the input array must be sorted (b) successful searches take logarithmic time on average (c) unsuccessful searches take logarithmic time on average (d) the worst case for any search is logarithmic

all are true

Rehashing can be used in (a) linear probing (b) quadratic probing (c) separate chaining (d) all of the above (e) none of the above

all of the above

Which of the following traversals requires more than linear time in the worst case? (a) inorder (b) level order (c) postorder (d) preorder (e) all of these traversals are linear time

all of these traversals are linear time

The header node of a linked list: (a) simplifies deletion (b) simplifies insertion (c) uses only constant extra space (d) all true

all true

Which of the following is a synonym for an edge? (a) arc (b) node (c) path (d) vertex (e) none of the above

arc

Which of the following data structures uses a sentinel? (a) binary heap (b) hash table (c) queue (d) stack (e) none of the above use sentinels

binary heap

Percolate up and down are used for (a) AVL trees (b) B-trees (c) circular queue (d) binary heaps (e) none of the above

binary heaps

Which of the following could be used as an ecient priority queue? (a) binary search tree (b) hash table (c) linked list (d) queue (e) stack

binary search tree

Which of the following is not a binary tree? (a) binary heap (b) binomial queue (c) skew heap (d) splay tree (e) all of the above are binary trees

binomial queue

Which of the following algorithms solves the unweighted single-source shortest path problem? (a) breadth-first search (b) depth-first search (c) Dijkstra's algorithm (d) Kruskal's algorithm (e) Prim's algorithm

breadth-first search

The UNIX editor vi allows searching in both directions, with wraparound if necessary. If the sequence of lines is stored as a linked list, which of the following is most reasonable? (a) singly linked list (b) doubly linked list (c) circular singly linked list (d) circular doubly linked list (e) none of the above

circular doubly linked list

For the weighted shortest path problem, let dv be the cost of reaching the current vertex v, let w be adjacent to v and assume the edge cost is cvw. Suppose that dw was the cost of reaching w prior to examining v. (Ties are broken in favor of the rst path seen). Then under what circumstances is w's distance lowered? (a) dw > dv (b) dw > dv + 1 (c) dw > dv + cvw (d) dv > dw + cvw (e) none of the above

dw > dv + cvw

In a graph with v vertices and e edges, which of the following maximum sizes is not correct for an unweighted shortest path computation? (a) v for the number of adjacency lists (b) e for the total size of all adjacency lists (c) e for the size of the hash table that maps names to internal numbers (d) v for the size of the queue (e) all of the above are correct

e for the size of the hash table that maps names to internal numbers

Which of the following is true about the skew heap? (a) it is balanced (b) each node stores nothing besides an item and two pointers (c) the right path contains at most a logarithmic number of nodes (d) two of the above (e) all of the above

each node stores nothing besides an item and two pointers

Which data structure is generally used to implement a symbol table? (a) binary search tree (b) hash table (c) priority queue (d) queue (e) stack

hash table

Which of the following data structures does not yield an ecient comparison-based sort? (a) AVL tree (b) hash table (c) priority queue (d) all can be used for ecient sorting (e) none can be used for ecient sorting

hash table

Which of the following operations is not efficiently supported by a singly-linked list? (a) accessing the element in the current position (b) insertion after the current position (c) insertion before the current position (d) moving to the position immediately following the current position (e) all of the above are efficiently supported

insertion before the current position

Which of the following algorithms runs in quadratic average time? (a) heapsort (b) insertion sort (c) mergesort (d) quicksort (e) shellsort

insertion sort

Which of the following algorithms, implemented as in the text, runs in O(n) time when presented with an array of n identical elements? (a) heapsort (b) insertion sort (c) mergesort (d) quicksort (e) shellsort

insertion sort

Every node in a (min) binary heap (a) has two children (b) is no larger than its children (c) is no smaller than its children (d) has a smaller left child than right child (e) two or more of the above

is no larger than its children

A / \ B C /\ D E Which of the following traversals yields ABCDE? (a) inorder (b) level order (c) postorder (d) preorder (e) two of the above

level order

Which traversal does not use a stack? (a) inorder (b) level order (c) postorder (d) preorder (e) all of these traversals uses a stack

level order

Primary clustering occurs in (a) linear probing (b) quadratic probing (c) separate chaining (d) all of the above (e) none of the above

linear probing

Which of the following algorithms requires the most extra space, on average, when implemented as in the text? (a) heapsort (b) insertion sort (c) mergesort (d) quicksort (e) shellsort

mergesort

Which sorting algorithm has the same average and worst-case time bounds (in Big-Oh) as heapsort? (a) insertion sort (b) mergesort (c) quicksort (d) shellsort (e) none of the above

mergesort

What is the basic algorithm used for external sorting? (a) nding the median (b) merging (c) selection (d) all of the above (e) none of the above

merging

A node with key 8 has a left child with key 10. Which of the following ob jects could this node be found in? (a) binary search tree (b) max heap (c) min heap (d) two of the above (e) none of the above

min heap

Which of the following functions grows fastest? a) n + log n b) n log n c) n - log n d) n

n log n

For the linked list implementation, if the stack is not empty, which of the following statements in a main procedure can be used to access the top element in the stack S? (a) S.Element (b) S.TopOfStack (c) S.TopOfStack.Element (d) TopOfStack.Element (e) none of the above

none

Approximately what is the maximum height of a binary search tree of n nodes? (a) log n (b) 1.38 log n (c) 1:44 log n (d) 2 log n (e) none of the above

none of the above

In median-of-three partitioning, where is the pivot placed before partitioning begins? (a) at the start of the array (b) at the middle of the array (c) at the end of the array (d) in a temporary variable (e) none of the above

none of the above

The first child / next sibling implementation (a) allows easy access to the parent (b) is appropriate for binary trees (c) uses C pointers per node, where C is the number of children (d) all of the above (e) none of the above

none of the above

Which of the following statements about quadratic probing is true (expensive does not include trivial operations such as multiplication or division by powers of 2; computation of the hash function is not included in the cost)? (a) an expensive division must be performed (b) an expensive mod operator must be performed (c) an expensive multiplication must be performed (d) all of the above (e) none of the above

none of the above

Programs A and B are analyzed and found to have worst-case running times no greater than 150n log n and n^2 , respectively. Which of the following statements does the analysis imply? (a) Program A will run faster on average for suciently large n. (b) Program B will run faster on average for small n. (c) Program A is probably simpler to code than program B. (d) There exists some input for which program B takes longer than program A. (e) none of the above

none of the following: - Program A will run faster on average for suciently large n. - Program B will run faster on average for small n. - Program A is probably simpler to code than program B. - There exists some input for which program B takes longer than program A

Which of the following does not use a queue? (a) negative weighted shortest path algorithm (b) positive weighted shortest path algorithm (c) topological sort (d) unweighted shortest path algorithm (e) all of the above use a queue

positive weighted shortest path algorithm

Which traversal computes the total size of each directory in the UNIX le system? (a) inorder (b) level order (c) postorder (d) preorder (e) two or more of the above traversals could be used

postorder

In which of the following traversals is the node processed before the recursive calls to the children complete? (a) inorder (b) level order (c) postorder (d) preorder (e) none of the above

preorder

Which data structure maintains the event set in an event-driven (discrete-event) simulation? (a) binary search tree (b) hash table (c) priority queue (d) queue (e) stack

priority queue

Which of the following does the binary heap implement? (a) binary search tree (b) hash table (c) priority queue (d) queue (e) stack

priority queue

An algorithm takes 6 seconds to solve a problem of size 100 and ten minutes to solve a problem of size 1000. What is the likely running time of the algorithm?

quadratic

6, 8, 4, 3, and 1 are inserted into a data structure in that order. An item is deleted using only a basic data structure operation. If the deleted item is a 1, the data structure cannot be a (a) hash table (b) priority queue (c) queue (d) search tree (e) stack

queue

Jobs sent to a printer are generally placed on a (a) binary search tree (b) hash table (c) priority queue (d) queue (e) stack

queue

Which of the following algorithms has the largest big-Oh di erential between average-case and worst-case performance? (a) heapsort (b) insertion sort (c) mergesort (d) quicksort (e) quickselect

quickselect

Which of the following algorithms runs in O(n log n) average time but quadratic worst-case time? (a) heapsort (b) insertion sort (c) mergesort (d) quicksort (e) shellsort

quicksort

Which of the following data structures requires more than constant average time for insertions? (a) hash table (b) queue (c) search tree (d) stack (e) all of the above have constant time insertion algorithms

search tree

Linked lists are used in (a) double hashing (b) linear probing (c) quadratic probing (d) separate chaining (e) all of the above

separate chaining

Which of (a) to (d) is false: The size of a hash table (a) should be a power of 2 for quadratic probing (b) should be a prime number for linear probing (c) should be about 2n for quadratic probing (d) should be about n for separate chaining (e) two or more of the above are false

should be a power of 2 for quadratic probing

Which data structure is used by the compiler to implement recursion? (a) hash table (b) priority queue (c) queue (d) search tree (e) stack

stack

Which data structure is used to check for balanced parentheses? (a) binary search tree (b) hash table (c) priority queue (d) queue (e) stack

stack

If an element in a binary heap is stored in position i and the root is at position 1, then where is the parent stored? (a) |_i/2_| (b) [i/2] (c) 1 + _|i/2|_ (d) 2i (e) 2i + 1

|_i/2_|

Which of the following is the strongest lower bound for sorting when ordering information is obtained only by adjacent comparisons? (a) O(n log n) (b) O(n^2 ) (c) Ω(n log n) (d) Ω(n^2 ) (e) none of the above is a valid lower bound for this problem

Ω(n^2 )

Which operation is not supported in constant time by a double-ended queue (deque)? (a) Insertion as the front or rear item (b) Access of the front or rear item (c) Deletion of the front or rear item (d) Access and deletion of the minimum item (e) all of the above are supported

Access and deletion of the minimum item

What happens when wraparound is implemented for a queue? (a) If Front advances past the last array position, it is reset to the rst array position. (b) If Rear advances past the last array position, it is reset to the rst array position. (c) Both a and b (d) Neither a nor b

Both A and B

Which statement, placed in the list package implementation, inserts an item X after position Current? (a) Current := new Node'( X, Current ); (b) Current := new Node'( X, Current.Next ); (c) Current.Next := new Node'( X, Current ); (d) Current.Next := new Node'( X, Current.Next ); (e) none of the above

Current.Next := new Node'( X, Current.Next );

Which of the following statements is true? (a) A topological ordering exists in every directed graph (b) Every acyclic graph has at least one topological ordering (c) Every acyclic graph has exactly one topological ordering (d) Every acyclic graph has at most one topological ordering (e) none of the above

Every acyclic graph has at least one topological ordering

Which operation is not eciently supported by priority queues? (a) Delete Min (b) Find (c) Find Min (d) Insert (e) All of the above are eciently supported

Find

What is the running time of the following routine? function Is_Prime( N : Integer ) return Boolean is I : Integer := 3; begin if N = 2 or else N = 3 then return TRUE; end if; if N MOD 2 = 0 then return FALSE; end if; while i * i <= N loop if N MOD i = 0 then return FALSE; else I := I + 2; end if; end loop; return TRUE; end Is_Prime;

O( sqrt(N))

How much extra space is used by heapsort? (a) O(1) (b) O(log n) (c) O(n) (d) O(n^2 ) (e) none of the above

O(1)

How many times is statement 4 executed? 1 for i in 1..N loop 2 - for j in 1..i loop 3 - - for k in i..j loop 4 - - - Sum := Sum + 1; 5 - - end loop; 6 - end loop; 7 end loop; 8 for p in 1..N*N loop 9 - for q in 1..p loop 10 - - Sum := Sum - 1; 11 - end loop; 12 end loop;

O(N^3 )

How many times is statement 10 executed? 1 for i in 1..N loop 2 - for j in 1..i loop 3 - - for k in i..j loop 4 - - - Sum := Sum + 1; 5 - - end loop; 6 - end loop; 7 end loop; 8 for p in 1..N*N loop 9 - for q in 1..p loop 10 - - Sum := Sum - 1; 11 - end loop; 12 end loop;

O(N^4)

What is the running time of the fragment? 1 for i in 1..N loop 2 - for j in 1..i loop 3 - - for k in i..j loop 4 - - - Sum := Sum + 1; 5 - - end loop; 6 - end loop; 7 end loop; 8 for p in 1..N*N loop 9 - for q in 1..p loop 10 - - Sum := Sum - 1; 11 - end loop; 12 end loop;

O(N^4)

The solution to T (n) = T (|_3n/4_|) + 10 with T (0) = 0 is most accurately given by

O(log n)

A recursive algorithm works by solving two half-sized problems recursively, with an additional linear-time overhead. The total running time is most accurately given by

O(n log n)

n elements are inserted one by one into an initially empty binary heap. The total running time is (a) O(n) worst case and O(n) average case (b) O(n) worst case and O(log n) average case (c) O(n) worst case and O(n log n) average case (d) O(n log n) worst case and O(n) average case (e) O(n log n) worst case and O(n log n) average case

O(n log n) worst case and O(n) average case

What is amortized cost of an operation using rotate-to-root? (a) O(1) (b) O(log n) (c) O(n) (d) O(n log n) (e) none of the above

O(n)

For the linked list implementation of the stack, where are the pushes and pops performed? (a) Push in front of the first element, pop the first element (b) Push after the last element, pop the last element (c) Push after the last element, pop the first element (d) Push in front of the first element, pop the last element (e) Push after the first element, pop the first element

Push in front of the first element, pop the first element

Which of the following is true about the height of a node? (a) The height of a node is one less than the height of its parent (b) The height of an empty tree is 0 (c) The height of a leaf is 0 (d) The height of a tree can be larger than its depth (e) all of the above are false

The height of a leaf is 0

Graph: V = {V0; V1; V2; V3; V4; V5; V6}. Edges: E = { (V0; V2; 4); (V1; V0; 2); (V1; V3; 3); (V3; V0; 1); (V3; V2; 2); (V3; V5; 8); (V3; V6; 4); (V4; V1; 10); (V4; V3; 2); (V4; V6; 7); (V5; V2; 2); (V6; V5; 1) } If the start vertex is V4, then using the standard weighted shortest path algorithm, which is the last vertex to be declared known? (a) V0 (b) V1 (c) V2 (d) V4 (e) none of the above

V1

Graph: V = {V0; V1; V2; V3; V4; V5; V6}. Edges: E = { (V0; V2; 4); (V1; V0; 2); (V1; V3; 3); (V3; V0; 1); (V3; V2; 2); (V3; V5; 8); (V3; V6; 4); (V4; V1; 10); (V4; V3; 2); (V4; V6; 7); (V5; V2; 2); (V6; V5; 1) } If the start vertex is V4, then using the acyclic weighted shortest path algorithm, which is the last vertex to be declared known? (a) V0 (b) V1 (c) V2 (d) the graph is not acyclic, so the acyclic algorithm should not be used (e) none of the above

V2

If the shortest path algorithm is run and a vertex is not reachable from the starting point, what happens? (a) a distance of infinity is reported (b) a distance of -1 is reported (c) a distance of zero is reported (d) the algorithm enters an in nite loop (e) the algorithm's results are unde ne

a distance of infinity is reported

Items 7, 3, 11, 9, and 13 are inserted into an AVL tree. What happens when 12 is inserted? (a) no rotation is needed (b) a single rotation between some node and its left child is performed (c) a single rotation between some node and its right child is performed (d) a double rotation with a node, its left child, and a third node is performed (e) a double rotation with a node, its right child, and a third node is performed

a single rotation between some node and its right child is performed

Replacement selection is (a) arranging the initial runs on the tape in an optimal way (b) constructing the runs so they have expected length 2M (c) using K-way merging instead of 2-way merging (d) using K + 1 tapes instead of K tapes (e) none of the above

constructing the runs so they have expected length 2M

Which of the following statements is true about deleting the root of a binary search tree? (a) the root pointer always changes (b) the root pointer changes if it does not have two children (c) if the root has two children, its item is replaced by the largest element in the right subtree (d) all of the above (e) none of the above

the root pointer changes if it does not have two children

What is the maximum number of nodes in a binary tree with L leaves? (a) 2L (b) 2^L (c) 2^(L+1) (d) there is no maximum (e) none of the above

there is no maximum

How are elements deleted in linear probing? (a) deletion is not allowed (b) they are changed to zero (c) they are marked deleted (d) unchecked deallocation (e) none of the above

they are marked deleted

Which of the following can be done in O(log n) arithmetic operations? (a) Raising a number to the nth power (b) Computing the greatest common divisor of some integer and n (c) Adding two n-digit numbers

two of them

In a connected graph with no loops or multiple edges, which of the following inequalities is not correct? (v is the number of vertices, e is the number of edges) (a) e <= v^2 (b) e >=v - 1 (c) v <=e^2 + 1 (d) v >= e/2 (e) all of the above are correc

v >= e/2

Which of the following problems is not known to be solvable in linear time? (a) topological sort (b) unweighted shortest path in general graphs (c) weighted shortest path in acyclic graphs (d) weighted shortest path in cyclic graphs (e) all are solvable in linear time

weighted shortest path in cyclic graphs


Conjuntos de estudio relacionados

Chapter 24 exam question possibility

View Set

Chapter 10 - Post-Lecture Assignment

View Set

VITAMINS/MINERALS - Functions in the Body/Benefits

View Set

patho course point exam 2 quizzes

View Set

State & National Real Estate PSI Practice Questions

View Set

Compensation Management - Chapter 7

View Set

Biology: Chapter 1 (Exploring Life)

View Set

Chapter 5 VSEPR, Hybridization, and MO Diagrams

View Set