19What is the initial shortest-path distance from the source vertex to itself?
Single-source shortest paths
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
The source is reached from itself using an empty path, whose total weight is .
Incorrect! Try again.
20Which algorithm can handle negative edge weights when no reachable negative cycle exists?
Single-source shortest paths
Easy
A.Bellman-Ford algorithm
B.Kruskal's algorithm
C.Prim's algorithm
D.Dijkstra's algorithm
Correct Answer: Bellman-Ford algorithm
Explanation:
Bellman-Ford supports negative edge weights and can also detect reachable negative-weight cycles.
Incorrect! Try again.
21Which two properties are typically required to prove that a greedy algorithm produces an optimal solution?
General method
Medium
A.Divide-and-conquer structure and memoization
B.Greedy-choice property and optimal substructure
C.Greedy-choice property and exhaustive search
D.Overlapping subproblems and optimal substructure
Correct Answer: Greedy-choice property and optimal substructure
Explanation:
The greedy-choice property justifies a locally optimal choice, while optimal substructure ensures the remaining problem can also be solved optimally.
Incorrect! Try again.
22A greedy coin-change algorithm repeatedly selects the largest coin not exceeding the remaining amount. For denominations and amount , what does the algorithm produce?
General method
Medium
A.It examines every possible combination before selecting the minimum number of coins
B.Three coins:
C.Two coins:
D.Three coins:
Correct Answer: Three coins:
Explanation:
The algorithm first selects , then two coins. This also shows that the greedy result is not optimal because uses only two coins.
Incorrect! Try again.
23In the activity-selection problem, activities are sorted by finishing time. Which next activity should be selected after choosing an activity that finishes at time ?
General method
Medium
A.The activity with the shortest total duration
B.The compatible activity with the latest start time
C.The compatible activity with the earliest finish time
D.The activity overlapping the fewest remaining activities
Correct Answer: The compatible activity with the earliest finish time
Explanation:
Choosing the next compatible activity that finishes earliest leaves the greatest amount of time available for later activities.
Incorrect! Try again.
24Consider activities , , , , , and . How many activities are selected by the earliest-finish-time greedy method?
General method
Medium
A. activities
B. activities
C. activities
D. activities
Correct Answer: activities
Explanation:
The method can select , then , then , giving three mutually compatible activities.
Incorrect! Try again.
25A fractional knapsack has capacity . Items have values , , and . What maximum profit is obtained?
Knapsack problem
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Select the first two items completely and of the third. The profit is .
Incorrect! Try again.
26For the fractional knapsack problem, which quantity should be used to order items greedily?
Knapsack problem
Medium
A.Increasing item weight
B.Increasing remaining capacity
C.Decreasing profit-to-weight ratio
D.Decreasing item profit
Correct Answer: Decreasing profit-to-weight ratio
Explanation:
Selecting items by decreasing profit per unit weight maximizes the value contributed by each unit of capacity.
Incorrect! Try again.
27A fractional knapsack has capacity and items , , and . What maximum profit can be obtained?
Knapsack problem
Medium
A.All three items are selected completely because their combined profit is greater than the capacity
B.
C.
D.
Correct Answer:
Explanation:
The third item has ratio and is selected first. The remaining units earn , giving .
Incorrect! Try again.
28For a knapsack of capacity , items have values , , and . Why does the profit-to-weight greedy rule fail?
Knapsack problem
Medium
A.It obtains , while the optimum is
B.It obtains , while the optimum is
C.It obtains , while the optimum is
D.It obtains , while the optimum is
Correct Answer: It obtains , while the optimum is
Explanation:
The greedy rule selects the first two items for profit . Selecting the second and third items instead fills the capacity and yields .
Incorrect! Try again.
29An undirected graph has edges , , , , and . Starting Prim's algorithm at , what is the total weight of the resulting MST?
Minimal spanning trees: Prim's algorithm
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Prim's algorithm selects , , and . Their total weight is .
Incorrect! Try again.
30Suppose Prim's algorithm has already included vertices . Which edge is eligible to be selected next?
Minimal spanning trees: Prim's algorithm
Medium
A.The lightest edge having both endpoints inside the tree
B.The globally lightest edge even if it creates a cycle
C.The lightest edge joining the tree to an excluded vertex
D.The edge that reaches the excluded vertex having the largest number of incident edges
Correct Answer: The lightest edge joining the tree to an excluded vertex
Explanation:
Prim's algorithm selects the minimum-weight edge crossing the cut between included and excluded vertices.
Incorrect! Try again.
31If a connected weighted graph has several equal-weight edges, what can happen when Prim's algorithm resolves ties differently?
Minimal spanning trees: Prim's algorithm
Medium
A.It must stop before including every vertex
B.It must produce trees with different total weights
C.It may produce different MSTs with the same total weight
D.It may produce a spanning tree containing a cycle
Correct Answer: It may produce different MSTs with the same total weight
Explanation:
Different safe edges can be chosen when weights tie, potentially producing different minimum spanning trees of equal weight.
Incorrect! Try again.
32Using adjacency lists and a binary min-heap, what is the typical time complexity of Prim's algorithm on a connected graph?
Minimal spanning trees: Prim's algorithm
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Heap operations add a logarithmic factor while vertices and adjacency-list edges are processed, giving .
Incorrect! Try again.
33An undirected graph has edges , , , , , and . What is the MST weight produced by Kruskal's algorithm?
Minimal spanning trees: Kruskal's algorithm
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Kruskal selects and , skips because it forms a cycle, and selects . The total is .
Incorrect! Try again.
34Why does Kruskal's algorithm skip an edge whose endpoints are already in the same disjoint-set component?
Minimal spanning trees: Kruskal's algorithm
Medium
A.The edge would form a cycle
B.The edge is compared with every previously rejected edge before being permanently removed
C.The edge must have negative weight
D.The edge cannot connect two vertices
Correct Answer: The edge would form a cycle
Explanation:
Vertices in the same component are already connected, so adding another edge between them would create a cycle.
Incorrect! Try again.
35Which data structure most efficiently supports cycle detection in Kruskal's algorithm?
Minimal spanning trees: Kruskal's algorithm
Medium
A.Binary search tree
B.Disjoint-set union
C.FIFO queue
D.Adjacency matrix
Correct Answer: Disjoint-set union
Explanation:
Disjoint-set union efficiently determines whether two endpoints belong to different components and merges those components.
Incorrect! Try again.
36What does Kruskal's algorithm produce when it is applied to a disconnected undirected graph?
Minimal spanning trees: Kruskal's algorithm
Medium
A.A maximum-weight connected graph
B.A shortest-path tree
C.A single minimum spanning tree
D.A minimum spanning forest
Correct Answer: A minimum spanning forest
Explanation:
Without enough edges to connect all vertices, Kruskal independently builds a minimum spanning tree for each connected component.
Incorrect! Try again.
37A directed graph has edges , , , , and . What shortest distance from to does Dijkstra's algorithm find?
Single-source shortest paths
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The shortest route is , with total cost .
Incorrect! Try again.
38During edge relaxation, , edge weight , and the current . What is the updated value of ?
Single-source shortest paths
Medium
A.It remains because relaxation updates only vertices that have already been permanently settled
B.
C.
D.
Correct Answer:
Explanation:
Relaxation compares with and replaces the current distance with the smaller value.
Incorrect! Try again.
39Why can standard Dijkstra's algorithm give an incorrect result on a graph containing a reachable negative-weight edge?
Correct Answer: A settled distance may later be reduced
Explanation:
Dijkstra assumes a vertex's distance is final when settled. A later path containing a negative edge can violate that assumption.
Incorrect! Try again.
40A graph has edges , , , , and . In what order are vertices settled by Dijkstra's algorithm?
Single-source shortest paths
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The finalized distances are , , , and , so the settlement order is .
Incorrect! Try again.
41Let be a finite independence system. A greedy algorithm processes elements in nonincreasing order of nonnegative weight and adds an element whenever feasibility is preserved. Under which condition is this algorithm guaranteed to return a maximum-weight feasible set for every weight assignment?
General method
Hard
A.The feasible sets form a matroid.
B.Every maximal feasible set is unique.
C.The feasible sets form a greedoid.
D.Every element belongs to a feasible pair.
Correct Answer: The feasible sets form a matroid.
Explanation:
The hereditary and exchange properties of a matroid are exactly what make weight-ordered greedy selection optimal for every nonnegative weight assignment.
Incorrect! Try again.
42In an exchange-argument proof, a greedy algorithm first chooses . Which statement most directly establishes that this first choice is safe?
General method
Hard
A.Every optimal solution initially contains as its first selected element.
B.The choice has greater value than the entire remaining solution.
C.Removing makes every remaining feasible solution uniquely determined.
D.Some optimal solution can be modified to contain without losing value.
Correct Answer: Some optimal solution can be modified to contain without losing value.
Explanation:
A safe-choice proof shows that at least one optimal solution can exchange other choices for while preserving feasibility and objective value.
Incorrect! Try again.
43For coin denominations and target value , what does the largest-denomination-first greedy rule demonstrate?
General method
Hard
A.It uses six unit coins because divisibility is not preserved.
B.It uses , so negative coins are implicitly required.
C.It uses , although uses fewer coins.
D.It uses , which is the unique optimal representation.
Correct Answer: It uses , although uses fewer coins.
Explanation:
Greedy uses three coins, whereas the optimal solution uses two. Thus, the local largest-coin choice is not safe for arbitrary denomination systems.
Incorrect! Try again.
44Five unit-time jobs have values , , , , and . Using the greedy rule that processes jobs by decreasing profit and places each job in its latest available slot, which schedule is produced?
General method
Hard
A.Slots with profit .
B.Slots with profit .
C.Slots with profit .
D.Slots with profit .
Correct Answer: Slots with profit .
Explanation:
Job occupies slot 2, then occupies slot 1, and occupies slot 3. Jobs and cannot meet their deadlines afterward.
Incorrect! Try again.
45A fractional knapsack of capacity has items , , , and , where each pair is . What solution is obtained by density-ordered greedy selection?
Knapsack problem
Hard
A.Take , , and of for value .
B.Take , , and of for value .
C.Take , , and of for value .
D.Take , , and of for value .
Correct Answer: Take , , and of for value .
Explanation:
The densities are . After taking and , the remaining capacity is , yielding .
Incorrect! Try again.
46A knapsack has capacity and items , , and . What is the outcome of selecting items by decreasing value-to-weight ratio?
Knapsack problem
Hard
A.Greedy selects only for , but gives .
B.Greedy selects for , which is globally optimal.
C.Greedy selects for , but gives .
D.Greedy selects for , but gives .
Correct Answer: Greedy selects for , but gives .
Explanation:
The density order is . After selecting and , item no longer fits, showing why fractional-knapsack greedy is invalid for the version.
Incorrect! Try again.
47Assume all weights are positive and values are nonnegative. Why can an optimal basic solution of the fractional knapsack contain at most one partially selected item?
Knapsack problem
Hard
A.The capacity constraint forces all selected fractions to have equal denominators.
B.Any pair of partial items can always be replaced by one indivisible item.
C.Two partial items can be shifted toward the higher-density item without reducing value.
D.Every partial item must have a density strictly greater than every full item.
Correct Answer: Two partial items can be shifted toward the higher-density item without reducing value.
Explanation:
If two items are partial, weight can be transferred to the higher-density one until one reaches a boundary. Repeating this leaves at most one fractional item.
Incorrect! Try again.
48A fractional knapsack uses the constraint that total weight is at most . Its items are , , and . What is the optimal value?
Knapsack problem
Hard
A., by taking only because it has the greatest weight.
B., by taking all three items and filling the knapsack.
C., by taking and while leaving capacity unused.
D., by taking and using the remaining capacity on .
Correct Answer: , by taking and while leaving capacity unused.
Explanation:
The capacity is an upper bound, not a requirement to fill the knapsack. Taking any positive fraction of negative-value item would reduce the objective.
Incorrect! Try again.
49An undirected graph has edges , , , , , , and . Starting Prim's algorithm at , which edges are selected in order?
Minimal spanning trees: Prim's algorithm
Hard
A., with total weight .
B., with total weight .
C., with total weight .
D., with total weight .
Correct Answer: , with total weight .
Explanation:
From , Prim selects , then . The lightest edge leaving is , after which completes the tree.
Incorrect! Try again.
50A connected undirected graph contains negative edge weights but no other unusual constraints. Which statement about Prim's algorithm is correct?
Minimal spanning trees: Prim's algorithm
Hard
A.It remains correct only after the same constant is added to every edge.
B.It fails unless all negative edges are selected before choosing a start vertex.
C.It remains correct because the cut property does not require nonnegative weights.
D.It fails because selecting a negative edge can later create a negative cycle.
Correct Answer: It remains correct because the cut property does not require nonnegative weights.
Explanation:
Minimum spanning trees are unaffected by the shortest-path concern about negative cycles. Prim's correctness depends on choosing a light edge across a cut.
Incorrect! Try again.
51What happens if standard Prim's algorithm is started in a graph that has multiple connected components?
Minimal spanning trees: Prim's algorithm
Hard
A.One run automatically joins all components using implicit zero-weight edges.
B.One run spans only the start component; restarting produces a minimum spanning forest.
C.The algorithm necessarily reports a cycle when its priority queue becomes empty.
D.One run spans every component but omits one edge from each component.
Correct Answer: One run spans only the start component; restarting produces a minimum spanning forest.
Explanation:
No edge crosses between distinct components. Prim therefore stops after spanning the start component, and separate runs yield an MST for each component.
Incorrect! Try again.
52All edge weights in a connected undirected graph are distinct. How can Prim's output depend on its starting vertex?
Minimal spanning trees: Prim's algorithm
Hard
A.Only the lexicographically smallest start vertex produces the unique MST.
B.The selection order may differ, but every start produces the same unique MST.
C.The final tree may differ, although every produced tree has the same weight.
D.The start vertex determines both the final weight and the number of edges.
Correct Answer: The selection order may differ, but every start produces the same unique MST.
Explanation:
Distinct edge weights guarantee a unique MST. Prim may discover its edges in different orders, but the resulting edge set cannot differ.
Incorrect! Try again.
53An undirected graph has edges , , , , , , and . Which edge set does Kruskal's algorithm select?
Minimal spanning trees: Kruskal's algorithm
Hard
A., with total weight .
B., with total weight .
C., with total weight .
D., with total weight .
Correct Answer: , with total weight .
Explanation:
After selecting , , and , edge is rejected because it closes a cycle. Edge then joins the two remaining components.
Incorrect! Try again.
54Edge is the unique heaviest edge on some cycle of a connected undirected graph. What can Kruskal's cycle property conclude?
Minimal spanning trees: Kruskal's algorithm
Hard
A.Edge must be selected before the other cycle edges.
B.Edge belongs to every minimum spanning tree.
C.Edge is excluded only when all weights are distinct.
D.Edge belongs to no minimum spanning tree.
Correct Answer: Edge belongs to no minimum spanning tree.
Explanation:
If a spanning tree contained , replacing it with a lighter edge from that cycle's induced cut would produce a lower-weight spanning tree.
Incorrect! Try again.
55Using comparison sorting and disjoint sets with union by rank and path compression, what is Kruskal's running time on a graph with vertices and edges?
Minimal spanning trees: Kruskal's algorithm
Hard
A., dominated by edge sorting.
B., dominated by vertex sorting.
C., dominated by cycle detection.
D., dominated by repeated component scans.
Correct Answer: , dominated by edge sorting.
Explanation:
Sorting costs , while all disjoint-set operations together cost . Sorting therefore determines the usual bound.
Incorrect! Try again.
56A graph has MST edges , , and non-tree edges , , . What is the weight of the minimum spanning tree whose weight is strictly greater than the MST weight?
Minimal spanning trees: Kruskal's algorithm
Hard
A., obtained only by replacing edge with edge .
B., obtained by an exchange involving or .
C., obtained by replacing edge with edge .
D., obtained by selecting both and .
Correct Answer: , obtained by an exchange involving or .
Explanation:
The MST weighs . Adding replaces the maximum path edge , and adding replaces ; both exchanges produce weight .
Incorrect! Try again.
57A directed graph has edges , , , , , , and . What settled-vertex order and final distances does Dijkstra's algorithm produce?
Single-source shortest paths
Hard
A.Order ; distances for .
B.Order ; distances for .
C.Order ; distances for .
D.Order ; distances for .
Correct Answer: Order ; distances for .
Explanation:
After settling , the distance to becomes . Settling gives , and settling improves to .
Incorrect! Try again.
58Consider edges , , and . Why can standard Dijkstra's algorithm, which never revisits settled vertices, fail?
Single-source shortest paths
Hard
A.It cannot initialize tentative distances when one edge is negative.
B.It settles at before discovering the true distance through .
C.It settles at before discovering the true distance through .
D.It creates a negative cycle containing , , and .
Correct Answer: It settles at before discovering the true distance through .
Explanation:
A negative edge can later improve an already settled vertex. This violates the greedy invariant that a minimum tentative distance is final.
Incorrect! Try again.
59Which edge-weight condition is sufficient for the standard correctness proof of Dijkstra's single-source shortest-path algorithm?
Single-source shortest paths
Hard
A.Every edge leaving the source has a strictly positive weight.
B.Every simple path has positive total weight, despite negative edges.
C.Every directed cycle has nonnegative total weight, despite negative edges.
D.Every edge weight is nonnegative, including the possibility of zero.
Correct Answer: Every edge weight is nonnegative, including the possibility of zero.
Explanation:
Nonnegative edges ensure that extending a path cannot produce a shorter route to an already settled vertex. Zero-weight edges do not violate this invariant.
Incorrect! Try again.
60For a dense graph with and nonnegative edge weights, which implementation gives the better asymptotic bound for Dijkstra's algorithm?
Single-source shortest paths
Hard
A.A sorted edge array with disjoint sets, taking .
B.A binary heap with adjacency lists, taking .
C.An adjacency matrix with linear minimum selection, taking .
D.A breadth-first queue with adjacency lists, taking .
Correct Answer: An adjacency matrix with linear minimum selection, taking .
Explanation:
For dense graphs, scanning all vertices for each minimum costs , improving on the binary-heap bound .
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 →