Graphs MCQs

By: Prof. Dr. Fazal Rehman Shamil | Last updated: September 20, 2024

What is a graph in data structures?
A) A collection of nodes and edges
B) A linear data structure
C) A data structure that stores data in a sorted manner
D) A type of tree
Answer: A) A collection of nodes and edges

Which of the following represents a directed graph?
A) A graph where edges have no direction
B) A graph where edges point from one vertex to another
C) A graph that forms a cycle
D) A graph with weighted edges
Answer: B) A graph where edges point from one vertex to another

What is an undirected graph?
A) A graph with directed edges
B) A graph where edges have no direction
C) A graph with weighted edges
D) A graph that contains cycles
Answer: B) A graph where edges have no direction

What is the degree of a vertex in a graph?
A) The number of edges connected to the vertex
B) The number of vertices connected to the graph
C) The length of the longest path
D) The total number of vertices in the graph
Answer: A) The number of edges connected to the vertex

What is a weighted graph?
A) A graph with no edges
B) A graph where edges have weights assigned to them
C) A graph that only contains directed edges
D) A graph that forms a cycle
Answer: B) A graph where edges have weights assigned to them

What is the main purpose of a graph traversal algorithm?
A) To find the shortest path
B) To visit all the vertices in a graph
C) To sort the vertices
D) To remove edges
Answer: B) To visit all the vertices in a graph

Which of the following algorithms is used for finding the shortest path in a graph?
A) Depth-first search
B) Breadth-first search
C) Dijkstra’s algorithm
D) Prim’s algorithm
Answer: C) Dijkstra’s algorithm

What is a cycle in a graph?
A) A path that visits each vertex exactly once
B) A path that starts and ends at the same vertex
C) A graph with no edges
D) A directed graph
Answer: B) A path that starts and ends at the same vertex

What is the time complexity of depth-first search (DFS) in a graph with V vertices and E edges?
A) O(V)
B) O(E)
C) O(V + E)
D) O(V * E)
Answer: C) O(V + E)

What is the time complexity of breadth-first search (BFS) in a graph with V vertices and E edges?
A) O(V)
B) O(E)
C) O(V + E)
D) O(V * E)
Answer: C) O(V + E)

What type of data structure is commonly used to implement a graph?
A) Array
B) Linked list
C) Hash table
D) Both A and B
Answer: D) Both A and B

What is an adjacency matrix?
A) A list of edges in a graph
B) A 2D array representing the connection between vertices
C) A list of vertices
D) A representation of weights in a graph
Answer: B) A 2D array representing the connection between vertices

What is an adjacency list?
A) A 2D array representation of a graph
B) A collection of lists where each list corresponds to a vertex
C) A matrix representing the graph
D) A table of edges
Answer: B) A collection of lists where each list corresponds to a vertex

Which traversal algorithm would you use to find the shortest path in an unweighted graph?
A) Depth-first search
B) Breadth-first search
C) Dijkstra’s algorithm
D) A* search
Answer: B) Breadth-first search

What is a complete graph?
A) A graph with no edges
B) A graph where every pair of vertices is connected by an edge
C) A directed graph
D) A graph that forms a cycle
Answer: B) A graph where every pair of vertices is connected by an edge

What is a bipartite graph?
A) A graph with only two vertices
B) A graph whose vertices can be divided into two disjoint sets
C) A graph with cycles
D) A graph where all edges are directed
Answer: B) A graph whose vertices can be divided into two disjoint sets

What is a spanning tree?
A) A tree that connects all vertices with minimum edges
B) A tree that contains all edges of the graph
C) A cycle that includes all vertices
D) A disconnected subgraph
Answer: A) A tree that connects all vertices with minimum edges

What algorithm is commonly used to find the minimum spanning tree?
A) Dijkstra’s algorithm
B) Prim’s algorithm
C) Kruskal’s algorithm
D) Both B and C
Answer: D) Both B and C

In a graph, what is the difference between a path and a cycle?
A) A path can have repeated vertices, while a cycle cannot
B) A path cannot have repeated vertices, while a cycle can
C) Both paths and cycles are the same
D) A cycle is always longer than a path
Answer: B) A path cannot have repeated vertices, while a cycle can

What is the purpose of the Floyd-Warshall algorithm?
A) To find the shortest path between two specific vertices
B) To find the shortest path between all pairs of vertices
C) To find the maximum flow in a network
D) To detect cycles in a graph
Answer: B) To find the shortest path between all pairs of vertices

What does it mean for a graph to be acyclic?
A) It has no edges
B) It contains cycles
C) It has a tree structure
D) It contains no cycles
Answer: D) It contains no cycles

What is a directed acyclic graph (DAG)?
A) A graph with directed edges and no cycles
B) A graph with undirected edges
C) A graph that forms a cycle
D) A graph with weighted edges
Answer: A) A graph with directed edges and no cycles

What is a cut in a graph?
A) A vertex with the highest degree
B) A partition of the vertices into two disjoint subsets
C) The removal of an edge
D) A path that visits every edge
Answer: B) A partition of the vertices into two disjoint subsets

What is the chromatic number of a graph?
A) The number of edges
B) The minimum number of colors needed to color the vertices
C) The maximum degree of a vertex
D) The number of vertices
Answer: B) The minimum number of colors needed to color the vertices

Which of the following statements is true about Eulerian paths?
A) They can visit each edge exactly once
B) They can visit each vertex exactly once
C) They cannot repeat edges
D) They must start and end at different vertices
Answer: A) They can visit each edge exactly once

What is the main difference between DFS and BFS?
A) DFS uses a queue, while BFS uses a stack
B) BFS explores neighbors before moving deeper, while DFS goes deep first
C) DFS is faster than BFS
D) BFS is recursive, while DFS is iterative
Answer: B) BFS explores neighbors before moving deeper, while DFS goes deep first

What is the time complexity of checking if a graph is connected using BFS?
A) O(V)
B) O(E)
C) O(V + E)
D) O(V^2)
Answer: C) O(V + E)

What does a strongly connected graph mean?
A) There is a path between any two vertices in both directions
B) All vertices are isolated
C) The graph contains cycles
D) It is a bipartite graph
Answer: A) There is a path between any two vertices in both directions

What is the primary characteristic of a tree?
A) It is a type of graph that contains cycles
B) It has no vertices
C) It is a connected graph with no cycles
D) It has multiple roots
Answer: C) It is a connected graph with no cycles

Which of the following is not a characteristic of trees?
A) A tree has one less edge than the number of vertices
B) A tree is a connected graph
C) A tree can have cycles
D) A tree has no cycles
Answer: C) A tree can have cycles

What is the primary purpose of the A search algorithm?*
A) To find the shortest path in weighted graphs
B) To traverse all vertices
C) To find cycles
D) To create a minimum spanning tree
Answer: A) To find the shortest path in weighted graphs

What is a graph traversal algorithm?
A) An algorithm to sort vertices
B) An algorithm to visit all vertices in a specific order
C) An algorithm to remove edges
D) An algorithm to find cycles
Answer: B) An algorithm to visit all vertices in a specific order

What is the main disadvantage of using an adjacency matrix?
A) It cannot represent graphs
B) It uses more memory for sparse graphs
C) It is difficult to implement
D) It is not efficient for dense graphs
Answer: B) It uses more memory for sparse graphs

What is a network flow problem in graph theory?
A) Finding the shortest path
B) Finding the maximum flow from a source to a sink
C) Coloring the vertices of a graph
D) Finding cycles
Answer: B) Finding the maximum flow from a source to a sink

What does it mean for two vertices to be adjacent in a graph?
A) They are not connected by an edge
B) They are connected directly by an edge
C) They have the same degree
D) They are in different connected components
Answer: B) They are connected directly by an edge

What is a planar graph?
A) A graph that can be drawn on a plane without edges crossing
B) A graph that contains cycles
C) A graph with weighted edges
D) A graph that is disconnected
Answer: A) A graph that can be drawn on a plane without edges crossing

Which of the following can be used to detect cycles in a directed graph?
A) Depth-first search
B) Breadth-first search
C) Kruskal’s algorithm
D) Prim’s algorithm
Answer: A) Depth-first search

What is a tree traversal?
A) The process of visiting all nodes in a tree
B) The process of counting the nodes in a tree
C) The process of finding the height of a tree
D) The process of searching for a specific value
Answer: A) The process of visiting all nodes in a tree

What does the term “graph density” refer to?
A) The number of edges in relation to the number of vertices
B) The number of vertices in a graph
C) The total weight of the edges
D) The number of connected components
Answer: A) The number of edges in relation to the number of vertices

 

Data Structures MCQs

Basic Concepts

  1. Introduction to Data Structures
  2. Complexity Analysis MCQs

Linear Data Structures MCQs

  1. Arrays MCQs
  2. Linked Lists MCQs
  3. Stacks MCQs
  4. Queues MCQs

Non-Linear Data Structures MCQs

  1. Trees MCQs
  2. Heaps MCQs
  3. Graphs MCQs

Hashing MCQs MCQs

  1. Hash Tables

Sorting and Searching Algorithms MCQs 

  1. Sorting Algorithms MCQs
  2. Searching Algorithms MCQs

Miscellaneous

  1. Memory Management in data structures MCQs
  2. String Manipulation Algorithms MCQs
  1. Data Structures MCQs 1
  2. Data Structures MCQs 2
  3. Data Structures MCQs 3
  4. Data Structures MCQs 4
  5. Data Structures MCQs 5
  6. Stacks Solved MCQs
  7. Queues MCQs
  8. pointer mcqs
  9. Array MCQs