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 3 MCQsGreedy Method
ECAP538 ·
60 questions. Pick an option to check it.
Question 19 of 60 · Single-source shortest paths · Easy
What is the initial shortest-path distance from the source vertex to itself?
Not quite. Try another option.
Answer:
The source is reached from itself using an empty path, whose total weight is .
Question 20 of 60 · Single-source shortest paths · Easy
Which algorithm can handle negative edge weights when no reachable negative cycle exists?
Not quite. Try another option.
Answer: Bellman-Ford algorithm
Bellman-Ford supports negative edge weights and can also detect reachable negative-weight cycles.
Question 21 of 60 · General method · Medium
Which two properties are typically required to prove that a greedy algorithm produces an optimal solution?
Not quite. Try another option.
Answer: Greedy-choice property and optimal substructure
The greedy-choice property justifies a locally optimal choice, while optimal substructure ensures the remaining problem can also be solved optimally.
Question 22 of 60 · General method · Medium
A greedy coin-change algorithm repeatedly selects the largest coin not exceeding the remaining amount. For denominations and amount , what does the algorithm produce?
Not quite. Try another option.
Answer: Three coins:
The algorithm first selects , then two coins. This also shows that the greedy result is not optimal because uses only two coins.
Question 23 of 60 · General method · Medium
In the activity-selection problem, activities are sorted by finishing time. Which next activity should be selected after choosing an activity that finishes at time ?
Not quite. Try another option.
Answer: The compatible activity with the earliest finish time
Choosing the next compatible activity that finishes earliest leaves the greatest amount of time available for later activities.
Question 24 of 60 · General method · Medium
Consider activities , , , , , and . How many activities are selected by the earliest-finish-time greedy method?
Not quite. Try another option.
Answer: activities
The method can select , then , then , giving three mutually compatible activities.
Question 25 of 60 · Knapsack problem · Medium
A fractional knapsack has capacity . Items have values , , and . What maximum profit is obtained?
Not quite. Try another option.
Answer:
Select the first two items completely and of the third. The profit is .
Question 26 of 60 · Knapsack problem · Medium
For the fractional knapsack problem, which quantity should be used to order items greedily?
Not quite. Try another option.
Answer: Decreasing profit-to-weight ratio
Selecting items by decreasing profit per unit weight maximizes the value contributed by each unit of capacity.
Question 27 of 60 · Knapsack problem · Medium
A fractional knapsack has capacity and items , , and . What maximum profit can be obtained?
Not quite. Try another option.
Answer:
The third item has ratio and is selected first. The remaining units earn , giving .
Question 28 of 60 · Knapsack problem · Medium
For a knapsack of capacity , items have values , , and . Why does the profit-to-weight greedy rule fail?
Not quite. Try another option.
Answer: It obtains , while the optimum is
The greedy rule selects the first two items for profit . Selecting the second and third items instead fills the capacity and yields .
Question 29 of 60 · Minimal spanning trees: Prim's algorithm · Medium
An undirected graph has edges , , , , and . Starting Prim's algorithm at , what is the total weight of the resulting MST?
Not quite. Try another option.
Answer:
Prim's algorithm selects , , and . Their total weight is .
Question 30 of 60 · Minimal spanning trees: Prim's algorithm · Medium
Suppose Prim's algorithm has already included vertices . Which edge is eligible to be selected next?
Not quite. Try another option.
Answer: The lightest edge joining the tree to an excluded vertex
Prim's algorithm selects the minimum-weight edge crossing the cut between included and excluded vertices.
Question 31 of 60 · Minimal spanning trees: Prim's algorithm · Medium
If a connected weighted graph has several equal-weight edges, what can happen when Prim's algorithm resolves ties differently?
Not quite. Try another option.
Answer: It may produce different MSTs with the same total weight
Different safe edges can be chosen when weights tie, potentially producing different minimum spanning trees of equal weight.
Question 32 of 60 · Minimal spanning trees: Prim's algorithm · Medium
Using adjacency lists and a binary min-heap, what is the typical time complexity of Prim's algorithm on a connected graph?
Not quite. Try another option.
Answer:
Heap operations add a logarithmic factor while vertices and adjacency-list edges are processed, giving .
Question 33 of 60 · Minimal spanning trees: Kruskal's algorithm · Medium
An undirected graph has edges , , , , , and . What is the MST weight produced by Kruskal's algorithm?
Not quite. Try another option.
Answer:
Kruskal selects and , skips because it forms a cycle, and selects . The total is .
Question 34 of 60 · Minimal spanning trees: Kruskal's algorithm · Medium
Why does Kruskal's algorithm skip an edge whose endpoints are already in the same disjoint-set component?
Not quite. Try another option.
Answer: The edge would form a cycle
Vertices in the same component are already connected, so adding another edge between them would create a cycle.
Question 35 of 60 · Minimal spanning trees: Kruskal's algorithm · Medium
Which data structure most efficiently supports cycle detection in Kruskal's algorithm?
Not quite. Try another option.
Answer: Disjoint-set union
Disjoint-set union efficiently determines whether two endpoints belong to different components and merges those components.
Question 36 of 60 · Minimal spanning trees: Kruskal's algorithm · Medium
What does Kruskal's algorithm produce when it is applied to a disconnected undirected graph?
Not quite. Try another option.
Answer: A minimum spanning forest
Without enough edges to connect all vertices, Kruskal independently builds a minimum spanning tree for each connected component.
Question 37 of 60 · Single-source shortest paths · Medium
A directed graph has edges , , , , and . What shortest distance from to does Dijkstra's algorithm find?
Not quite. Try another option.
Answer:
The shortest route is , with total cost .
Question 38 of 60 · Single-source shortest paths · Medium
During edge relaxation, , edge weight , and the current . What is the updated value of ?
Not quite. Try another option.
Answer:
Relaxation compares with and replaces the current distance with the smaller value.
Question 39 of 60 · Single-source shortest paths · Medium
Why can standard Dijkstra's algorithm give an incorrect result on a graph containing a reachable negative-weight edge?
Not quite. Try another option.
Answer: A settled distance may later be reduced
Dijkstra assumes a vertex's distance is final when settled. A later path containing a negative edge can violate that assumption.
Question 40 of 60 · Single-source shortest paths · Medium
A graph has edges , , , , and . In what order are vertices settled by Dijkstra's algorithm?
Not quite. Try another option.
Answer:
The finalized distances are , , , and , so the settlement order is .
Question 41 of 60 · General method · Hard
Let 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?
Not quite. Try another option.
Answer: The feasible sets form a matroid.
The hereditary and exchange properties of a matroid are exactly what make weight-ordered greedy selection optimal for every nonnegative weight assignment.
Question 42 of 60 · General method · Hard
In an exchange-argument proof, a greedy algorithm first chooses . Which statement most directly establishes that this first choice is safe?
Not quite. Try another option.
Answer: Some optimal solution can be modified to contain without losing value.
A safe-choice proof shows that at least one optimal solution can exchange other choices for while preserving feasibility and objective value.
Question 43 of 60 · General method · Hard
For coin denominations and target value , what does the largest-denomination-first greedy rule demonstrate?
Not quite. Try another option.
Answer: It uses , although uses fewer coins.
Greedy uses three coins, whereas the optimal solution uses two. Thus, the local largest-coin choice is not safe for arbitrary denomination systems.
Question 44 of 60 · General method · Hard
Five 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?
Not quite. Try another option.
Answer: Slots with profit .
Job occupies slot 2, then occupies slot 1, and occupies slot 3. Jobs and cannot meet their deadlines afterward.
Question 45 of 60 · Knapsack problem · Hard
A fractional knapsack of capacity has items , , , and , where each pair is . What solution is obtained by density-ordered greedy selection?
Not quite. Try another option.
Answer: Take , , and of for value .
The densities are . After taking and , the remaining capacity is , yielding .
Question 46 of 60 · Knapsack problem · Hard
A knapsack has capacity and items , , and . What is the outcome of selecting items by decreasing value-to-weight ratio?
Not quite. Try another option.
Answer: Greedy selects for , but gives .
The density order is . After selecting and , item no longer fits, showing why fractional-knapsack greedy is invalid for the version.
Question 47 of 60 · Knapsack problem · Hard
Assume 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?
Not quite. Try another option.
Answer: Two partial items can be shifted toward the higher-density item without reducing value.
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.
Question 48 of 60 · Knapsack problem · Hard
A fractional knapsack uses the constraint that total weight is at most . Its items are , , and . What is the optimal value?
Not quite. Try another option.
Answer: , by taking and while leaving capacity unused.
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.
Question 49 of 60 · Minimal spanning trees: Prim's algorithm · Hard
An undirected graph has edges , , , , , , and . Starting Prim's algorithm at , which edges are selected in order?
Not quite. Try another option.
Answer: , with total weight .
From , Prim selects , then . The lightest edge leaving is , after which completes the tree.
Question 50 of 60 · Minimal spanning trees: Prim's algorithm · Hard
A connected undirected graph contains negative edge weights but no other unusual constraints. Which statement about Prim's algorithm is correct?
Not quite. Try another option.
Answer: It remains correct because the cut property does not require nonnegative weights.
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.
Question 51 of 60 · Minimal spanning trees: Prim's algorithm · Hard
What happens if standard Prim's algorithm is started in a graph that has multiple connected components?
Not quite. Try another option.
Answer: One run spans only the start component; restarting produces a minimum spanning forest.
No edge crosses between distinct components. Prim therefore stops after spanning the start component, and separate runs yield an MST for each component.
Question 52 of 60 · Minimal spanning trees: Prim's algorithm · Hard
All edge weights in a connected undirected graph are distinct. How can Prim's output depend on its starting vertex?
Not quite. Try another option.
Answer: The selection order may differ, but every start produces the same unique MST.
Distinct edge weights guarantee a unique MST. Prim may discover its edges in different orders, but the resulting edge set cannot differ.
Question 53 of 60 · Minimal spanning trees: Kruskal's algorithm · Hard
An undirected graph has edges , , , , , , and . Which edge set does Kruskal's algorithm select?
Not quite. Try another option.
Answer: , with total weight .
After selecting , , and , edge is rejected because it closes a cycle. Edge then joins the two remaining components.
Question 54 of 60 · Minimal spanning trees: Kruskal's algorithm · Hard
Edge is the unique heaviest edge on some cycle of a connected undirected graph. What can Kruskal's cycle property conclude?
Not quite. Try another option.
Answer: Edge belongs to no minimum spanning tree.
If a spanning tree contained , replacing it with a lighter edge from that cycle's induced cut would produce a lower-weight spanning tree.
Question 55 of 60 · Minimal spanning trees: Kruskal's algorithm · Hard
Using 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?
Not quite. Try another option.
Answer: , dominated by edge sorting.
Sorting costs , while all disjoint-set operations together cost . Sorting therefore determines the usual bound.
Question 56 of 60 · Minimal spanning trees: Kruskal's algorithm · Hard
A 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?
Not quite. Try another option.
Answer: , obtained by an exchange involving or .
The MST weighs . Adding replaces the maximum path edge , and adding replaces ; both exchanges produce weight .
Question 57 of 60 · Single-source shortest paths · Hard
A directed graph has edges , , , , , , and . What settled-vertex order and final distances does Dijkstra's algorithm produce?
Not quite. Try another option.
Answer: Order ; distances for .
After settling , the distance to becomes . Settling gives , and settling improves to .
Question 58 of 60 · Single-source shortest paths · Hard
Consider edges , , and . Why can standard Dijkstra's algorithm, which never revisits settled vertices, fail?
Not quite. Try another option.
Answer: It settles at before discovering the true distance through .
A negative edge can later improve an already settled vertex. This violates the greedy invariant that a minimum tentative distance is final.
Question 59 of 60 · Single-source shortest paths · Hard
Which edge-weight condition is sufficient for the standard correctness proof of Dijkstra's single-source shortest-path algorithm?
Not quite. Try another option.
Answer: Every edge weight is nonnegative, including the possibility of zero.
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.
Question 60 of 60 · Single-source shortest paths · Hard
For a dense graph with and nonnegative edge weights, which implementation gives the better asymptotic bound for Dijkstra's algorithm?
Not quite. Try another option.
Answer: An adjacency matrix with linear minimum selection, taking .
For dense graphs, scanning all vertices for each minimum costs , improving on the binary-heap bound .
That's unit 3
Answer a few questions and your score shows up here.
Nearly through. Did unit 3 of ECAP538 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 3 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.