Unit 5: More on Dynamic Programming - Practice Quiz

ECAP538 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What does the all-pairs shortest paths problem compute?

All-pairs shortest paths Easy
A. Minimum spanning tree of the graph
B. Longest paths between adjacent vertices
C. Shortest paths from one selected vertex
D. Shortest paths between every pair of vertices

2 Which dynamic programming algorithm commonly solves the all-pairs shortest paths problem?

All-pairs shortest paths Easy
A. Prim's algorithm
B. Kruskal's algorithm
C. Floyd-Warshall algorithm
D. Huffman algorithm

3 What is the time complexity of the Floyd-Warshall algorithm for vertices?

All-pairs shortest paths Easy
A.
B.
C.
D.

4 What is normally stored in entry of the final Floyd-Warshall matrix?

All-pairs shortest paths Easy
A. Parent of vertex
B. Degree of vertex
C. Weight of vertex
D. Distance from to

5 What is the usual initial distance from a vertex to itself?

All-pairs shortest paths Easy
A.
B.
C.
D.

6 How is the initial distance from to usually represented when no direct edge exists?

All-pairs shortest paths Easy
A.
B.
C.
D.

7 Which update rule is used by the Floyd-Warshall algorithm when considering vertex ?

All-pairs shortest paths Easy
A.
B.
C.
D.

8 Can the Floyd-Warshall algorithm process graphs containing negative edge weights?

All-pairs shortest paths Easy
A. Yes, if no negative cycle exists
B. No, only positive edges work
C. No, negative edges are forbidden
D. Yes, only for undirected graphs

9 After Floyd-Warshall finishes, what indicates a negative cycle?

All-pairs shortest paths Easy
A. Every matrix entry is zero
B. A diagonal entry is negative
C. A diagonal entry is positive
D. Every matrix entry is infinite

10 Which graph representation is most directly used by the Floyd-Warshall algorithm?

All-pairs shortest paths Easy
A. Priority queue
B. Binary search tree
C. Distance matrix
D. Disjoint-set forest

11 What is the main objective of an optimal binary search tree?

Optimal binary search trees Easy
A. Sort keys in descending order
B. Minimize the expected search cost
C. Equalize all search probabilities
D. Maximize the total tree height

12 What information is primarily used to construct an optimal binary search tree?

Optimal binary search trees Easy
A. Memory addresses of the keys
B. Colors assigned to the keys
C. Insertion times of the keys
D. Search probabilities of the keys

13 Where are frequently searched keys generally placed in an optimal binary search tree?

Optimal binary search trees Easy
A. At the deepest level
B. Outside the tree
C. Closer to the root
D. Only at leaf nodes

14 Which traversal of a binary search tree lists its keys in sorted order?

Optimal binary search trees Easy
A. Inorder traversal
B. Level-order traversal
C. Preorder traversal
D. Postorder traversal

15 What does the dynamic programming solution test for each key interval?

Optimal binary search trees Easy
A. Each key as a possible edge
B. Each key as a possible duplicate
C. Each key as a possible color
D. Each key as a possible root

16 What property must an optimal binary search tree preserve?

Optimal binary search trees Easy
A. Complete-tree shape
B. Binary search tree ordering
C. Heap priority ordering
D. Equal subtree heights

17 What do dummy keys represent in the standard optimal binary search tree model?

Optimal binary search trees Easy
A. Unsuccessful searches
B. Repeated successful searches
C. Deleted tree edges
D. Balanced tree levels

18 Which technique avoids repeatedly solving the same optimal-BST subproblems?

Optimal binary search trees Easy
A. Random sampling
B. Depth-first search
C. Linear probing
D. Dynamic programming

19 If all keys have equal search probability, which tree shape generally gives a low search cost?

Optimal binary search trees Easy
A. A right-skewed tree
B. A left-skewed tree
C. A single long chain
D. A balanced tree

20 What is the usual time complexity of the basic dynamic programming algorithm for an optimal BST with keys?

Optimal binary search trees Easy
A.
B.
C.
D.

21 During Floyd–Warshall processing, suppose , , and . What is the updated value of after considering vertex ?

All-pairs shortest paths Medium
A.
B.
C.
D.

22 A directed graph has edges , , , , and . What is the shortest-path distance from to ?

All-pairs shortest paths Medium
A.
B.
C.
D.

23 After Floyd–Warshall finishes, which result indicates that a vertex belongs to or can participate in a reachable negative-weight cycle?

All-pairs shortest paths Medium
A.
B.
C.
D.

24 What are the standard time and space complexities of Floyd–Warshall when its distance table is stored as a matrix?

All-pairs shortest paths Medium
A. time and space
B. time and space
C. time and space
D. time and space

25 In the Floyd–Warshall recurrence, represents the shortest path from to whose intermediate vertices are restricted to which set?

All-pairs shortest paths Medium
A.
B.
C. All vertices except
D.

26 For a sparse directed graph with nonnegative edge weights, which approach usually computes all-pairs shortest paths more efficiently than Floyd–Warshall?

All-pairs shortest paths Medium
A. Run Dijkstra's algorithm from every vertex
B. Run Bellman–Ford from one chosen vertex
C. Run depth-first search from every vertex
D. Run breadth-first search from one vertex

27 A Floyd–Warshall implementation maintains a next-hop matrix. If an update through improves the path from to , how should the next hop for be updated?

All-pairs shortest paths Medium
A. Set it permanently to the intermediate vertex
B. Set it directly to the destination vertex
C. Set it to the next hop from toward
D. Set it to the next hop from toward

28 Using min-plus matrix multiplication, let row of be and column of be . What is the resulting entry ?

All-pairs shortest paths Medium
A.
B.
C.
D.

29 Suppose all-pairs distances are already known and a new directed edge of weight is added without creating a negative cycle. Which expression correctly tests a path from to that uses the new edge?

All-pairs shortest paths Medium
A.
B.
C.
D.

30 Johnson's algorithm assigns each edge the reweighted cost . Why does this preserve shortest paths between each source and destination?

All-pairs shortest paths Medium
A. Every path in the graph is changed to have total weight zero
B. Every source-to-destination path receives a different positive factor
C. Every path between fixed endpoints changes by the same amount
D. Every individual edge keeps exactly the same numerical weight

31 Two ordered keys have successful-search probabilities and . If only successful searches are considered, which root minimizes the expected number of comparisons?

Optimal binary search trees Medium
A. , with expected cost
B. , with expected cost
C. , with expected cost
D. , with expected cost

32 For ordered keys with successful-search frequencies , , and , respectively, which key should be the root of an optimal BST?

Optimal binary search trees Medium
A.
B. Either or
C.
D.

33 When only successful-search frequencies are used, which recurrence correctly defines the optimal weighted search cost ?

Optimal binary search trees Medium
A.
B.
C.
D.

34 In what order should interval entries generally be computed in the dynamic programming table for an optimal BST?

Optimal binary search trees Medium
A. From longer intervals to shorter intervals
B. From the final key toward the first key
C. From higher frequencies to lower frequencies
D. From shorter intervals to longer intervals

35 An optimal-BST algorithm stores the selected root index in . After choosing , which intervals must be recursively reconstructed?

Optimal binary search trees Medium
A. and
B. and
C. and
D. and

36 In an optimal BST that includes unsuccessful-search probabilities, what does conventionally represent?

Optimal binary search trees Medium
A. The cost of comparing with the key
B. A successful search for the key
C. A failed search between and
D. The probability that becomes the root

37 For ordered keys with successful-search frequencies , which root yields the minimum weighted search cost?

Optimal binary search trees Medium
A. , with cost
B. , with cost
C. , with cost
D. , with cost

38 If every successful- and unsuccessful-search probability is multiplied by the same positive constant, how does the optimal BST change?

Optimal binary search trees Medium
A. Its root moves to the smallest key
B. Its root moves to the largest key
C. Its left and right subtrees are exchanged
D. Its optimal structure remains unchanged

39 For four ordered keys with successful-search frequencies , why can choosing the most frequent key as the root be suboptimal?

Optimal binary search trees Medium
A. A root near an endpoint violates the binary-search-tree property
B. A root near the middle can reduce the depths of several other keys
C. The root must always be one of the two middle ordered keys
D. The most frequent key is required to appear at a leaf

40 An optimal BST has one key with successful-search probability and unsuccessful-search probabilities and . Counting the root at depth and dummy leaves at depth , what is the expected search cost?

Optimal binary search trees Medium
A.
B.
C.
D.

41 In Floyd–Warshall, let denote the value after completing iteration . Which invariant precisely supports the recurrence ?

All-pairs shortest paths Hard
A. is the shortest -to- path whose edge weights are at most
B. is the shortest -to- path whose endpoints belong to
C. is the shortest -to- path whose internal vertices belong to
D. is the shortest -to- path containing at most edges

42 After Floyd–Warshall finishes, suppose . For which ordered pairs is the shortest-path value unbounded below because of this negative cycle?

All-pairs shortest paths Hard
A. Exactly those with finite and finite
B. Exactly those with negative or negative
C. Exactly those with finite and finite
D. Exactly those satisfying

43 Let be the weighted adjacency matrix, with and unreachable entries equal to . Under min-plus multiplication, what does the entry of represent?

All-pairs shortest paths Hard
A. The minimum weight of a path using at least edges
B. The minimum weight of a path using exactly nonzero edges
C. The minimum weight of a path using exactly distinct vertices
D. The minimum weight of a path using at most edges

44 Johnson's algorithm computes potentials and defines . If Dijkstra returns in the reweighted graph, which expression recovers the original distance?

All-pairs shortest paths Hard
A.
B.
C.
D.

45 During Johnson's algorithm, Bellman–Ford finds an edge that can still be relaxed after passes from the added super-source. What is the correct conclusion?

All-pairs shortest paths Hard
A. The super-source introduced a negative cycle that can be removed before reweighting
B. The graph is disconnected, so a separate potential must be computed per component
C. The original graph contains a negative-weight cycle, so Johnson's reweighting cannot proceed
D. The original graph contains a negative edge, so every Dijkstra run must use Bellman–Ford

46 Assuming no negative cycles, which loop-order constraint is essential for a correct in-place implementation of Floyd–Warshall?

All-pairs shortest paths Hard
A. Any permutation of the three loops preserves the dynamic-programming invariant
B. The destination loop must be outermost; and may be interchanged
C. The source loop must be outermost; and may be interchanged
D. The intermediate-vertex loop must be outermost; and may be interchanged

47 A graph with known APSP distances receives a new directed edge of weight . Assume the old graph and the updated graph have no negative cycles. Which formula gives every updated distance?

All-pairs shortest paths Hard
A.
B.
C.
D.

48 To compute transitive closure with the Floyd–Warshall structure, which semiring-style replacement is required?

All-pairs shortest paths Hard
A. Replace minimum by XOR, addition by , and initialize the diagonal as true
B. Replace minimum by , addition by , and initialize the diagonal as false
C. Replace minimum by , addition by XOR, and initialize the diagonal as false
D. Replace minimum by , addition by , and initialize the diagonal as true

49 Using Fibonacci heaps, what is the asymptotic running time of Johnson's algorithm on a graph with vertices and edges?

All-pairs shortest paths Hard
A.
B.
C.
D.

50 A Floyd–Warshall implementation stores , the first vertex after on a reconstructed shortest path to . If iteration strictly improves through , how should this entry be updated?

All-pairs shortest paths Hard
A. in every case
B.
C.
D.

51 For successful probabilities , unsuccessful probabilities , base cases , and interval mass , which is the correct optimal-BST recurrence?

Optimal binary search trees Hard
A.
B.
C.
D.

52 For two keys, let , , , , and . Using the standard optimal-BST recurrence, which root and expected cost are optimal?

Optimal binary search trees Hard
A. Root with cost
B. Root with cost
C. Root with cost
D. Root with cost

53 An optimal BST has only successful-search probabilities and charges one comparison at the root. Which root and expected comparison count are optimal?

Optimal binary search trees Hard
A. Root with expected cost
B. Root with expected cost
C. Root with expected cost
D. Root with expected cost

54 Let store an optimal root for interval . Under the standard assumptions enabling Knuth optimization, which range is sufficient when searching for ?

Optimal binary search trees Hard
A.
B.
C.
D.

55 What time and space bounds result when the standard optimal-BST dynamic program uses Knuth's root-monotonicity optimization while retaining its cost and root tables?

Optimal binary search trees Hard
A. time and space
B. time and space
C. time and space
D. time and space

56 Define and , with empty prefixes equal to zero. Which expression computes the interval mass in constant time?

Optimal binary search trees Hard
A.
B.
C.
D.

57 Why does the term appear once in every candidate of the optimal-BST recurrence, independently of the chosen root?

Optimal binary search trees Hard
A. Every key in the interval is compared directly with the chosen root
B. Every item in the two resulting subtrees becomes one level deeper
C. Every unsuccessful search is redirected through both resulting subtrees
D. Every candidate root contributes its probability to each subtree cost

58 All successful and unsuccessful search weights in an optimal-BST instance are multiplied by the same constant . What necessarily happens?

Optimal binary search trees Hard
A. The tree remains optimal only when the original weights sum to one
B. Every optimal root shifts toward the median, while DP costs remain unchanged
C. Only successful-search contributions scale, so the optimal tree may change
D. Every optimal root choice remains valid, and every DP cost is multiplied by

59 For interval , suppose . The relevant left/right cost pairs for roots are respectively , , , and . Which candidate is optimal?

Optimal binary search trees Hard
A. Root with total cost
B. Root with total cost
C. Root with total cost
D. Root with total cost

60 An optimal-root table gives , , , , and . What is the preorder traversal of the reconstructed key tree?

Optimal binary search trees Hard
A.
B.
C.
D.