4Which data structure is typically used by Breadth-First Search (BFS)?
Breadth-first search
Easy
A.Stack
B.Queue
C.Hash table
D.Heap
Correct Answer: Queue
Explanation:
BFS uses a queue so vertices are explored in the order they are discovered.
Incorrect! Try again.
5In an unweighted graph, BFS visits vertices primarily according to their:
Breadth-first search
Easy
A.Distance from the source
B.Alphabetical vertex labels
C.Number of outgoing edges
D.Order in the input file
Correct Answer: Distance from the source
Explanation:
BFS explores all vertices at one distance from the source before moving to the next distance.
Incorrect! Try again.
6What does BFS find efficiently in an unweighted graph?
Breadth-first search
Easy
A.Shortest paths by edge count
B.All negative-weight edges
C.Largest edge weights
D.Minimum spanning cycles
Correct Answer: Shortest paths by edge count
Explanation:
BFS finds shortest paths in an unweighted graph when distance is measured by the number of edges.
Incorrect! Try again.
7Which data structure is commonly used by Depth-First Search (DFS)?
Depth-first search
Easy
A.Stack
B.Priority queue
C.Queue
D.Circular buffer
Correct Answer: Stack
Explanation:
DFS uses a stack, either explicitly or through the program's recursion stack.
Incorrect! Try again.
8How does DFS generally explore a graph?
Depth-first search
Easy
A.It visits all neighbors at once
B.It examines vertices in sorted order
C.It always selects the heaviest edge
D.It follows one path before backtracking
Correct Answer: It follows one path before backtracking
Explanation:
DFS continues along a path as far as possible and backtracks when no unvisited neighbor remains.
Incorrect! Try again.
9Which task can DFS help perform in a directed graph?
Depth-first search
Easy
A.Removing isolated vertices
B.Detecting cycles
C.Adding weights to edges
D.Making every edge undirected
Correct Answer: Detecting cycles
Explanation:
DFS can identify cycles by tracking vertices currently in the recursion or active path.
Incorrect! Try again.
10What is the shortest path between two vertices?
Shortest path algorithms
Easy
A.A path with minimum total cost
B.A path containing every vertex
C.A path containing the most edges
D.A path with maximum total cost
Correct Answer: A path with minimum total cost
Explanation:
A shortest path has the smallest sum of edge weights, or the fewest edges when the graph is unweighted.
Incorrect! Try again.
11What does the distance value for a source vertex usually start as?
Shortest path algorithms
Easy
A.One
B.Zero
C.The number of vertices
D.Infinity
Correct Answer: Zero
Explanation:
The distance from a source vertex to itself is .
Incorrect! Try again.
12What value is commonly assigned initially to vertices that are unreachable from the source?
Shortest path algorithms
Easy
A.Zero
B.Negative one
C.Infinity
D.The edge count
Correct Answer: Infinity
Explanation:
An initial distance of infinity represents that no path from the source is known.
Incorrect! Try again.
13Dijkstra's algorithm is designed to find shortest paths from:
Dijkstra's algorithm
Easy
A.Every edge independently
B.One destination only
C.One source vertex
D.A set of disconnected edges
Correct Answer: One source vertex
Explanation:
Dijkstra's algorithm solves the single-source shortest-path problem.
Incorrect! Try again.
14What restriction applies to edge weights in Dijkstra's algorithm?
Dijkstra's algorithm
Easy
A.They must all equal zero
B.They must all be negative
C.They must be identical
D.They must be nonnegative
Correct Answer: They must be nonnegative
Explanation:
Dijkstra's algorithm requires edge weights that are zero or positive.
Incorrect! Try again.
15Which vertex does Dijkstra's algorithm typically select next?
Dijkstra's algorithm
Easy
A.The vertex with the most neighbors
B.The unvisited vertex with largest weight
C.The unvisited vertex with smallest distance
D.The visited vertex with largest degree
Correct Answer: The unvisited vertex with smallest distance
Explanation:
At each step, Dijkstra's algorithm selects the unvisited vertex with the smallest tentative distance.
Incorrect! Try again.
16Which type of edge weight can Bellman-Ford handle that Dijkstra's algorithm cannot generally handle?
Bellman-Ford algorithm
Easy
A.Positive edge weight
B.Equal edge weight
C.Zero edge weight
D.Negative edge weight
Correct Answer: Negative edge weight
Explanation:
Bellman-Ford can process graphs containing negative edge weights.
Incorrect! Try again.
17What important problem can Bellman-Ford detect?
Bellman-Ford algorithm
Easy
A.Negative-weight cycles
B.Duplicate vertex names
C.Disconnected input files
D.Unsorted adjacency lists
Correct Answer: Negative-weight cycles
Explanation:
Bellman-Ford can detect a reachable cycle whose total weight is negative.
Incorrect! Try again.
18How many times does Bellman-Ford normally relax all edges in a graph with vertices?
Bellman-Ford algorithm
Easy
A. times
B. times
C. times
D. times
Correct Answer: times
Explanation:
In the standard algorithm, all edges are relaxed times because a simple shortest path has at most edges.
Incorrect! Try again.
19What type of shortest-path problem does Floyd-Warshall solve?
Floyd-Warshall algorithm
Easy
A.Maximum spanning paths
B.All-pairs shortest paths
C.Single-edge shortest paths
D.Single-source paths only
Correct Answer: All-pairs shortest paths
Explanation:
Floyd-Warshall computes shortest distances between every pair of vertices.
Incorrect! Try again.
20Which technique is used by the Floyd-Warshall algorithm?
Floyd-Warshall algorithm
Easy
A.Randomized sampling
B.Dynamic programming
C.Binary searching
D.Hashing
Correct Answer: Dynamic programming
Explanation:
Floyd-Warshall uses dynamic programming to improve paths by considering intermediate vertices.
Incorrect! Try again.
21A graph with vertices and edges is represented using adjacency lists. What is the worst-case time complexity of traversing the entire graph using either BFS or DFS?
Graph traversal
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Each vertex is visited once, and every edge is examined a constant number of times, giving time.
Incorrect! Try again.
22A graph is disconnected, and a traversal starts from only one vertex. What modification is required to guarantee that every vertex is visited?
Graph traversal
Medium
A.Repeat the traversal from every edge
B.Start a traversal from each unvisited vertex
C.Sort all vertices by their degrees
D.Convert the graph into a complete graph
Correct Answer: Start a traversal from each unvisited vertex
Explanation:
A traversal from one source reaches only its connected component. Restarting from each unvisited vertex covers all components.
Incorrect! Try again.
23Consider an undirected graph with adjacency lists , , and . BFS starts at , and neighbors are processed in the listed order. What is the queue immediately after has been processed?
Breadth-first search
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
After processing , the queue is . Processing removes it and adds unvisited vertices and , producing .
Incorrect! Try again.
24In an unweighted graph, BFS begins at vertex . Vertex is first discovered while processing a vertex whose BFS distance is . What distance is assigned to ?
Breadth-first search
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
A newly discovered neighbor is one edge farther from the source, so its distance is .
Incorrect! Try again.
25While using BFS to test whether an undirected graph is bipartite, an edge is found between two vertices assigned the same color. What does this imply?
Breadth-first search
Medium
A.The graph must be disconnected
B.The graph contains an even-length cycle
C.The graph must be acyclic
D.The graph contains an odd-length cycle
Correct Answer: The graph contains an odd-length cycle
Explanation:
An edge joining vertices of the same BFS color violates bipartite coloring and implies the presence of an odd-length cycle.
Incorrect! Try again.
26A recursive DFS starts at in a directed graph with adjacency lists , , , , , and . Neighbors are processed in the listed order. What is the discovery order?
Depth-first search
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
DFS follows , then backtracks to visit .
Incorrect! Try again.
27During DFS of a directed graph, an edge from the current vertex leads to a vertex that is discovered but not yet finished. How is this edge interpreted?
Depth-first search
Medium
A.It is a forward edge proving acyclicity
B.It is a back edge indicating a cycle
C.It is a cross edge proving connectivity
D.It is a tree edge indicating a leaf
Correct Answer: It is a back edge indicating a cycle
Explanation:
A discovered but unfinished vertex is on the active recursion stack. An edge to it is a back edge and identifies a directed cycle.
Incorrect! Try again.
28How can DFS finishing times be used to obtain a topological ordering of a directed acyclic graph?
Depth-first search
Medium
A.List vertices by increasing finishing time
B.List vertices by increasing discovery time
C.List vertices by decreasing discovery time
D.List vertices by decreasing finishing time
Correct Answer: List vertices by decreasing finishing time
Explanation:
In a DAG, placing vertices in reverse order of their DFS finishing times gives a valid topological ordering.
Incorrect! Try again.
29Which algorithm is most appropriate for finding shortest paths from one source in an unweighted graph?
Shortest path algorithms
Medium
A.Bellman-Ford algorithm
B.Floyd-Warshall algorithm
C.Depth-first search
D.Breadth-first search
Correct Answer: Breadth-first search
Explanation:
BFS explores vertices by increasing number of edges from the source, so it finds shortest paths in an unweighted graph.
Incorrect! Try again.
30A weighted directed graph is a DAG and may contain negative edge weights. Which approach finds single-source shortest paths in time?
Shortest path algorithms
Medium
A.Relax edges in topological order
B.Run Floyd-Warshall once
C.Run BFS from the source
D.Apply Dijkstra without a heap
Correct Answer: Relax edges in topological order
Explanation:
Topological ordering ensures that all incoming paths to a vertex are considered before its outgoing edges, even when edge weights are negative.
Incorrect! Try again.
31Consider directed edges with weight , with weight , with weight , with weight , with weight , and with weight . What is the order in which vertices are settled by Dijkstra's algorithm from ?
Dijkstra's algorithm
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The final distances are for , respectively, so vertices are settled in that order.
Incorrect! Try again.
32A directed graph has edges , , , , , and . What shortest distance does Dijkstra's algorithm compute from to ?
Dijkstra's algorithm
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The shortest route is , with total weight .
Incorrect! Try again.
33A graph contains edges with weight , with weight , and with weight . What is the true shortest distance from to , and why can Dijkstra's algorithm fail?
Dijkstra's algorithm
Medium
A., because direct edges are always shortest
B., because only the final edge matters
C., because a later negative edge improves
D., because is reached before
Correct Answer: , because a later negative edge improves
Explanation:
The path has weight . Dijkstra may settle at distance before discovering this improvement.
Incorrect! Try again.
34For edges , , , , and , what distances does Bellman-Ford compute from ?
Bellman-Ford algorithm
Medium
A., ,
B., ,
C., ,
D., ,
Correct Answer: , ,
Explanation:
The edge improves to , and then improves to .
Incorrect! Try again.
35After full relaxation passes, an edge whose source has a finite distance can still be relaxed. What does Bellman-Ford conclude?
Bellman-Ford algorithm
Medium
A.A reachable positive-weight cycle exists
B.All shortest paths are finalized
C.The source vertex is disconnected
D.A reachable negative-weight cycle exists
Correct Answer: A reachable negative-weight cycle exists
Explanation:
Without a reachable negative cycle, every shortest simple path uses at most edges. A further improvement therefore signals a reachable negative cycle.
Incorrect! Try again.
36During Bellman-Ford, a complete pass over all edges causes no distance update. What is the correct action?
Bellman-Ford algorithm
Medium
A.Stop because distances are final
B.Switch immediately to DFS
C.Perform exactly more passes
D.Restart with a different source
Correct Answer: Stop because distances are final
Explanation:
If no edge can be relaxed during a full pass, subsequent passes cannot improve any distance, so the algorithm may terminate early.
Incorrect! Try again.
37Which recurrence correctly describes the Floyd-Warshall update when vertex is allowed as an intermediate vertex?
Floyd-Warshall algorithm
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The shortest path either avoids or passes through , so the algorithm takes the minimum of those two possibilities.
Incorrect! Try again.
38Before considering vertex as an intermediate vertex, the current distances are , , and . What is the updated value of ?
Floyd-Warshall algorithm
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The route through vertex has length , which improves the previous distance of .
Incorrect! Try again.
39After Floyd-Warshall finishes, which matrix condition indicates that the graph contains a negative-weight cycle?
Floyd-Warshall algorithm
Medium
A.Some off-diagonal entry equals
B.Some diagonal entry satisfies
C.Some diagonal entry satisfies
D.Some off-diagonal entry equals
Correct Answer: Some diagonal entry satisfies
Explanation:
A negative diagonal value means a vertex can return to itself with negative total cost, which is possible only through a negative-weight cycle.
Incorrect! Try again.
40A directed graph has edges , , , and . What shortest distance from to will Floyd-Warshall compute?
Floyd-Warshall algorithm
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The shortest route is , whose total weight is .
Incorrect! Try again.
41A graph has vertices and edges and may be disconnected. A complete traversal runs BFS from every still-unvisited vertex. What are the tight worst-case running times when the graph is represented by an adjacency list and by an adjacency matrix, respectively?
Graph traversal
Hard
A. and
B. and
C. and
D. and
Correct Answer: and
Explanation:
Across all components, an adjacency-list traversal examines every vertex and edge once. An adjacency matrix requires scanning a row of entries for each vertex.
Incorrect! Try again.
42An undirected, unweighted graph has edges --, --, --, --, --, --, --, --, --, and --. How many distinct shortest paths exist from to ?
Breadth-first search
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
All shortest paths have length . There are two through and three through , giving .
Incorrect! Try again.
43BFS starts at in the directed graph with ordered adjacency lists: , , , , , , , , , and all other lists empty. Vertices are marked when enqueued. What is the maximum number of vertices simultaneously in the queue?
Breadth-first search
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The queue first reaches size after processing : . Later processing maintains or reduces this size.
Incorrect! Try again.
44BFS is run from source in a directed, unweighted graph. For a directed edge where both endpoints are reachable from , which relation is always guaranteed?
Breadth-first search
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
A shortest path to followed by is a path to of length . Directed edges can point back many BFS levels, so the reverse bound need not hold.
Incorrect! Try again.
45Recursive DFS begins at using adjacency lists , , , and . Neighbors are processed in listed order. How are edges and classified?
Depth-first search
Hard
A. is cross; is back
B. is back; is cross
C. is forward; is cross
D. is back; is forward
Correct Answer: is back; is cross
Explanation:
While exploring , vertex is a gray ancestor, so is back. By the time examines , is finished in another completed branch, making cross.
Incorrect! Try again.
46An iterative DFS uses a stack, marks a vertex when it is popped, and pushes all of its currently unvisited neighbors. To reproduce the discovery order of recursive DFS that scans each adjacency list from first to last, in what order should the iterative algorithm push the neighbors?
Depth-first search
Hard
A.By decreasing vertex degree
B.From first to last
C.From last to first
D.By increasing DFS finish time
Correct Answer: From last to first
Explanation:
Because a stack is LIFO, pushing neighbors in reverse adjacency order places the first-listed neighbor on top. Marking on pop may also require suppressing duplicate processing.
Incorrect! Try again.
47Which DFS condition is both necessary and sufficient for a directed graph to be acyclic?
Depth-first search
Hard
A.No DFS forest contains a cross edge
B.Every vertex has a distinct finish time
C.No DFS forest contains a back edge
D.Every DFS tree contains a forward edge
Correct Answer: No DFS forest contains a back edge
Explanation:
A directed cycle produces an edge to a gray ancestor during DFS, which is a back edge. Conversely, every back edge closes a directed cycle.
Incorrect! Try again.
48In the standard DFS low-link algorithm for articulation points in an undirected graph, which criterion is correct?
Depth-first search
Hard
A.A root needs two DFS children; a non-root needs a child with
B.A root needs no back edge; a non-root needs a child with
C.A root needs two graph neighbors; a non-root needs
D.A root needs one DFS child; a non-root needs a child with
Correct Answer: A root needs two DFS children; a non-root needs a child with
Explanation:
A DFS root is an articulation point exactly when it has multiple DFS-tree children. A non-root qualifies when some child's subtree cannot reach a strict ancestor of .
Incorrect! Try again.
49Johnson's algorithm computes potentials using Bellman-Ford. Which reweighting both preserves shortest-path ordering and makes every edge nonnegative when no negative cycle exists?
Shortest path algorithms
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Bellman-Ford potentials satisfy , so . Potential terms telescope along a path, preserving path comparisons between fixed endpoints.
Incorrect! Try again.
50A weighted directed graph is a DAG but may contain negative edge weights. Which method computes single-source shortest paths in tight time ?
Shortest path algorithms
Hard
A.Run Dijkstra with a binary heap
B.Run Bellman-Ford for passes
C.Run Floyd-Warshall from the source
D.Relax edges in topological order
Correct Answer: Relax edges in topological order
Explanation:
Topological order ensures all possible predecessors of a vertex are processed before it. Negative weights are safe because a DAG has no cycles.
Incorrect! Try again.
51Dijkstra's algorithm runs from on directed edges , , , , , , , and . What is the order in which vertices are permanently settled?
Dijkstra's algorithm
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The final distances are for , respectively. Their strictly increasing values determine the settlement order.
Incorrect! Try again.
52Consider directed edges , , and . Standard Dijkstra finalizes a vertex when extracted and never changes a finalized distance. What distance does it report for , and what is the true shortest distance?
Dijkstra's algorithm
Hard
A.Reported ; true
B.Reported ; true
C.Reported ; true
D.Reported ; true
Correct Answer: Reported ; true
Explanation:
Dijkstra finalizes at distance before extracting . The path has weight , demonstrating why negative edges invalidate the algorithm.
Incorrect! Try again.
53Dijkstra's algorithm uses a binary heap without decrease-key: every strict distance improvement inserts a new pair, and stale pairs are ignored when extracted. For edges , , , , , , , and , how many stale pairs are eventually extracted?
Dijkstra's algorithm
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The obsolete entries are for at , at , and at and . The improved entries settle those vertices at , , and .
Incorrect! Try again.
54When all edge weights are nonnegative, at which event may Dijkstra's algorithm safely terminate if only the distance from to target is required?
Dijkstra's algorithm
Hard
A.When is first inserted into the queue
B.When an edge entering is first scanned
C.When every neighbor of is discovered
D.When is extracted with minimum key
Correct Answer: When is extracted with minimum key
Explanation:
Extraction of the current minimum finalizes 's distance. Discovery or insertion is insufficient because a later relaxation may produce a shorter route.
Incorrect! Try again.
55Suppose Bellman-Ford performs synchronous passes, so every relaxation in pass reads distances produced only by pass . After pass , what does represent?
Bellman-Ford algorithm
Hard
A.The minimum weight of an - walk using at most edges
B.The minimum weight of an - walk using exactly edges
C.The minimum weight of an - path visiting at most vertices
D.The minimum weight of an - path containing at most negative edges
Correct Answer: The minimum weight of an - walk using at most edges
Explanation:
Each synchronous pass permits one additional edge beyond the previous pass. This invariant explains why passes suffice when no reachable negative cycle exists.
Incorrect! Try again.
56A graph contains a negative-weight cycle in a component unreachable from source . What does standard single-source Bellman-Ford initialized with and all other distances infinite do?
Bellman-Ford algorithm
Hard
A.It assigns negative infinity to that component
B.It does not report that unreachable cycle
C.It fails during the first relaxation pass
D.It reports every negative cycle in the graph
Correct Answer: It does not report that unreachable cycle
Explanation:
Edges in the unreachable component never receive finite distances, so they cannot relax. A zero-weight super-source connected to every vertex is needed to detect a negative cycle anywhere.
Incorrect! Try again.
57Bellman-Ford runs from on edges , , , , , , , , , and . What is after convergence?
Bellman-Ford algorithm
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
The shortest routes give , , , and . No reachable negative cycle exists.
Incorrect! Try again.
58Immediately before Floyd-Warshall allows vertex as an intermediate, its distance matrix is What is the first row immediately after this phase?
Floyd-Warshall algorithm
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Using vertex , entry becomes . Entry remains .
Incorrect! Try again.
59After Floyd-Warshall finishes, suppose . For which ordered pairs is there no finite shortest-walk value because the negative cycle can be used arbitrarily many times?
Floyd-Warshall algorithm
Hard
A.Pairs satisfying only
B.Pairs satisfying only or
C.Pairs with finite and finite
D.Pairs with finite and finite
Correct Answer: Pairs with finite and finite
Explanation:
Such a walk can travel from to the negative cycle, repeat it arbitrarily often, and then reach . Its weight is therefore unbounded below.
Incorrect! Try again.
60In Floyd-Warshall, after completing the outer-loop iteration for intermediate vertex , what invariant is maintained by ?
Floyd-Warshall algorithm
Hard
A.It is shortest among paths containing at most total edges
B.It is shortest among paths whose endpoints lie in
C.It is shortest among paths containing exactly intermediate vertices
D.It is shortest among paths whose intermediate vertices lie in
Correct Answer: It is shortest among paths whose intermediate vertices lie in
Explanation:
The recurrence compares paths that avoid with paths split at . This invariant is why must be the outermost loop in the standard in-place implementation.
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 →