1In a weighted graph, what does the weight assigned to an edge typically represent?
labelled and weighted graph
Easy
A.The direction of the edge only
B.The color assigned to the edge
C.The number of vertices in the graph
D.A numerical value such as cost, distance, or time
Correct Answer: A numerical value such as cost, distance, or time
Explanation:
In a weighted graph, each edge is assigned a numerical value (weight) that may represent quantities like distance, cost, or time.
Incorrect! Try again.
2A graph in which each vertex or edge is assigned a name or label is called a:
labelled and weighted graph
Easy
A.Complete graph
B.Null graph
C.Regular graph
D.Labelled graph
Correct Answer: Labelled graph
Explanation:
A labelled graph is one where vertices and/or edges are given distinct labels or names to identify them.
Incorrect! Try again.
3The shortest path between two vertices in a weighted graph is the path with the:
shortest path in weighted graphs
Easy
A.Maximum total edge weight
B.Minimum total edge weight
C.Minimum number of vertices
D.Maximum number of edges
Correct Answer: Minimum total edge weight
Explanation:
The shortest path is defined as the path between two vertices for which the sum of the edge weights is minimum.
Incorrect! Try again.
4In an unweighted graph, the shortest path between two vertices is measured by the:
shortest path in weighted graphs
Easy
A.Product of edge weights
B.Sum of vertex labels
C.Number of disconnected components
D.Number of edges in the path
Correct Answer: Number of edges in the path
Explanation:
When a graph has no weights, every edge is treated as weight 1, so the shortest path is simply the one with the fewest edges.
Incorrect! Try again.
5Dijkstra's algorithm is used to find the shortest path from:
Dijkstra's algorithm to find shortest path
Easy
A.The vertex with the highest degree only
B.A single source vertex to all other vertices
C.Every vertex to every other vertex simultaneously in a single pass
D.Only between two adjacent vertices
Correct Answer: A single source vertex to all other vertices
Explanation:
Dijkstra's algorithm computes the shortest paths from one chosen source vertex to all remaining vertices in the graph.
Incorrect! Try again.
6A key limitation of Dijkstra's algorithm is that it does not work correctly with:
Dijkstra's algorithm to find shortest path
Easy
A.Negative edge weights
B.Undirected graphs
C.Weighted graphs
D.Connected graphs
Correct Answer: Negative edge weights
Explanation:
Dijkstra's algorithm assumes all edge weights are non-negative; negative weights can produce incorrect results.
Incorrect! Try again.
7At each step, Dijkstra's algorithm selects the unvisited vertex with the:
Dijkstra's algorithm to find shortest path
Easy
A.Highest vertex label
B.Smallest known distance from the source
C.Most number of neighbors
D.Largest known distance from the source
Correct Answer: Smallest known distance from the source
Explanation:
The algorithm greedily picks the unvisited vertex having the minimum tentative distance and finalizes it.
Incorrect! Try again.
8A tree is best defined as a connected graph that:
introduction to tree
Easy
A.Has multiple disconnected parts
B.Contains exactly one cycle
C.Has no edges
D.Contains no cycles
Correct Answer: Contains no cycles
Explanation:
A tree is a connected, acyclic graph — it has no cycles.
Incorrect! Try again.
9A tree with vertices always has exactly how many edges?
introduction to tree
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Any tree with vertices contains exactly edges.
Incorrect! Try again.
10How many paths exist between any two distinct vertices in a tree?
introduction to tree
Easy
A.At least three
B.Exactly one
C.Exactly two
D.None
Correct Answer: Exactly one
Explanation:
In a tree there is a unique simple path connecting any two vertices, which follows from it being connected and acyclic.
Incorrect! Try again.
11In a rooted tree, the topmost vertex from which the tree originates is called the:
rooted tree
Easy
A.Root
B.Leaf
C.Edge
D.Sibling
Correct Answer: Root
Explanation:
A rooted tree has one specially designated vertex called the root from which all other vertices descend.
Incorrect! Try again.
12In a rooted tree, a vertex that has no children is known as a:
rooted tree
Easy
A.Root node
B.Internal node
C.Leaf node
D.Parent node
Correct Answer: Leaf node
Explanation:
A leaf (or terminal) node is a vertex in a rooted tree that has no children.
Incorrect! Try again.
13A binary tree is a rooted tree in which every node has at most:
binary tree
Easy
A.Three children
B.One child
C.Two children
D.Four children
Correct Answer: Two children
Explanation:
In a binary tree each node can have a maximum of two children, usually called the left and right child.
Incorrect! Try again.
14What is the maximum number of nodes at level of a binary tree, taking the root as level ?
binary tree
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
At level , a binary tree can have at most nodes since the number of nodes doubles at each level.
Incorrect! Try again.
15A spanning tree of a connected graph is a subgraph that:
spanning tree
Easy
A.Includes only some of the vertices of
B.Includes all edges of the original graph
C.Includes all vertices of and is a tree
D.Contains at least one cycle among its vertices
Correct Answer: Includes all vertices of and is a tree
Explanation:
A spanning tree contains every vertex of the original graph while remaining a tree (connected and acyclic).
Incorrect! Try again.
16A spanning tree of a connected graph with vertices contains exactly how many edges?
spanning tree
Easy
A.
B.
C.
D.
Correct Answer:
Explanation:
Since a spanning tree is a tree containing all vertices, it has exactly edges.
Incorrect! Try again.
17A minimum spanning tree (MST) of a weighted graph is the spanning tree with the:
minimum spanning tree
Easy
A.Minimum number of vertices
B.Minimum total edge weight
C.Maximum number of edges
D.Maximum total edge weight
Correct Answer: Minimum total edge weight
Explanation:
An MST is a spanning tree whose sum of edge weights is the smallest among all possible spanning trees.
Incorrect! Try again.
18Kruskal's algorithm builds a minimum spanning tree by considering edges in order of:
Kruskal and Prims algorithms to find minimum spanning tree
Easy
A.Random selection
B.Vertex label
C.Increasing weight
D.Decreasing weight
Correct Answer: Increasing weight
Explanation:
Kruskal's algorithm sorts all edges by weight in ascending order and adds them one by one, skipping any that form a cycle.
Incorrect! Try again.
19While adding edges, Kruskal's algorithm avoids selecting an edge that would:
Kruskal and Prims algorithms to find minimum spanning tree
Easy
A.Form a cycle
B.Increase the number of vertices
C.Reduce the total weight
D.Connect two vertices
Correct Answer: Form a cycle
Explanation:
Kruskal's algorithm rejects any edge whose inclusion would create a cycle, ensuring the result remains a tree.
Incorrect! Try again.
20Prim's algorithm builds the minimum spanning tree by:
Kruskal and Prims algorithms to find minimum spanning tree
Easy
A.Removing the heaviest edges from the graph
B.Growing the tree one vertex at a time from a starting vertex
C.Selecting vertices with the highest degree first
D.Sorting all edges globally and adding the smallest ones first regardless of connectivity
Correct Answer: Growing the tree one vertex at a time from a starting vertex
Explanation:
Prim's algorithm starts from a chosen vertex and repeatedly adds the smallest-weight edge that connects a new vertex to the growing tree.
Incorrect! Try again.
21In a weighted graph, the sum of the weights of all edges in a path is called the:
labelled and weighted graph
Medium
A.Edge count
B.Path length or path weight
C.Graph diameter
D.Vertex degree
Correct Answer: Path length or path weight
Explanation:
In a weighted graph, the weight (or length) of a path is the sum of the weights of the edges that make up the path.
Incorrect! Try again.
22A weighted graph has edges with weights that represent distances. If an edge between vertices and has weight and no edge exists between and , which statement is correct?
labelled and weighted graph
Medium
A.The distance equals
B.The edge has weight by default
C.The distance is considered until a path is found
D.The distance equals
Correct Answer: The distance is considered until a path is found
Explanation:
When no direct edge exists, the cost is taken as in shortest-path computations until an actual path is discovered.
Incorrect! Try again.
23Which property must hold for a shortest path between two vertices in a weighted graph with non-negative weights?
shortest path in weighted graphs
Medium
A.It always has the fewest number of edges
B.It must always pass through the vertex of highest degree
C.It must include every edge of minimum weight
D.Every subpath of a shortest path is also a shortest path
Correct Answer: Every subpath of a shortest path is also a shortest path
Explanation:
This is the optimal substructure property: any subpath of a shortest path is itself a shortest path between its endpoints.
Incorrect! Try again.
24A shortest path that minimizes the number of edges rather than total weight would be found by treating the graph as:
shortest path in weighted graphs
Medium
A.A weighted graph and using Dijkstra
B.A complete graph and using Prim's algorithm
C.An unweighted graph and using BFS
D.A tree and using DFS
Correct Answer: An unweighted graph and using BFS
Explanation:
When all edges count equally, minimizing edge count is equivalent to a BFS traversal on an unweighted graph.
Incorrect! Try again.
25Dijkstra's algorithm fails to give correct results when the graph contains:
26In Dijkstra's algorithm, once a vertex is marked as finalized (added to the set of visited vertices), its shortest distance:
Dijkstra's algorithm to find shortest path
Medium
A.Is set to infinity
B.May decrease later
C.May increase later
D.Will never change again
Correct Answer: Will never change again
Explanation:
Dijkstra finalizes a vertex only when its minimum distance is confirmed; with non-negative weights this value is never updated afterward.
Incorrect! Try again.
27Consider a graph with edges , , . Using Dijkstra from , the shortest distance to is:
Dijkstra's algorithm to find shortest path
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The path costs , which is less than the direct edge .
Incorrect! Try again.
28Using a binary min-heap (priority queue), the time complexity of Dijkstra's algorithm for a graph with vertices and edges is:
Dijkstra's algorithm to find shortest path
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
With a binary heap, each extract-min and decrease-key operation costs , giving an overall .
Incorrect! Try again.
29A connected graph with vertices is a tree if and only if it has exactly:
introduction to tree
Medium
A. edges
B. edges
C. edges
D. edges
Correct Answer: edges
Explanation:
A tree on vertices is connected and acyclic, which forces exactly edges.
Incorrect! Try again.
30Which of the following is NOT necessarily true for a tree?
introduction to tree
Medium
A.It contains at least one cycle
B.There is a unique path between any two vertices
C.Removing any edge disconnects it
D.It is connected
Correct Answer: It contains at least one cycle
Explanation:
A tree is acyclic by definition; the other three statements are all valid properties of trees.
Incorrect! Try again.
31In a rooted tree, a vertex with no children is called a:
rooted tree
Medium
A.Leaf (or terminal node)
B.Sibling node
C.Internal node
D.Root node
Correct Answer: Leaf (or terminal node)
Explanation:
A leaf is a node that has no children; internal nodes have at least one child.
Incorrect! Try again.
32In a rooted tree, the length of the path from the root to a given node is called that node's:
rooted tree
Medium
A.Height
B.Degree
C.Width
D.Depth (or level)
Correct Answer: Depth (or level)
Explanation:
Depth is the number of edges from the root to the node; height is measured from a node down to the deepest leaf.
Incorrect! Try again.
33The maximum number of nodes in a binary tree of height (root at height ) is:
binary tree
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
A full binary tree of height has nodes.
Incorrect! Try again.
34A binary tree with internal nodes, where every internal node has exactly two children (a full binary tree), has how many leaf nodes?
binary tree
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
In a full binary tree, the number of leaves is always one more than the number of internal nodes: .
Incorrect! Try again.
35How many distinct binary trees can be formed using unlabelled nodes?
binary tree
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
The number of distinct binary trees with nodes is the Catalan number ; for , .
Incorrect! Try again.
36A spanning tree of a connected graph with vertices always contains:
spanning tree
Medium
A.Exactly edges
B.All edges of the graph
C.Exactly edges
D.At least one cycle
Correct Answer: Exactly edges
Explanation:
A spanning tree includes all vertices while remaining a tree, so it has exactly edges and no cycles.
Incorrect! Try again.
37By Cayley's formula, the number of distinct spanning trees of a complete graph is:
spanning tree
Medium
A.
B.
C.
D.
Correct Answer:
Explanation:
Cayley's formula gives spanning trees for ; for , this is .
Incorrect! Try again.
38If all edge weights in a connected graph are distinct, then the minimum spanning tree is:
minimum spanning tree
Medium
A.Never unique
B.Always the same as any spanning tree
C.Unique
D.Undefined
Correct Answer: Unique
Explanation:
When all edge weights are distinct, there is exactly one minimum spanning tree for the graph.
Incorrect! Try again.
39Kruskal's algorithm selects edges in increasing order of weight while avoiding cycles. Which data structure efficiently detects cycles during this process?
Kruskal and Prims algorithms to find minimum spanning tree
Medium
A.Min-heap only
B.Union-Find (disjoint set)
C.Adjacency matrix
D.Stack
Correct Answer: Union-Find (disjoint set)
Explanation:
The Union-Find structure quickly checks whether two vertices are already connected, preventing cycle formation.
Incorrect! Try again.
40A key difference between Prim's and Kruskal's algorithms is that Prim's algorithm:
Kruskal and Prims algorithms to find minimum spanning tree
Medium
A.Can produce a forest during execution
B.Sorts all edges before starting
C.Only works on directed graphs
D.Grows a single connected tree from a starting vertex
Correct Answer: Grows a single connected tree from a starting vertex
Explanation:
Prim's maintains one growing connected tree, whereas Kruskal's may temporarily maintain a forest of components.
Incorrect! Try again.
41Dijkstra's algorithm may produce incorrect shortest-path results when a graph contains which of the following?
Dijkstra's algorithm to find shortest path
Hard
A.A large number of vertices
B.Self-loops with positive weight
C.Parallel edges with equal weights
D.Negative weight edges
Correct Answer: Negative weight edges
Explanation:
Dijkstra's greedy strategy finalizes a vertex's distance once it is extracted from the priority queue. A negative edge encountered later can offer a shorter path, but the vertex is already finalized, giving wrong results. Parallel edges, many vertices, and positive self-loops do not break correctness.
Incorrect! Try again.
42Using a binary min-heap as the priority queue, the time complexity of Dijkstra's algorithm on a graph with vertices and edges is:
Dijkstra's algorithm to find shortest path
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Each vertex extraction is giving , and each edge relaxation performs a decrease-key of giving . Together this is . The bound applies to the array-based implementation.
Incorrect! Try again.
43If all edge weights in a connected weighted graph are distinct, which statement about its minimum spanning tree (MST) is true?
minimum spanning tree
Hard
A.There may be several MSTs of equal weight
B.The MST is a Hamiltonian path
C.The MST is unique
D.The MST always contains the two heaviest edges
Correct Answer: The MST is unique
Explanation:
When all edge weights are distinct, the cut property and cycle property each select edges unambiguously, so exactly one MST exists. Multiple MSTs can only occur when some edge weights are equal.
Incorrect! Try again.
44By Cayley's formula, the number of distinct spanning trees of the complete graph is:
spanning tree
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Cayley's formula gives spanning trees for . For , this is .
Incorrect! Try again.
45The Union-Find data structure with union by rank and path compression is used in Kruskal's algorithm primarily to:
Kruskal and Prims algorithms to find minimum spanning tree
Hard
A.Compute shortest distances between components
B.Sort the edges by weight faster
C.Store the final MST edges in order
D.Efficiently detect whether adding an edge forms a cycle
Correct Answer: Efficiently detect whether adding an edge forms a cycle
Explanation:
Kruskal's adds an edge only if its endpoints lie in different components. Union-Find checks connectivity (cycle detection) in near-constant amortized time. Sorting is done separately, typically in .
Incorrect! Try again.
46A binary tree has internal nodes each with exactly two children (a full binary tree). How many leaf nodes does it have?
binary tree
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
In a full binary tree, the number of leaves equals the number of internal (degree-2) nodes plus one, i.e. . This follows from counting edges: edges connect to leaves plus the remaining internal nodes.
Incorrect! Try again.
47Prim's algorithm grows the MST by repeatedly selecting the minimum-weight edge that:
Prims algorithm to find minimum spanning tree
Hard
A.Has not yet been examined regardless of endpoints
B.Crosses the cut between the tree and the remaining vertices
C.Completes a cycle within the current tree
D.Connects the two most distant vertices
Correct Answer: Crosses the cut between the tree and the remaining vertices
Explanation:
Prim's maintains a growing tree and, at each step, adds the cheapest edge crossing the cut separating tree vertices from non-tree vertices. This is a direct application of the cut property.
Incorrect! Try again.
48A weighted graph has vertices. Which representation gives time to query the weight of a specific edge ?
labelled and weighted graph
Hard
A.Edge list
B.Adjacency list
C.Incidence matrix
D.Adjacency matrix
Correct Answer: Adjacency matrix
Explanation:
An adjacency matrix stores the weight of edge at position , allowing direct lookup. Adjacency lists and edge lists require scanning, and an incidence matrix requires scanning columns.
Incorrect! Try again.
49Consider a connected weighted graph. If an edge is the unique maximum-weight edge on some cycle, which property guarantees is excluded from the MST?
minimum spanning tree
Hard
A.The pigeonhole principle
B.The handshake lemma
C.The cut property
D.The cycle property
Correct Answer: The cycle property
Explanation:
The cycle property states that the unique heaviest edge in any cycle cannot belong to any MST, since removing it and using the cycle's other edges yields a lighter spanning structure.
Incorrect! Try again.
50In a weighted graph where every edge weight is multiplied by a positive constant , the shortest path between any two vertices:
shortest path in weighted graphs
Hard
A.Becomes the longest path
B.Is unaffected in both edges and total cost
C.May change to a completely different route
D.Remains the same set of edges, with total cost scaled by
Correct Answer: Remains the same set of edges, with total cost scaled by
Explanation:
Scaling all weights by a positive constant preserves the relative ordering of every path's cost, so the optimal route is unchanged while its total cost is multiplied by .
Incorrect! Try again.
51In a rooted tree with nodes, what is the sum of the number of children over all nodes?
rooted tree
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Every node except the root is the child of exactly one parent, so counting children over all nodes equals the number of non-root nodes, which is (also the number of edges).
Incorrect! Try again.
52During Dijkstra's execution, at the moment a vertex is extracted from the priority queue, which invariant holds?
Dijkstra's algorithm to find shortest path
Hard
A.Every neighbor of is already finalized
B.The distance label of equals its true shortest distance from the source
C. must be adjacent to the source
D. has the largest distance among all vertices
Correct Answer: The distance label of equals its true shortest distance from the source
Explanation:
Dijkstra's correctness rests on the fact that when the minimum-label vertex is extracted, its label already equals the true shortest distance, because all shorter paths would go through already-finalized vertices with non-negative edges.
Incorrect! Try again.
53For a dense graph with edges, which MST algorithm/implementation is typically most efficient?
Kruskal and Prims algorithms to find minimum spanning tree
Hard
A.Kruskal's with edge sorting in
B.Prim's with a binary heap in
C.Prim's with an adjacency matrix in
D.Repeated Dijkstra from every vertex
Correct Answer: Prim's with an adjacency matrix in
Explanation:
For dense graphs , the array-based Prim's is optimal since for Kruskal's and for heap-Prim's are asymptotically larger.
Incorrect! Try again.
54What is the maximum number of nodes in a binary tree of height (where a single node has height )?
binary tree
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
A perfect binary tree of height has levels through , containing nodes.
Incorrect! Try again.
55A connected graph has vertices and edges. The number of edges that must be removed to obtain a spanning tree is:
spanning tree
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
A spanning tree has exactly edges. Removing the excess edges (the cyclomatic number) yields a spanning tree.
Incorrect! Try again.
56Which statement correctly relates the MST and the shortest-path tree (SPT) rooted at a vertex in a weighted graph?
minimum spanning tree
Hard
A.The SPT always has smaller total weight than the MST
B.They can be different trees for the same graph
C.The MST is always a subtree of the SPT
D.They are always identical
Correct Answer: They can be different trees for the same graph
Explanation:
An MST minimizes total edge weight, while an SPT minimizes distances from a source. These are different objectives, so the two trees generally differ, though they may coincide in special cases.
Incorrect! Try again.
57If a weighted directed graph contains a negative-weight cycle reachable from the source, the shortest-path problem:
shortest path in weighted graphs
Hard
A.Is undefined because distances can decrease without bound
B.Can be solved correctly by Dijkstra's algorithm
C.Has shortest distances equal to zero
D.Always has a unique finite solution
Correct Answer: Is undefined because distances can decrease without bound
Explanation:
Traversing a negative cycle repeatedly reduces path cost indefinitely, so no finite shortest path exists. Algorithms like Bellman-Ford detect such cycles; Dijkstra's cannot even handle negative edges.
Incorrect! Try again.
58Both Kruskal's and Prim's algorithms are greedy and correct because they rely on which fundamental principle?
Kruskal and Prims algorithms to find minimum spanning tree
Hard
A.Optimal substructure of longest paths
B.The cut property guarantees the minimum crossing edge is safe to add
C.The matrix-tree theorem
D.Dynamic programming over subsets
Correct Answer: The cut property guarantees the minimum crossing edge is safe to add
Explanation:
Both algorithms add a minimum-weight edge crossing some cut. The cut property proves such an edge belongs to some MST, ensuring the greedy choices build an optimal tree.
Incorrect! Try again.
59In a complete -ary rooted tree with internal nodes, the total number of nodes is:
rooted tree
Hard
A.
B.
C.
D.
Correct Answer:
Explanation:
Each of the internal nodes has children, giving non-root nodes. Adding the single root yields a total of nodes.
Incorrect! Try again.
60In a weighted graph, if a unique edge has strictly the smallest weight, then this edge:
labelled and weighted graph
Hard
A.Must form a cycle in the MST
B.May be excluded from some MST
C.Is always the root of the spanning tree
D.Belongs to every minimum spanning tree
Correct Answer: Belongs to every minimum spanning tree
Explanation:
By the cut property, the globally minimum-weight edge crosses some cut as the cheapest crossing edge, so it is safe and must appear in every MST when its weight is strictly the smallest.
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 →