Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
You're offline
Unit 5 MCQsMore on Dynamic Programming
ECAP538 ·
60 questions. Pick an option to check it.
Question 1 of 60 · All-pairs shortest paths · Easy
What does the all-pairs shortest paths problem compute?
Not quite. Try another option.
Answer: Shortest paths between every pair of vertices
The problem finds the shortest-path distance for every ordered pair of vertices in a graph.
Question 2 of 60 · All-pairs shortest paths · Easy
Which dynamic programming algorithm commonly solves the all-pairs shortest paths problem?
Not quite. Try another option.
Answer: Floyd-Warshall algorithm
The Floyd-Warshall algorithm uses dynamic programming to compute shortest paths between all pairs of vertices.
Question 3 of 60 · All-pairs shortest paths · Easy
What is the time complexity of the Floyd-Warshall algorithm for vertices?
Not quite. Try another option.
Answer:
Floyd-Warshall uses three nested loops over the graph's vertices, giving a time complexity of .
Question 4 of 60 · All-pairs shortest paths · Easy
What is normally stored in entry of the final Floyd-Warshall matrix?
Not quite. Try another option.
Answer: Distance from to
The final matrix entry stores the shortest-path distance from vertex to vertex .
Question 5 of 60 · All-pairs shortest paths · Easy
What is the usual initial distance from a vertex to itself?
Not quite. Try another option.
Answer:
A path of length zero connects each vertex to itself, so its initial diagonal distance is .
Question 6 of 60 · All-pairs shortest paths · Easy
How is the initial distance from to usually represented when no direct edge exists?
Not quite. Try another option.
Answer:
An absent direct edge is represented by to show that no known direct route exists initially.
Question 7 of 60 · All-pairs shortest paths · Easy
Which update rule is used by the Floyd-Warshall algorithm when considering vertex ?
Not quite. Try another option.
Answer:
The algorithm compares the current route with a route that passes through intermediate vertex .
Question 8 of 60 · All-pairs shortest paths · Easy
Can the Floyd-Warshall algorithm process graphs containing negative edge weights?
Not quite. Try another option.
Answer: Yes, if no negative cycle exists
Floyd-Warshall supports negative edge weights, but shortest paths are not well-defined when a reachable negative cycle exists.
Question 9 of 60 · All-pairs shortest paths · Easy
After Floyd-Warshall finishes, what indicates a negative cycle?
Not quite. Try another option.
Answer: A diagonal entry is negative
A negative value means that a negative-cost cycle is reachable from vertex .
Question 10 of 60 · All-pairs shortest paths · Easy
Which graph representation is most directly used by the Floyd-Warshall algorithm?
Not quite. Try another option.
Answer: Distance matrix
Floyd-Warshall repeatedly updates a matrix containing distances between pairs of vertices.
Question 11 of 60 · Optimal binary search trees · Easy
What is the main objective of an optimal binary search tree?
Not quite. Try another option.
Answer: Minimize the expected search cost
An optimal binary search tree arranges keys to minimize the expected number or cost of comparisons.
Question 12 of 60 · Optimal binary search trees · Easy
What information is primarily used to construct an optimal binary search tree?
Not quite. Try another option.
Answer: Search probabilities of the keys
Search probabilities determine how frequently keys are accessed and therefore influence their best positions.
Question 13 of 60 · Optimal binary search trees · Easy
Where are frequently searched keys generally placed in an optimal binary search tree?
Not quite. Try another option.
Answer: Closer to the root
Placing frequently searched keys near the root reduces their expected number of comparisons.
Question 14 of 60 · Optimal binary search trees · Easy
Which traversal of a binary search tree lists its keys in sorted order?
Not quite. Try another option.
Answer: Inorder traversal
An inorder traversal visits the keys of a binary search tree in ascending sorted order.
Question 15 of 60 · Optimal binary search trees · Easy
What does the dynamic programming solution test for each key interval?
Not quite. Try another option.
Answer: Each key as a possible root
The algorithm considers every key in an interval as its root and selects the choice with minimum expected cost.
Question 16 of 60 · Optimal binary search trees · Easy
What property must an optimal binary search tree preserve?
Not quite. Try another option.
Answer: Binary search tree ordering
An optimal binary search tree remains a binary search tree, with smaller keys on the left and larger keys on the right.
Question 17 of 60 · Optimal binary search trees · Easy
What do dummy keys represent in the standard optimal binary search tree model?
Not quite. Try another option.
Answer: Unsuccessful searches
Dummy keys represent gaps between actual keys where unsuccessful searches can terminate.
Question 18 of 60 · Optimal binary search trees · Easy
Which technique avoids repeatedly solving the same optimal-BST subproblems?
Not quite. Try another option.
Answer: Dynamic programming
Dynamic programming stores solutions for key intervals so that overlapping subproblems are not recomputed.
Question 19 of 60 · Optimal binary search trees · Easy
If all keys have equal search probability, which tree shape generally gives a low search cost?
Not quite. Try another option.
Answer: A balanced tree
With equal probabilities, keeping key depths small through a balanced shape generally minimizes average search cost.
Question 20 of 60 · Optimal binary search trees · Easy
What is the usual time complexity of the basic dynamic programming algorithm for an optimal BST with keys?
Not quite. Try another option.
Answer:
The basic method examines key intervals and tries up to roots for each interval.
Question 21 of 60 · All-pairs shortest paths · Medium
During Floyd–Warshall processing, suppose , , and . What is the updated value of after considering vertex ?
Not quite. Try another option.
Answer:
The update is .
Question 22 of 60 · All-pairs shortest paths · Medium
A directed graph has edges , , , , and . What is the shortest-path distance from to ?
Not quite. Try another option.
Answer:
The path has cost , which is smaller than the alternatives.
Question 23 of 60 · All-pairs shortest paths · Medium
After Floyd–Warshall finishes, which result indicates that a vertex belongs to or can participate in a reachable negative-weight cycle?
Not quite. Try another option.
Answer:
A negative diagonal entry means there is a path from back to itself with negative total weight.
Question 24 of 60 · All-pairs shortest paths · Medium
What are the standard time and space complexities of Floyd–Warshall when its distance table is stored as a matrix?
Not quite. Try another option.
Answer: time and space
The algorithm examines every ordered triple of vertices and stores one distance for every ordered vertex pair.
Question 25 of 60 · All-pairs shortest paths · Medium
In the Floyd–Warshall recurrence, represents the shortest path from to whose intermediate vertices are restricted to which set?
Not quite. Try another option.
Answer:
Iteration permits the first vertices to be used as intermediate vertices.
Question 26 of 60 · All-pairs shortest paths · Medium
For a sparse directed graph with nonnegative edge weights, which approach usually computes all-pairs shortest paths more efficiently than Floyd–Warshall?
Not quite. Try another option.
Answer: Run Dijkstra's algorithm from every vertex
With nonnegative weights, repeated Dijkstra runs in about with a suitable heap and can outperform on sparse graphs.
Question 27 of 60 · All-pairs shortest paths · Medium
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?
Not quite. Try another option.
Answer: Set it to the next hop from toward
The improved path begins by following the known path from to , so its first hop is the first hop of that subpath.
Question 28 of 60 · All-pairs shortest paths · Medium
Using min-plus matrix multiplication, let row of be and column of be . What is the resulting entry ?
Not quite. Try another option.
Answer:
Min-plus multiplication gives .
Question 29 of 60 · All-pairs shortest paths · Medium
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?
Not quite. Try another option.
Answer:
Such a path goes from to , crosses the new edge to , and then continues from to .
Question 30 of 60 · All-pairs shortest paths · Medium
Johnson's algorithm assigns each edge the reweighted cost . Why does this preserve shortest paths between each source and destination?
Not quite. Try another option.
Answer: Every path between fixed endpoints changes by the same amount
The potential terms telescope, so every path from to changes by and their relative ordering is preserved.
Question 31 of 60 · Optimal binary search trees · Medium
Two ordered keys have successful-search probabilities and . If only successful searches are considered, which root minimizes the expected number of comparisons?
Not quite. Try another option.
Answer: , with expected cost
Placing at depth gives cost .
Question 32 of 60 · Optimal binary search trees · Medium
For ordered keys with successful-search frequencies , , and , respectively, which key should be the root of an optimal BST?
Not quite. Try another option.
Answer:
The weighted costs for roots , , and are , , and , respectively.
Question 33 of 60 · Optimal binary search trees · Medium
When only successful-search frequencies are used, which recurrence correctly defines the optimal weighted search cost ?
Not quite. Try another option.
Answer:
Choosing a root increases the depth of every key in its left and right subtrees by one, contributing the interval's total frequency.
Question 34 of 60 · Optimal binary search trees · Medium
In what order should interval entries generally be computed in the dynamic programming table for an optimal BST?
Not quite. Try another option.
Answer: From shorter intervals to longer intervals
The value for an interval depends on values for its smaller left and right subintervals.
Question 35 of 60 · Optimal binary search trees · Medium
An optimal-BST algorithm stores the selected root index in . After choosing , which intervals must be recursively reconstructed?
Not quite. Try another option.
Answer: and
Keys smaller than form the left subtree, while keys larger than form the right subtree.
Question 36 of 60 · Optimal binary search trees · Medium
In an optimal BST that includes unsuccessful-search probabilities, what does conventionally represent?
Not quite. Try another option.
Answer: A failed search between and
The values correspond to dummy leaves representing gaps between consecutive keys, including the two outer gaps.
Question 37 of 60 · Optimal binary search trees · Medium
For ordered keys with successful-search frequencies , which root yields the minimum weighted search cost?
Not quite. Try another option.
Answer: , with cost
Using as root and as the left-subtree root gives .
Question 38 of 60 · Optimal binary search trees · Medium
If every successful- and unsuccessful-search probability is multiplied by the same positive constant, how does the optimal BST change?
Not quite. Try another option.
Answer: Its optimal structure remains unchanged
Scaling all probabilities multiplies every candidate tree's cost by the same positive constant, preserving their ordering.
Question 39 of 60 · Optimal binary search trees · Medium
For four ordered keys with successful-search frequencies , why can choosing the most frequent key as the root be suboptimal?
Not quite. Try another option.
Answer: A root near the middle can reduce the depths of several other keys
Optimality depends on the total weighted depth, so balancing several moderately frequent keys can outweigh placing the largest frequency at the root.
Question 40 of 60 · Optimal binary search trees · Medium
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?
Not quite. Try another option.
Answer:
The expected cost is .
Question 41 of 60 · All-pairs shortest paths · Hard
In Floyd–Warshall, let denote the value after completing iteration . Which invariant precisely supports the recurrence ?
Not quite. Try another option.
Answer: is the shortest -to- path whose internal vertices belong to
A qualifying shortest path either avoids vertex internally or splits at into two paths using only internal vertices from .
Question 42 of 60 · All-pairs shortest paths · Hard
After Floyd–Warshall finishes, suppose . For which ordered pairs is the shortest-path value unbounded below because of this negative cycle?
Not quite. Try another option.
Answer: Exactly those with finite and finite
The pair is affected precisely when can reach the negative cycle and the cycle can reach . Repeating the cycle then drives the walk cost toward .
Question 43 of 60 · All-pairs shortest paths · Hard
Let be the weighted adjacency matrix, with and unreachable entries equal to . Under min-plus multiplication, what does the entry of represent?
Not quite. Try another option.
Answer: The minimum weight of a path using at most edges
The zero diagonal permits padding a path with zero-cost self-transitions, so an exactly- min-plus product represents paths using at most original edges.
Question 44 of 60 · All-pairs shortest paths · Hard
Johnson's algorithm computes potentials and defines . If Dijkstra returns in the reweighted graph, which expression recovers the original distance?
Not quite. Try another option.
Answer:
Potential terms telescope along a path, giving . Rearranging yields the original distance.
Question 45 of 60 · All-pairs shortest paths · Hard
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?
Not quite. Try another option.
Answer: The original graph contains a negative-weight cycle, so Johnson's reweighting cannot proceed
The super-source has only zero-weight outgoing edges and makes every original vertex reachable. A further relaxation therefore reveals a negative cycle in the original graph.
Question 46 of 60 · All-pairs shortest paths · Hard
Assuming no negative cycles, which loop-order constraint is essential for a correct in-place implementation of Floyd–Warshall?
Not quite. Try another option.
Answer: The intermediate-vertex loop must be outermost; and may be interchanged
Each stage must finish all updates using intermediate vertices through before stage begins. Making or outermost mixes incompatible stages.
Question 47 of 60 · All-pairs shortest paths · Hard
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?
Not quite. Try another option.
Answer:
Any newly improved simple shortest path uses the inserted edge once, preceded by an old shortest path to and followed by an old shortest path from .
Question 48 of 60 · All-pairs shortest paths · Hard
To compute transitive closure with the Floyd–Warshall structure, which semiring-style replacement is required?
Not quite. Try another option.
Answer: Replace minimum by , addition by , and initialize the diagonal as true
A route exists either already or by joining two existing routes through , giving .
Question 49 of 60 · All-pairs shortest paths · Hard
Using Fibonacci heaps, what is the asymptotic running time of Johnson's algorithm on a graph with vertices and edges?
Not quite. Try another option.
Answer:
Bellman–Ford costs . The Dijkstra executions cost in total with Fibonacci heaps.
Question 50 of 60 · All-pairs shortest paths · Hard
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?
Not quite. Try another option.
Answer:
The improved route first follows the reconstructed path from toward , so its first hop is the first hop of the -to- path.
Question 51 of 60 · Optimal binary search trees · Hard
For successful probabilities , unsuccessful probabilities , base cases , and interval mass , which is the correct optimal-BST recurrence?
Not quite. Try another option.
Answer:
Choosing root separates the ordered keys into two independent intervals. Every item in both subtrees moves one level deeper, adding total mass .
Question 52 of 60 · Optimal binary search trees · Hard
For two keys, let , , , , and . Using the standard optimal-BST recurrence, which root and expected cost are optimal?
Not quite. Try another option.
Answer: Root with cost
The one-key costs are and . The two root choices cost and , respectively.
Question 53 of 60 · Optimal binary search trees · Hard
An optimal BST has only successful-search probabilities and charges one comparison at the root. Which root and expected comparison count are optimal?
Not quite. Try another option.
Answer: Root with expected cost
Placing at depth one and the other keys at depth two gives , lower than either endpoint root.
Question 54 of 60 · Optimal binary search trees · Hard
Let store an optimal root for interval . Under the standard assumptions enabling Knuth optimization, which range is sufficient when searching for ?
Not quite. Try another option.
Answer:
Optimal roots are monotone across adjacent intervals. Restricting candidates to this inclusive range reduces the total number of root evaluations.
Question 55 of 60 · Optimal binary search trees · Hard
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?
Not quite. Try another option.
Answer: time and space
Monotone candidate ranges reduce all root searches to quadratic total work. The interval cost and root tables still contain entries.
Question 56 of 60 · Optimal binary search trees · Hard
Define and , with empty prefixes equal to zero. Which expression computes the interval mass in constant time?
Not quite. Try another option.
Answer:
The interval contains successful probabilities through and unsuccessful probabilities through .
Question 57 of 60 · Optimal binary search trees · Hard
Why does the term appear once in every candidate of the optimal-BST recurrence, independently of the chosen root?
Not quite. Try another option.
Answer: Every item in the two resulting subtrees becomes one level deeper
Subproblem costs treat their subtree roots as local top levels. Attaching them below the selected root increases every included key and dummy-leaf depth by one.
Question 58 of 60 · Optimal binary search trees · Hard
All successful and unsuccessful search weights in an optimal-BST instance are multiplied by the same constant . What necessarily happens?
Not quite. Try another option.
Answer: Every optimal root choice remains valid, and every DP cost is multiplied by
Each candidate cost is linear in the weights. Positive uniform scaling preserves all comparisons between candidates, including ties.
Question 59 of 60 · Optimal binary search trees · Hard
For interval , suppose . The relevant left/right cost pairs for roots are respectively , , , and . Which candidate is optimal?
Not quite. Try another option.
Answer: Root with total cost
Adding gives candidate costs , , , and . The minimum is attained at root .
Question 60 of 60 · Optimal binary search trees · Hard
An optimal-root table gives , , , , and . What is the preorder traversal of the reconstructed key tree?
Not quite. Try another option.
Answer:
The full root is . Its left subtree has root with right child , while its right subtree has root with left child .
That's unit 5
Answer a few questions and your score shows up here.
Nearly through. Did unit 5 of ECAP538 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 5 of ECAP538 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.