1In a graph, what are the objects connected by edges called?
Introduction to Graphs
Easy
A.Paths
B.Cycles
C.Vertices
D.Weights
Correct Answer: Vertices
Explanation:
A graph consists of vertices, also called nodes, connected by edges.
Incorrect! Try again.
2What distinguishes a directed graph from an undirected graph?
Introduction to Graphs
Easy
A.It contains no cycles
B.It contains one component
C.Its edges have directions
D.Its vertices have weights
Correct Answer: Its edges have directions
Explanation:
In a directed graph, every edge has a specified direction from one vertex to another.
Incorrect! Try again.
3Which data structure is primarily used by Breadth-First Search?
Breadth-First Search (BFS)
Easy
A.Hash table
B.Queue
C.Stack
D.Heap
Correct Answer: Queue
Explanation:
BFS uses a queue to process vertices in the order in which they are discovered.
Incorrect! Try again.
4In an unweighted graph, BFS can be used to find which of the following?
Breadth-First Search (BFS)
Easy
A.A minimum spanning tree by weight
B.A shortest path by edge count
C.A maximum-capacity network flow
D.A topological order with cycles
Correct Answer: A shortest path by edge count
Explanation:
BFS explores vertices level by level, so it finds a path with the fewest edges from the source.
Incorrect! Try again.
5Which data structure is naturally associated with an iterative Depth-First Search?
Depth-First Search (DFS)
Easy
A.Stack
B.Priority queue
C.Circular list
D.Queue
Correct Answer: Stack
Explanation:
Iterative DFS uses a stack, while recursive DFS uses the program's call stack.
Incorrect! Try again.
6How does DFS typically explore a graph?
Depth-First Search (DFS)
Easy
A.It follows one branch deeply
B.It sorts vertices by degree
C.It selects the lightest edge
D.It visits every level first
Correct Answer: It follows one branch deeply
Explanation:
DFS explores as far as possible along one branch before backtracking.
Incorrect! Try again.
7Topological sorting is defined for which type of graph?
Topological Sort
Easy
A.Undirected weighted graph
B.Undirected connected graph
C.Directed acyclic graph
D.Directed cyclic graph
Correct Answer: Directed acyclic graph
Explanation:
A topological ordering exists for a directed acyclic graph, commonly called a DAG.
Incorrect! Try again.
8In a topological ordering, what must be true for every directed edge from to ?
Topological Sort
Easy
A. and share a weight
B. appears next to
C. appears before
D. appears before
Correct Answer: appears before
Explanation:
For every directed edge , vertex must appear before vertex .
Incorrect! Try again.
9What does a greedy algorithm choose at each step?
Introduction to Greedy Approach
Easy
A.Every possible available choice
B.The locally best available choice
C.The globally worst available choice
D.A randomly selected available choice
Correct Answer: The locally best available choice
Explanation:
A greedy algorithm repeatedly makes the choice that appears best at the current step.
Incorrect! Try again.
10Which statement about greedy algorithms is generally true?
Introduction to Greedy Approach
Easy
A.They always require a recursion tree
B.They build solutions through local choices
C.They always examine every possible solution
D.They work only on unweighted graphs
Correct Answer: They build solutions through local choices
Explanation:
Greedy algorithms construct a solution by repeatedly making locally optimal choices.
Incorrect! Try again.
11In the fractional knapsack problem, what is allowed?
Knapsack Problem
Easy
A.Taking each item twice
B.Changing an item's weight
C.Taking part of an item
D.Ignoring the capacity limit
Correct Answer: Taking part of an item
Explanation:
The fractional knapsack problem permits taking a fraction of an item.
Incorrect! Try again.
12Which value is commonly used to select items greedily in the fractional knapsack problem?
Knapsack Problem
Easy
A.Weight-to-capacity ratio
B.Capacity-to-value ratio
C.Item count ratio
D.Value-to-weight ratio
Correct Answer: Value-to-weight ratio
Explanation:
Items are selected in decreasing order of their value-to-weight ratio.
Incorrect! Try again.
13How many edges does a spanning tree of a connected graph with vertices contain?
Minimum Spanning Trees
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Every tree with vertices has exactly edges.
Incorrect! Try again.
14What is minimized by a minimum spanning tree?
Minimum Spanning Trees
Easy
A.The maximum degree of each vertex
B.The total weight of its edges
C.The number of connected components
D.The total number of its vertices
Correct Answer: The total weight of its edges
Explanation:
A minimum spanning tree connects all vertices while minimizing the sum of selected edge weights.
Incorrect! Try again.
15How does Prim's algorithm build a minimum spanning tree?
Prim's Algorithm
Easy
A.It removes every edge from the graph
B.It sorts all vertices by their labels
C.It grows one tree from a start vertex
D.It finds paths from every source vertex
Correct Answer: It grows one tree from a start vertex
Explanation:
Prim's algorithm begins at a vertex and repeatedly adds a minimum-weight edge connecting the tree to a new vertex.
Incorrect! Try again.
16In what order does Kruskal's algorithm consider the edges?
Kruskal's Algorithm
Easy
A.Decreasing order of weight
B.Increasing order of degree
C.Increasing order of weight
D.Decreasing order of degree
Correct Answer: Increasing order of weight
Explanation:
Kruskal's algorithm considers edges from smallest to largest weight and skips edges that create a cycle.
Incorrect! Try again.
17What does a single-source shortest-path algorithm compute?
Single-Source Shortest Paths
Easy
A.A valid topological ordering
B.A minimum-weight spanning tree
C.Shortest paths from one source
D.Shortest paths between every pair
Correct Answer: Shortest paths from one source
Explanation:
The goal is to find shortest-path distances from one selected source to the other reachable vertices.
Incorrect! Try again.
18Dijkstra's algorithm is normally applied when edge weights are which of the following?
Single-Source Shortest Paths
Easy
A.Only fractional
B.All identical
C.All negative
D.Non-negative
Correct Answer: Non-negative
Explanation:
Dijkstra's algorithm correctly computes shortest paths when all edge weights are non-negative.
Incorrect! Try again.
19What is the output of an all-pairs shortest-path algorithm?
All-Pairs Shortest Paths
Easy
A.Distances from one chosen vertex
B.Edges of one spanning tree
C.Vertices in one traversal order
D.Distances between every vertex pair
Correct Answer: Distances between every vertex pair
Explanation:
An all-pairs algorithm computes shortest-path distances for every possible source and destination pair.
Incorrect! Try again.
20Which algorithm is commonly used for the all-pairs shortest-path problem?
All-Pairs Shortest Paths
Easy
A.Breadth-First Search
B.Floyd-Warshall algorithm
C.Prim's algorithm
D.Kruskal's algorithm
Correct Answer: Floyd-Warshall algorithm
Explanation:
The Floyd-Warshall algorithm uses dynamic programming to compute shortest paths between all pairs of vertices.
Incorrect! Try again.
21A connected undirected graph has 8 vertices and 7 edges. Which statement must be true?
Introduction to Graphs
Medium
A.The graph is bipartite
B.The graph is a tree
C.The graph has one cycle
D.The graph is complete
Correct Answer: The graph is a tree
Explanation:
A connected undirected graph with edges is a tree. Here, .
Incorrect! Try again.
22A sparse graph has vertices and edges, where is much smaller than . Which representation is generally most space-efficient?
Introduction to Graphs
Medium
A.An adjacency list using space
B.An incidence matrix using space
C.A distance matrix using space
D.An adjacency matrix using space
Correct Answer: An adjacency list using space
Explanation:
An adjacency list stores only existing edges, making its space usage suitable for sparse graphs.
Incorrect! Try again.
23An undirected graph has edges , , , , , , and . Starting BFS at and visiting adjacent vertices alphabetically, what is the traversal order?
Breadth-First Search (BFS)
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
BFS visits vertices level by level. From , it first visits , then , and finally .
Incorrect! Try again.
24An unweighted undirected graph has edges , , , , , , and . What shortest-path distance does BFS compute from to ?
Breadth-First Search (BFS)
Medium
A.5 edges
B.2 edges
C.4 edges
D.3 edges
Correct Answer: 3 edges
Explanation:
A shortest path is or , each containing 3 edges.
Incorrect! Try again.
25An undirected graph has edges , , , , , , and . Starting recursive DFS at and choosing adjacent vertices alphabetically, what is the traversal order?
Depth-First Search (DFS)
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
DFS follows one branch as deeply as possible: to to to to to .
Incorrect! Try again.
26During DFS of a directed graph, an edge from the current vertex reaches a gray vertex . What does this indicate?
Depth-First Search (DFS)
Medium
A.A forward edge and a shortest path
B.A tree edge and a new component
C.A back edge and a directed cycle
D.A cross edge and an acyclic graph
Correct Answer: A back edge and a directed cycle
Explanation:
A gray vertex is still on the recursion stack. An edge to it is a back edge, which identifies a directed cycle.
Incorrect! Try again.
27A directed acyclic graph has edges , , , , and . Which sequence is a valid topological ordering?
Topological Sort
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Every source appears before its destination: and precede , precedes , and both precede .
Incorrect! Try again.
28A DAG contains edges , , , and . Which added edge would make topological sorting impossible?
Topological Sort
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Adding creates a cycle such as . A graph with a directed cycle has no topological ordering.
Incorrect! Try again.
29For activity selection, the intervals are , , , , , and . Using the earliest-finish-time greedy rule, which set is selected?
Introduction to Greedy Approach
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The algorithm repeatedly selects the compatible activity with the earliest finishing time, producing three non-overlapping activities.
Incorrect! Try again.
30A greedy coin-change algorithm always chooses the largest usable coin. For denominations and amount , what happens?
Introduction to Greedy Approach
Medium
A.It uses 2 coins, which is optimal
B.It uses 4 coins, although 3 are sufficient
C.It uses 3 coins, although 2 are sufficient
D.It cannot represent the amount exactly
Correct Answer: It uses 3 coins, although 2 are sufficient
Explanation:
Greedy chooses , using 3 coins, while the optimal solution is , using 2 coins.
Incorrect! Try again.
31In a fractional knapsack of capacity 50, the items have pairs , , and . What maximum value can be obtained?
Knapsack Problem
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Take the first two items completely and of the third: .
Incorrect! Try again.
32For the 0/1 knapsack with capacity 50 and items , , and , what is the optimal total value?
Knapsack Problem
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Selecting the items of weights 20 and 30 fills the knapsack exactly and gives value .
Incorrect! Try again.
33For the cut and , the crossing edges are of weight 4, of weight 6, of weight 2, and of weight 5. Which edge is safe to add to an MST?
Minimum Spanning Trees
Medium
A. of weight 4
B. of weight 2
C. of weight 6
D. of weight 5
Correct Answer: of weight 2
Explanation:
By the cut property, a minimum-weight edge crossing a cut is safe for an MST. Here that edge is .
Incorrect! Try again.
34A connected undirected graph has distinct weights on all its edges. What can be concluded about its minimum spanning tree?
Minimum Spanning Trees
Medium
A.It is unique
B.It is a shortest-path tree
C.It contains every light edge
D.It has minimum degree 2
Correct Answer: It is unique
Explanation:
Distinct edge weights guarantee that each relevant cut has a unique lightest edge, resulting in a unique MST.
Incorrect! Try again.
35Consider edges , , , , , , and . Starting Prim's algorithm at , which edge sequence is selected?
Prim's Algorithm
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Prim selects the lightest edge connecting the current tree to a new vertex: weights , giving total weight 9.
Incorrect! Try again.
36Prim's algorithm is implemented with adjacency lists and a binary min-heap. What is its standard time complexity?
Prim's Algorithm
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Heap-based priority updates and extractions take logarithmic time, giving a total complexity of .
Incorrect! Try again.
37Using edges , , , , , , and , which edges does Kruskal's algorithm select, in order?
Kruskal's Algorithm
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Edges are considered by increasing weight. is skipped because it forms a cycle, and then connects the two components.
Incorrect! Try again.
38A directed graph has edges , , , , , , and . What 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 cost .
Incorrect! Try again.
39After relaxation passes in Bellman-Ford, an additional pass still decreases the distance of a vertex reachable from the source. What does this show?
Single-Source Shortest Paths
Medium
A.The graph must be disconnected
B.A zero-weight edge remains unprocessed
C.A reachable negative-weight cycle exists
D.The shortest-path tree is unique
Correct Answer: A reachable negative-weight cycle exists
Explanation:
If a reachable distance can still decrease after passes, some reachable negative-weight cycle permits unlimited improvement.
Incorrect! Try again.
40During Floyd-Warshall, suppose the current values are , , and . What is the updated value of when is allowed as an intermediate vertex?
All-Pairs Shortest Paths
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Floyd-Warshall applies , so the update is .
Incorrect! Try again.
41A simple undirected graph on vertices has edges . If is its adjacency matrix, what are the number of distinct triangles and the value of , respectively?
Introduction to Graphs
Hard
A. triangles and
B. triangles and
C. triangles and
D. triangles and
Correct Answer: triangles and
Explanation:
The triangles are and . In a simple undirected graph, each triangle contributes six length- closed walks, so .
Incorrect! Try again.
42The condensation graph of a directed graph has more than one vertex, with exactly three source strongly connected components and two sink strongly connected components. If arbitrary directed edges may be added, what is the minimum number required to make the original graph strongly connected?
Introduction to Graphs
Hard
A. edges
B. edges
C. edges
D. edges
Correct Answer: edges
Explanation:
For a condensation DAG with more than one vertex, the minimum is , where and are the numbers of source and sink components. Thus .
Incorrect! Try again.
43BFS is run from source in a directed, unweighted graph. For an edge where is reachable from , which relationship between the BFS distances is always guaranteed?
Breadth-First Search (BFS)
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
A shortest path to followed by gives a path to of length . Directed edges may point back many levels, so no symmetric bound is guaranteed.
Incorrect! Try again.
44A directed unweighted graph has edges , , , , , , and , . How many distinct shortest paths exist from to ?
Breadth-First Search (BFS)
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
There are three shortest paths to each of and , hence six to each of and . The final edges to give shortest paths of length four.
Incorrect! Try again.
45In a DFS of a directed graph, the timestamp intervals are and . If edge exists, how can that edge be classified using only these timestamps?
Depth-First Search (DFS)
Hard
A.It must be a tree edge
B.It may be tree or forward
C.It may be back or cross
D.It must be a forward edge
Correct Answer: It may be tree or forward
Explanation:
The nested intervals show that is a descendant of . An edge from an ancestor to a descendant is a tree edge if it discovered the descendant and otherwise a forward edge.
Incorrect! Try again.
46Which statement is always true about a DFS forest of an undirected graph?
Depth-First Search (DFS)
Hard
A.Every non-tree edge joins two different DFS trees
B.Every non-tree edge joins vertices whose depths differ by one
C.Every non-tree edge joins an ancestor and a descendant
D.Every non-tree edge joins vertices at the same depth
Correct Answer: Every non-tree edge joins an ancestor and a descendant
Explanation:
Undirected DFS has only tree and back edges. A non-tree edge therefore connects a vertex to one of its ancestors; cross edges between unrelated subtrees cannot occur.
Incorrect! Try again.
47For a DAG, which condition is necessary and sufficient for its topological ordering to be unique?
Topological Sort
Hard
A.Every pair of vertices has a common descendant
B.An edge exists for every
C.The DAG has exactly one source and one sink
D.Every vertex except has positive out-degree
Correct Answer: An edge exists for every
Explanation:
If consecutive vertices lack an edge, they can be exchanged to obtain another topological order. Edges between every consecutive pair force the displayed ordering.
Incorrect! Try again.
48A DAG on contains exactly the edges , , , , , , and . How many topological orderings does it have?
Topological Sort
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
and must occupy the first two positions in either order, while and occupy the next two in either order. Then and are forced, giving .
Incorrect! Try again.
49A family of feasible subsets is hereditary and satisfies the exchange property: whenever feasible sets and satisfy , some makes feasible. What does this imply about repeatedly selecting the highest-weight feasible element for arbitrary nonnegative weights?
Introduction to Greedy Approach
Hard
A.It is optimal only when every maximal feasible set is unique
B.It is optimal because the feasible family forms a matroid
C.It gives a factor- approximation for every weight assignment
D.It is optimal only when all element weights are distinct
Correct Answer: It is optimal because the feasible family forms a matroid
Explanation:
Hereditary closure and the exchange property define a matroid. The weighted matroid greedy theorem guarantees a maximum-weight independent set for arbitrary nonnegative weights.
Incorrect! Try again.
50Weighted activities are , , , and , where each tuple is . What values are obtained by earliest-finish-time greedy selection and by an optimal weighted selection, respectively?
Introduction to Greedy Approach
Hard
A. and
B. and
C. and
D. and
Correct Answer: and
Explanation:
Earliest-finish greedy selects for value . The weighted optimum selects for value , showing that the unweighted greedy rule does not solve the weighted variant.
Incorrect! Try again.
51A knapsack has capacity . Items have pairs , , , and . What are the optimal values for the fractional and variants, respectively?
Knapsack Problem
Hard
A. and
B. and
C. and
D. and
Correct Answer: and
Explanation:
Density order gives the first two items and half of the fourth, worth . For knapsack, the first and third items exactly fill capacity and yield .
Incorrect! Try again.
52Let be a subset of edges contained in some MST. A cut respects , and edge is a minimum-weight edge crossing that cut, with ties allowed. Which conclusion is guaranteed?
Minimum Spanning Trees
Hard
A.Every MST contains
B.Some MST contains
C.Edge is the unique light edge
D.No MST excluding exists
Correct Answer: Some MST contains
Explanation:
By the cut property, a light edge crossing a cut that respects is safe. Ties mean it need not occur in every MST, but at least one MST contains .
Incorrect! Try again.
53A spanning tree has edges of weight , of weight , and of weight . The remaining graph edges are of weight , of weight , and of weight . Which statement is correct?
Minimum Spanning Trees
Hard
A. is an MST and is unique
B. is an MST but is not unique
C. is not minimum because is lighter than its cycle
D. is not minimum because can replace
Correct Answer: is an MST but is not unique
Explanation:
Each non-tree edge is at least as heavy as the maximum-weight edge on its path in , so is minimum. Since , replacing by gives another MST.
Incorrect! Try again.
54Prim's algorithm starts at on a graph with weighted edges , , , , , , and . What is the order of selected edges?
Prim's Algorithm
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Prim first chooses , then . The cheapest edge leaving is , after which adds the final vertex.
Incorrect! Try again.
55Prim's algorithm is implemented with an adjacency matrix and run on a disconnected graph without restarting after the initial source component is exhausted. Which result and running time are expected?
Prim's Algorithm
Hard
A.A minimum spanning forest in time
B.A minimum spanning forest in time
C.One component's MST in time
D.One component's MST in time
Correct Answer: One component's MST in time
Explanation:
A single run reaches only the source's connected component. Matrix-based selection scans vertices repeatedly, giving time; restarting is required to obtain a full minimum spanning forest.
Incorrect! Try again.
56Kruskal's algorithm is run on vertices with edges , , , , , , , and . Equal-weight edges are processed lexicographically. Which sequence of edges is accepted?
Kruskal's Algorithm
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
and are accepted first, followed by . Edges and then create cycles, while connects the remaining vertex .
Incorrect! Try again.
57A directed graph has edges , , , , and . A standard label-setting Dijkstra implementation never revisits finalized vertices. What distance to does it return, and what is the true shortest distance?
Single-Source Shortest Paths
Hard
A.It returns ; the true distance is
B.It returns ; the true distance is
C.It returns ; the true distance is
D.It returns ; the true distance is
Correct Answer: It returns ; the true distance is
Explanation:
Dijkstra finalizes at distance and then at before processing . The true shortest path is , with length .
Incorrect! Try again.
58Bellman-Ford performs full relaxation passes from source , followed by one additional pass. Which event proves that a negative-weight cycle reachable from exists?
Correct Answer: Any reachable edge can still be relaxed
Explanation:
Without a reachable negative cycle, every shortest simple path uses at most edges. A further successful relaxation therefore implies an indefinitely improvable reachable cycle of negative total weight.
Incorrect! Try again.
59A directed graph has edges , , , , and . After Floyd-Warshall completes, what are the distances and ?
All-Pairs Shortest Paths
Hard
A. and
B. and
C. and
D. and
Correct Answer: and
Explanation:
The path has cost . The path has cost ; the cycle has positive cost .
Incorrect! Try again.
60In Johnson's algorithm, Bellman-Ford produces potentials , and each edge is reweighted as . If Dijkstra computes using , how is the original shortest-path distance recovered?
All-Pairs Shortest Paths
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Reweighting makes every path from to differ by the constant . Hence , giving the stated recovery formula.
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 →