The Floyd-Warshall algorithm uses dynamic programming to compute shortest paths between all pairs of vertices.
Incorrect! Try again.
3What is the time complexity of the Floyd-Warshall algorithm for vertices?
All-pairs shortest paths
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Floyd-Warshall uses three nested loops over the graph's vertices, giving a time complexity of .
Incorrect! Try again.
4What 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
Correct Answer: Distance from to
Explanation:
The final matrix entry stores the shortest-path distance from vertex to vertex .
Incorrect! Try again.
5What is the usual initial distance from a vertex to itself?
All-pairs shortest paths
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
A path of length zero connects each vertex to itself, so its initial diagonal distance is .
Incorrect! Try again.
6How is the initial distance from to usually represented when no direct edge exists?
All-pairs shortest paths
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
An absent direct edge is represented by to show that no known direct route exists initially.
Incorrect! Try again.
7Which update rule is used by the Floyd-Warshall algorithm when considering vertex ?
All-pairs shortest paths
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
The algorithm compares the current route with a route that passes through intermediate vertex .
Incorrect! Try again.
8Can 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
Correct Answer: Yes, if no negative cycle exists
Explanation:
Floyd-Warshall supports negative edge weights, but shortest paths are not well-defined when a reachable negative cycle exists.
Incorrect! Try again.
9After 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
Correct Answer: A diagonal entry is negative
Explanation:
A negative value means that a negative-cost cycle is reachable from vertex .
Incorrect! Try again.
10Which 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
Correct Answer: Distance matrix
Explanation:
Floyd-Warshall repeatedly updates a matrix containing distances between pairs of vertices.
Incorrect! Try again.
11What 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
Correct Answer: Minimize the expected search cost
Explanation:
An optimal binary search tree arranges keys to minimize the expected number or cost of comparisons.
Incorrect! Try again.
12What 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
Correct Answer: Search probabilities of the keys
Explanation:
Search probabilities determine how frequently keys are accessed and therefore influence their best positions.
Incorrect! Try again.
13Where 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
Correct Answer: Closer to the root
Explanation:
Placing frequently searched keys near the root reduces their expected number of comparisons.
Incorrect! Try again.
14Which 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
Correct Answer: Inorder traversal
Explanation:
An inorder traversal visits the keys of a binary search tree in ascending sorted order.
Incorrect! Try again.
15What 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
Correct Answer: Each key as a possible root
Explanation:
The algorithm considers every key in an interval as its root and selects the choice with minimum expected cost.
Incorrect! Try again.
16What 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
Correct Answer: Binary search tree ordering
Explanation:
An optimal binary search tree remains a binary search tree, with smaller keys on the left and larger keys on the right.
Incorrect! Try again.
17What 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
Correct Answer: Unsuccessful searches
Explanation:
Dummy keys represent gaps between actual keys where unsuccessful searches can terminate.
Incorrect! Try again.
18Which 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
Correct Answer: Dynamic programming
Explanation:
Dynamic programming stores solutions for key intervals so that overlapping subproblems are not recomputed.
Incorrect! Try again.
19If 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
Correct Answer: A balanced tree
Explanation:
With equal probabilities, keeping key depths small through a balanced shape generally minimizes average search cost.
Incorrect! Try again.
20What 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.
Correct Answer:
Explanation:
The basic method examines key intervals and tries up to roots for each interval.
Incorrect! Try again.
21During Floyd–Warshall processing, suppose , , and . What is the updated value of after considering vertex ?
All-pairs shortest paths
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The update is .
Incorrect! Try again.
22A directed graph has edges , , , , and . What is the shortest-path distance from to ?
All-pairs shortest paths
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The path has cost , which is smaller than the alternatives.
Incorrect! Try again.
23After 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.
Correct Answer:
Explanation:
A negative diagonal entry means there is a path from back to itself with negative total weight.
Incorrect! Try again.
24What 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
Correct Answer: time and space
Explanation:
The algorithm examines every ordered triple of vertices and stores one distance for every ordered vertex pair.
Incorrect! Try again.
25In 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.
Correct Answer:
Explanation:
Iteration permits the first vertices to be used as intermediate vertices.
Incorrect! Try again.
26For 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
Correct Answer: Run Dijkstra's algorithm from every vertex
Explanation:
With nonnegative weights, repeated Dijkstra runs in about with a suitable heap and can outperform on sparse graphs.
Incorrect! Try again.
27A 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
Correct Answer: Set it to the next hop from toward
Explanation:
The improved path begins by following the known path from to , so its first hop is the first hop of that subpath.
Incorrect! Try again.
28Using 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.
Correct Answer:
Explanation:
Min-plus multiplication gives .
Incorrect! Try again.
29Suppose 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.
Correct Answer:
Explanation:
Such a path goes from to , crosses the new edge to , and then continues from to .
Incorrect! Try again.
30Johnson'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
Correct Answer: Every path between fixed endpoints changes by the same amount
Explanation:
The potential terms telescope, so every path from to changes by and their relative ordering is preserved.
Incorrect! Try again.
31Two 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
Correct Answer: , with expected cost
Explanation:
Placing at depth gives cost .
Incorrect! Try again.
32For 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.
Correct Answer:
Explanation:
The weighted costs for roots , , and are , , and , respectively.
Incorrect! Try again.
33When only successful-search frequencies are used, which recurrence correctly defines the optimal weighted search cost ?
Optimal binary search trees
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Choosing a root increases the depth of every key in its left and right subtrees by one, contributing the interval's total frequency.
Incorrect! Try again.
34In 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
Correct Answer: From shorter intervals to longer intervals
Explanation:
The value for an interval depends on values for its smaller left and right subintervals.
Incorrect! Try again.
35An 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
Correct Answer: and
Explanation:
Keys smaller than form the left subtree, while keys larger than form the right subtree.
Incorrect! Try again.
36In 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
Correct Answer: A failed search between and
Explanation:
The values correspond to dummy leaves representing gaps between consecutive keys, including the two outer gaps.
Incorrect! Try again.
37For 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
Correct Answer: , with cost
Explanation:
Using as root and as the left-subtree root gives .
Incorrect! Try again.
38If 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
Correct Answer: Its optimal structure remains unchanged
Explanation:
Scaling all probabilities multiplies every candidate tree's cost by the same positive constant, preserving their ordering.
Incorrect! Try again.
39For 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
Correct Answer: A root near the middle can reduce the depths of several other keys
Explanation:
Optimality depends on the total weighted depth, so balancing several moderately frequent keys can outweigh placing the largest frequency at the root.
Incorrect! Try again.
40An 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.
Correct Answer:
Explanation:
The expected cost is .
Incorrect! Try again.
41In 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
Correct Answer: is the shortest -to- path whose internal vertices belong to
Explanation:
A qualifying shortest path either avoids vertex internally or splits at into two paths using only internal vertices from .
Incorrect! Try again.
42After 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
Correct Answer: Exactly those with finite and finite
Explanation:
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 .
Incorrect! Try again.
43Let 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
Correct Answer: The minimum weight of a path using at most edges
Explanation:
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.
Incorrect! Try again.
44Johnson'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.
Correct Answer:
Explanation:
Potential terms telescope along a path, giving . Rearranging yields the original distance.
Incorrect! Try again.
45During 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
Correct Answer: The original graph contains a negative-weight cycle, so Johnson's reweighting cannot proceed
Explanation:
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.
Incorrect! Try again.
46Assuming 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
Correct Answer: The intermediate-vertex loop must be outermost; and may be interchanged
Explanation:
Each stage must finish all updates using intermediate vertices through before stage begins. Making or outermost mixes incompatible stages.
Incorrect! Try again.
47A 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.
Correct Answer:
Explanation:
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 .
Incorrect! Try again.
48To 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
Correct Answer: Replace minimum by , addition by , and initialize the diagonal as true
Explanation:
A route exists either already or by joining two existing routes through , giving .
Incorrect! Try again.
49Using 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.
Correct Answer:
Explanation:
Bellman–Ford costs . The Dijkstra executions cost in total with Fibonacci heaps.
Incorrect! Try again.
50A 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.
Correct Answer:
Explanation:
The improved route first follows the reconstructed path from toward , so its first hop is the first hop of the -to- path.
Incorrect! Try again.
51For 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.
Correct Answer:
Explanation:
Choosing root separates the ordered keys into two independent intervals. Every item in both subtrees moves one level deeper, adding total mass .
Incorrect! Try again.
52For 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
Correct Answer: Root with cost
Explanation:
The one-key costs are and . The two root choices cost and , respectively.
Incorrect! Try again.
53An 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
Correct Answer: Root with expected cost
Explanation:
Placing at depth one and the other keys at depth two gives , lower than either endpoint root.
Incorrect! Try again.
54Let 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.
Correct Answer:
Explanation:
Optimal roots are monotone across adjacent intervals. Restricting candidates to this inclusive range reduces the total number of root evaluations.
Incorrect! Try again.
55What 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
Correct Answer: time and space
Explanation:
Monotone candidate ranges reduce all root searches to quadratic total work. The interval cost and root tables still contain entries.
Incorrect! Try again.
56Define 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.
Correct Answer:
Explanation:
The interval contains successful probabilities through and unsuccessful probabilities through .
Incorrect! Try again.
57Why 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
Correct Answer: Every item in the two resulting subtrees becomes one level deeper
Explanation:
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.
Incorrect! Try again.
58All 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
Correct Answer: Every optimal root choice remains valid, and every DP cost is multiplied by
Explanation:
Each candidate cost is linear in the weights. Positive uniform scaling preserves all comparisons between candidates, including ties.
Incorrect! Try again.
59For 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
Correct Answer: Root with total cost
Explanation:
Adding gives candidate costs , , , and . The minimum is attained at root .
Incorrect! Try again.
60An optimal-root table gives , , , , and . What is the preorder traversal of the reconstructed key tree?
Optimal binary search trees
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The full root is . Its left subtree has root with right child , while its right subtree has root with left child .
Incorrect! Try again.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. 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.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it.
What it pays for →