Back to Practice Data Structures

Graphs - Practice MCQs for CCAT

50 Questions Section B: Programming Data Structures

Graphs Question Bank for C-CAT

Topic-wise Graphs MCQs for CDAC C-CAT preparation with answers and explanations.

Q1.
Shortest path in unweighted graph uses:
ADFS
BBFS
CDijkstra
DBellman-Ford
Show Answer & Explanation

Correct Answer: B - BFS

BFS finds shortest path in unweighted graphs by exploring level by level.

Q2.
Dijkstra's algorithm finds:
AMST
BAll pairs shortest path
CShortest path from single source
DCycle detection
Show Answer & Explanation

Correct Answer: C - Shortest path from single source

Dijkstra finds shortest path from single source to all other vertices.

Q3.
DFS uses which data structure?
AStack
BQueue
CPriority Queue
DHeap
Show Answer & Explanation

Correct Answer: A - Stack

DFS uses stack (or recursion which uses call stack).

Q4.
A graph with n vertices can have maximum __ edges (simple, undirected):
An
Bn(n-1)/2
Cn-1
D
Show Answer & Explanation

Correct Answer: B - n(n-1)/2

Maximum edges in simple undirected graph = n(n-1)/2 (complete graph).

Q5.
Topological sort is for:
ADAG only
BUndirected graph
CAny graph
DComplete graph
Show Answer & Explanation

Correct Answer: A - DAG only

Topological sort works only on Directed Acyclic Graphs (DAG).

Q6.
Kruskal's algorithm finds:
AShortest path
BMinimum Spanning Tree
CMaximum flow
DCycle
Show Answer & Explanation

Correct Answer: B - Minimum Spanning Tree

Kruskal's finds MST using greedy approach, selecting smallest edges.

Q7.
Time complexity of BFS with adjacency list:
AO(V)
BO(E)
CO(V×E)
DO(V+E)
Show Answer & Explanation

Correct Answer: D - O(V+E)

BFS visits all vertices and edges once, taking O(V+E) time.

Q8.
A connected graph with V vertices has at least __ edges:
AV
B2V
CV+1
DV-1
Show Answer & Explanation

Correct Answer: D - V-1

Minimum edges for connected graph is V-1 (a tree).

Q9.
Adjacency matrix for n vertices uses __ space:
AO(n)
BO(1)
CO(log n)
DO(n²)
Show Answer & Explanation

Correct Answer: D - O(n²)

Adjacency matrix is n×n, using O(n²) space.

Q10.
Prim's algorithm is used for:
AShortest path
BCycle detection
CMST
DTopological sort
Show Answer & Explanation

Correct Answer: C - MST

Prim's algorithm finds Minimum Spanning Tree.

Q11.
Which algorithm detects negative weight cycles?
ADijkstra
BPrim
CBellman-Ford
DKruskal
Show Answer & Explanation

Correct Answer: C - Bellman-Ford

Bellman-Ford algorithm can detect negative weight cycles in a graph.

Q12.
Floyd-Warshall algorithm finds:
ASingle source shortest path
BAll pairs shortest paths
CMST
DTopological order
Show Answer & Explanation

Correct Answer: B - All pairs shortest paths

Floyd-Warshall finds shortest paths between all pairs of vertices.

Q13.
Time complexity of Floyd-Warshall algorithm:
AO(V²)
BO(V³)
CO(V+E)
DO(VE)
Show Answer & Explanation

Correct Answer: B - O(V³)

Floyd-Warshall uses three nested loops, giving O(V³) complexity.

Q14.
A graph is bipartite if it contains no cycle of:
AEven length
BOdd length
CLength 3
DLength 4
Show Answer & Explanation

Correct Answer: B - Odd length

A graph is bipartite if and only if it contains no odd-length cycles.

Q15.
Strongly connected components are found using:
ABFS only
BDijkstra
CKosaraju or Tarjan algorithm
DPrim
Show Answer & Explanation

Correct Answer: C - Kosaraju or Tarjan algorithm

Kosaraju's and Tarjan's algorithms find strongly connected components in directed graphs.

Q16.
An articulation point in a graph is:
AHighest degree vertex
BRoot node
CLeaf node
DVertex whose removal disconnects graph
Show Answer & Explanation

Correct Answer: D - Vertex whose removal disconnects graph

An articulation point (cut vertex) is a vertex whose removal increases connected components.

Q17.
In-degree of a vertex in directed graph is:
AIncoming edges count
BOutgoing edges count
CTotal edges
DSelf-loops
Show Answer & Explanation

Correct Answer: A - Incoming edges count

In-degree is the number of edges coming into a vertex.

Q18.
Which data structure is used in Dijkstra for efficiency?
AStack
BMin-Heap/Priority Queue
CQueue
DLinked List
Show Answer & Explanation

Correct Answer: B - Min-Heap/Priority Queue

Min-heap or priority queue gives O((V+E)log V) complexity for Dijkstra.

Q19.
A tree with n vertices has exactly:
An edges
B2n edges
Cn+1 edges
Dn-1 edges
Show Answer & Explanation

Correct Answer: D - n-1 edges

A tree is a connected acyclic graph with exactly n-1 edges for n vertices.

Q20.
Back edge in DFS indicates:
APresence of cycle
BTree structure
CShortest path
DDisconnected graph
Show Answer & Explanation

Correct Answer: A - Presence of cycle

A back edge (edge to ancestor) in DFS tree indicates a cycle in the graph.

Q21.
Which data structure is typically used to implement Breadth-First Search (BFS)?
AQueue
BStack
CPriority Queue
DDeque
Show Answer & Explanation

Correct Answer: A - Queue

BFS uses a queue to explore all vertices at the current depth level before moving to vertices at the next depth level.

Q22.
Which data structure is typically used to implement Depth-First Search (DFS)?
AQueue
BStack
CPriority Queue
DArray
Show Answer & Explanation

Correct Answer: B - Stack

DFS uses a stack (either explicitly or via recursion's call stack) to explore as deep as possible along each branch before backtracking.

Q23.
The time complexity of BFS on a graph with V vertices and E edges using an adjacency list is:
AO(V)
BO(E)
CO(V × E)
DO(V + E)
Show Answer & Explanation

Correct Answer: D - O(V + E)

BFS visits each vertex once O(V) and examines each edge once O(E), giving a total time complexity of O(V + E).

Q24.
Which algorithm is used to find the shortest path in an unweighted graph?
ABFS
BDijkstra's algorithm
CDFS
DBellman-Ford algorithm
Show Answer & Explanation

Correct Answer: A - BFS

BFS finds the shortest path in an unweighted graph because it explores nodes level by level, ensuring the first time a node is reached is via the shortest path.

Q25.
Dijkstra's algorithm does NOT work correctly with:
ADirected graphs
BUndirected graphs
CDense graphs
DGraphs with negative edge weights
Show Answer & Explanation

Correct Answer: D - Graphs with negative edge weights

Dijkstra's algorithm assumes all edge weights are non-negative. Negative edge weights can cause it to produce incorrect shortest paths.

Q26.
Which algorithm can find shortest paths in a graph with negative edge weights (but no negative cycles)?
ADijkstra's algorithm
BPrim's algorithm
CKruskal's algorithm
DBellman-Ford algorithm
Show Answer & Explanation

Correct Answer: D - Bellman-Ford algorithm

The Bellman-Ford algorithm can handle negative edge weights and also detect negative weight cycles, unlike Dijkstra's algorithm.

Q27.
The number of edges in a complete undirected graph with n vertices is:
An
Bn(n-1)
Cn(n-1)/2
D2n
Show Answer & Explanation

Correct Answer: C - n(n-1)/2

In a complete undirected graph, every pair of distinct vertices is connected by an edge. The number of such pairs is C(n,2) = n(n-1)/2.

Q28.
Which of the following is true about a tree in graph theory?
AIt can have cycles
BIt must have at least one cycle
CIt is a connected acyclic graph
DIt is always a directed graph
Show Answer & Explanation

Correct Answer: C - It is a connected acyclic graph

A tree is defined as a connected acyclic graph. It has exactly n-1 edges for n vertices and no cycles.

Q29.
Kruskal's algorithm is used to find:
AShortest path between two vertices
BMinimum Spanning Tree
CMaximum flow in a network
DTopological ordering
Show Answer & Explanation

Correct Answer: B - Minimum Spanning Tree

Kruskal's algorithm finds the Minimum Spanning Tree (MST) of a connected weighted graph by greedily adding edges in order of increasing weight.

Q30.
Prim's algorithm for MST uses which approach?
AGreedy
BDivide and conquer
CDynamic programming
DBacktracking
Show Answer & Explanation

Correct Answer: A - Greedy

Prim's algorithm uses a greedy approach, growing the MST by always adding the minimum weight edge connecting the tree to a vertex not yet in the tree.

Q31.
The space complexity of an adjacency matrix for a graph with V vertices is:
AO(V²)
BO(V)
CO(V + E)
DO(E)
Show Answer & Explanation

Correct Answer: A - O(V²)

An adjacency matrix requires a V × V 2D array, resulting in O(V²) space regardless of the number of edges.

Q32.
For a sparse graph, which representation is more space-efficient?
AAdjacency matrix
BAdjacency list
CBoth are equally efficient
DIncidence matrix
Show Answer & Explanation

Correct Answer: B - Adjacency list

An adjacency list uses O(V + E) space, which is much less than O(V²) of an adjacency matrix when the graph is sparse (E << V²).

Q33.
Topological sorting is possible only for:
AUndirected graphs
BComplete graphs
CCyclic graphs
DDirected Acyclic Graphs (DAGs)
Show Answer & Explanation

Correct Answer: D - Directed Acyclic Graphs (DAGs)

Topological sorting is only possible for Directed Acyclic Graphs (DAGs). If a graph has a cycle, no valid topological ordering exists.

Q34.
In DFS of a directed graph, a back edge indicates the presence of:
AA cycle
BA spanning tree
CA bridge
DAn articulation point
Show Answer & Explanation

Correct Answer: A - A cycle

A back edge in DFS connects a vertex to one of its ancestors in the DFS tree, which indicates the presence of a cycle in a directed graph.

Q35.
The time complexity of Dijkstra's algorithm using a binary heap is:
AO(V²)
BO(E log V)
CO(V + E)
DO(V log V)
Show Answer & Explanation

Correct Answer: B - O(E log V)

Using a binary heap (min-priority queue), Dijkstra's algorithm runs in O(E log V) time, as each edge relaxation involves a heap operation of O(log V).

Q36.
Which of the following algorithms can detect a negative weight cycle in a graph?
ABellman-Ford algorithm
BPrim's algorithm
CDijkstra's algorithm
DFloyd-Warshall algorithm
Show Answer & Explanation

Correct Answer: A - Bellman-Ford algorithm

Bellman-Ford can detect negative weight cycles by running one extra iteration. If any distance is updated in the V-th iteration, a negative cycle exists.

Q37.
A graph with V vertices and exactly V-1 edges that is connected is called a:
AComplete graph
BBipartite graph
CTree
DCycle
Show Answer & Explanation

Correct Answer: C - Tree

A connected graph with V vertices and exactly V-1 edges is a tree. It has no cycles and removing any edge disconnects it.

Q38.
What is the maximum number of edges in a directed graph with n vertices (no self-loops)?
An(n-1)/2
Bn(n-1)
C
D2n
Show Answer & Explanation

Correct Answer: B - n(n-1)

In a directed graph without self-loops, each ordered pair of distinct vertices can have an edge. There are n(n-1) such ordered pairs.

Q39.
Which algorithm finds the shortest paths between all pairs of vertices?
ADijkstra's algorithm
BBFS
CFloyd-Warshall algorithm
DPrim's algorithm
Show Answer & Explanation

Correct Answer: C - Floyd-Warshall algorithm

Floyd-Warshall algorithm computes shortest paths between all pairs of vertices using dynamic programming with O(V³) time complexity.

Q40.
The degree of a vertex in an undirected graph is:
AThe number of paths from it to other vertices
BThe number of edges in the graph
CThe number of vertices adjacent to it
DThe weight of the vertex
Show Answer & Explanation

Correct Answer: C - The number of vertices adjacent to it

The degree of a vertex in an undirected graph is the number of edges incident to it, which equals the number of adjacent vertices.

Q41.
In an undirected graph, the sum of degrees of all vertices equals:
ANumber of vertices
BNumber of edges
CTwice the number of edges
DSquare of number of vertices
Show Answer & Explanation

Correct Answer: C - Twice the number of edges

By the Handshaking Lemma, the sum of degrees of all vertices in an undirected graph equals 2 × E (twice the number of edges), since each edge contributes to the degree of two vertices.

Q42.
Which data structure is used in Kruskal's algorithm to detect cycles efficiently?
AStack
BQueue
CHash Table
DDisjoint Set (Union-Find)
Show Answer & Explanation

Correct Answer: D - Disjoint Set (Union-Find)

Kruskal's algorithm uses the Disjoint Set (Union-Find) data structure to efficiently check whether adding an edge would create a cycle.

Q43.
A bipartite graph is one that:
AHas exactly two vertices
BHas exactly two edges
CCan be colored with 2 colors such that no adjacent vertices share a color
DHas vertices of degree 2 only
Show Answer & Explanation

Correct Answer: C - Can be colored with 2 colors such that no adjacent vertices share a color

A bipartite graph can be divided into two sets such that every edge connects a vertex from one set to the other, equivalent to being 2-colorable.

Q44.
What is the time complexity of the Bellman-Ford algorithm?
AO(VE)
BO(V log V)
CO(V + E)
DO(V²)
Show Answer & Explanation

Correct Answer: A - O(VE)

Bellman-Ford relaxes all E edges V-1 times, giving a time complexity of O(VE).

Q45.
An articulation point in a graph is a vertex whose removal:
AIncreases the number of edges
BCreates a cycle
CReduces the degree of all vertices
DDisconnects the graph
Show Answer & Explanation

Correct Answer: D - Disconnects the graph

An articulation point (or cut vertex) is a vertex whose removal increases the number of connected components, disconnecting the graph.

Q46.
Which traversal can be used to check if an undirected graph is bipartite?
ADFS only
BBFS only
CBoth BFS and DFS
DNeither BFS nor DFS
Show Answer & Explanation

Correct Answer: C - Both BFS and DFS

Both BFS and DFS can check bipartiteness by attempting a 2-coloring. If a conflict is found (adjacent vertices same color), the graph is not bipartite.

Q47.
The minimum number of edges required to make a graph with V vertices connected is:
AV - 1
BV
CV + 1
DV/2
Show Answer & Explanation

Correct Answer: A - V - 1

A connected graph with V vertices requires at least V-1 edges, forming a tree structure.

Q48.
Which of the following is true about the Minimum Spanning Tree (MST) of a graph?
AIt contains V edges
BIt connects all vertices with minimum total edge weight
CIt may contain cycles
DIt always uses the shortest path between every pair of vertices
Show Answer & Explanation

Correct Answer: B - It connects all vertices with minimum total edge weight

An MST connects all V vertices using V-1 edges with the minimum possible total edge weight, without forming any cycle.

Q49.
In BFS, when we visit a vertex, we mark it as visited to:
AReduce space complexity
BOptimize edge weights
CSort the vertices
DAvoid revisiting and infinite loops
Show Answer & Explanation

Correct Answer: D - Avoid revisiting and infinite loops

Marking vertices as visited in BFS prevents revisiting them, which avoids infinite loops (especially in cyclic graphs) and ensures each vertex is processed once.

Q50.
The time complexity of Floyd-Warshall algorithm is:
AO(V³)
BO(V² log V)
CO(V²)
DO(VE)
Show Answer & Explanation

Correct Answer: A - O(V³)

Floyd-Warshall uses three nested loops over V vertices, resulting in O(V³) time complexity.

Showing 1-10 of 50 questions