0% found this document useful (0 votes)
2 views

Data Structures and Algorithms

The document contains practice questions focused on graphs, including multiple-choice questions (MCQs) and subjective questions related to graph theory, algorithms, and data structures. Key topics include graph connectivity, traversal algorithms like BFS and DFS, Dijkstra's algorithm, and concepts such as minimum spanning trees and cycle detection. The document serves as a study aid for understanding fundamental graph concepts and algorithms.

Uploaded by

Irfan Ul Haq
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Data Structures and Algorithms

The document contains practice questions focused on graphs, including multiple-choice questions (MCQs) and subjective questions related to graph theory, algorithms, and data structures. Key topics include graph connectivity, traversal algorithms like BFS and DFS, Dijkstra's algorithm, and concepts such as minimum spanning trees and cycle detection. The document serves as a study aid for understanding fundamental graph concepts and algorithms.

Uploaded by

Irfan Ul Haq
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Data Structures and Algorithms.

(Practice Question)

Topic: Graphs

MCQ’s

1. A graph is said to be connected if:


a) Every node has at least one edge
b) There is a path between every pair of vertices
c) All nodes are at the same level
d) It contains no cycles
2. Which of the following is used to implement Breadth-First Search (BFS)?
a) Stack
b) Queue
c) Priority Queue
d) Hash Table
3. The time complexity of Depth-First Search (DFS) is:
a) O (V + E)
b) O(V^2)
c) O (E log V)
d) O(V^3)
4. In Dijkstra's algorithm, which data structure is commonly used to store and fetch the next
vertex with the smallest distance?
a) Stack
b) Queue
c) Priority Queue
d) Linked List
5. A graph with no cycles is called:
a) Directed graph
b) Weighted graph
c) Tree
d) Acyclic graph
6. Kruskal’s algorithm is used to find:
a) Shortest path
b) Minimum spanning tree
c) Maximum flow
d) Strongly connected components
7. What is the degree of a vertex in a graph?
a) Number of edges connected to the vertex
b) Number of paths passing through the vertex
c) Weight of the vertex
d) Distance from the source vertex
8. Which traversal technique uses a stack?
a) DFS
b) BFS
c) Kruskal’s Algorithm
d) Floyd-Warshall Algorithm
9. In a weighted graph, the weight of an edge represents:
a) Degree of the vertex
b) Number of vertices connected by the edge
c) Cost of traversal between the vertices
d) None of the above
10. Adjacency matrix representation of a graph requires:
a) O (V + E) space
b) O(V^2) space
c) O (E log V) space
d) O(E^2) space
11. Which of the following is NOT a fundamental graph traversal algorithm?
a. Depth-First Search (DFS)
b. Breadth-First Search (BFS)
c. Dijkstra's Algorithm (Dijkstra's is a shortest path algorithm, not a traversal algorithm
itself)
d. Prim's Algorithm
12. A graph with no cycles is called a(n):
a. Directed Graph
b. Undirected Graph
c. Acyclic Graph
d. Weighted Graph
13. In a weighted graph, the shortest path between two nodes is determined using:
a. DFS
b. BFS
c. Dijkstra's Algorithm
d. Topological Sort
14. A data structure used to efficiently represent a graph is:
a. Array
b. Linked List
c. Tree
d. Adjacency Matrix/List
15. A graph where every node is connected to every other node is called a(n):
a. Complete Graph
b. Bipartite Graph
c. Tree
d. Cyclic Graph
16. Which algorithm is used to find the minimum spanning tree of a graph?
a. Dijkstra's Algorithm
b. Bellman-Ford Algorithm
c. Prim's Algorithm
d. Floyd-Warshall Algorithm
17. A node with no outgoing edges is called a(n):
a. Source Node
b. Sink Node
c. Isolated Node
d. Degree Node
18. In a directed graph, an edge from node A to node B is represented as:
a. A -> B
b. B -> A
c. A <-> B
d. A || B
19. What is the time complexity of DFS in the worst case?
a. O(V)
b. O(E)
c. O (V + E)
d. O(V^2)
20. A graph that can be drawn without any edges crossing is called a(n):
a) Planar Graph
b) Non-Planar Graph
c) Cyclic Graph
d) Acyclic Graph
21. The graph traversal algorithm that explores all neighbors at the current depth before
moving to the next depth is:
a) DFS
b) BFS
c) Dijkstra's
d) Kruskal's
22. The process of checking if all vertices of a graph are reachable from a given starting
vertex is called:
a) Connectivity test
b) Graph traversal
c) Cycle detection
d) Topological sorting
23. In a directed acyclic graph (DAG), what is the significance of topological sorting?
a) Finding the shortest path
b) Determining the execution order of tasks
c) Detecting cycles
d) Calculating minimum spanning tree
24. What is the primary purpose of the Floyd-Warshall algorithm?
a) Finding the shortest paths between a single source and all other vertices
b) Finding the shortest paths between all pairs of vertices
c) Finding the maximum flow in a graph
d) Detecting negative weight cycles
25. Which of the following is not a characteristic of a tree?
a) It is a connected graph
b) It has exactly one cycle
c) It has |V| - 1 edges
d) It is acyclic
26. If a graph has n vertices and m edges, the adjacency list representation takes:
a) O(n) space
b) O(m) space
c) O (n + m) space
d) O(n^2) space
27. Which algorithm can detect strongly connected components in a directed graph?
a) Prim's algorithm
b) Tarjan’s algorithm
c) Kruskal’s algorithm
d) Bellman-Ford algorithm
28. Which of the following graphs is guaranteed to have at least one Eulerian circuit?
a) A graph where all vertices have even degrees
b) A graph where all vertices have odd degrees
c) Any connected graph
d) A graph where at least one vertex has degree zero
29. In the Bellman-Ford algorithm, how many times are the edges relaxed to find the shortest
paths?
a) |E| times
b) |V| - 1 times
c) |E| - 1 times
d) |V| times
30. What is the best-case time complexity for inserting an edge in an adjacency list
representation of a graph?
a) O(V)
b) O(1)
c) O(E)
d) O (log E)

Subjective Question

1. Define the difference between a directed graph and an undirected graph with
examples.
2. Explain the role of a priority queue in Dijkstra's algorithm.
3. What is the difference between a graph's adjacency list and adjacency matrix
representation?
4. Write the steps involved in the BFS traversal of a graph.
5. Explain the term cycle detection in a graph and name an algorithm for detecting
cycles.
6. What is a minimum spanning tree, and where is it used?
7. Explain the difference between a tree and a graph.
8. Define a cycle in a graph. How can you detect a cycle in a directed graph?
9. What are the applications of graph algorithms in real-world scenarios?
10. Explain the concept of topological sort and its significance.
11. Describe the steps involved in implementing Dijkstra's algorithm.
12. What is the difference between a weighted graph and an unweighted graph?
13. Depth-First Search:
a) Write the pseudocode for Depth-First Search (DFS).
b) Perform DFS traversal on the graph below starting from vertex undirected (a)
directed (1):

14. Dijkstra’s Algorithm:


a) Explain the working of Dijkstra’s algorithm with an example.
b) Compute the shortest path from a given source to all other vertices in the graph:

In Directed Graph the Source is S

In Undirected Graph the Source is a


15. Kruskal’s Algorithm:
a) Describe the steps of Kruskal’s algorithm for finding the Minimum Spanning Tree
(MST).
b) Apply Kruskal’s algorithm to the following graph and find its MST:
16. Implement the Depth-First Search (DFS) algorithm using any programming language
of your choice. Include code and explain the logic.

You might also like