Unit 6: Graphs - Practice Quiz

CSE205 — Data Structures And Algorithms 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 Which data structure is primarily used to implement Breadth-First Search (BFS)?

A. Hash Table
B. Priority Queue
C. Queue
D. Stack

2 Which data structure is primarily used to implement Depth-First Search (DFS)?

A. Queue
B. Linked List
C. Stack
D. Heap

3 What is the time complexity of BFS for a graph represented using an adjacency list with V vertices and E edges?

A. O(V * E)
B. O(V)
C. O(E)
D. O(V + E)

4 What is the time complexity of DFS for a graph represented using an adjacency matrix with V vertices?

A. O(V)
B. O(log V)
C. O(V + E)
D. O(V^2)

5 Which algorithm is best suited for finding the shortest path in an unweighted graph?

A. Kruskal's Algorithm
B. DFS
C. Prim's Algorithm
D. BFS

6 Dijkstra’s Algorithm is based on which algorithmic paradigm?

A. Divide and Conquer
B. Greedy Approach
C. Backtracking
D. Dynamic Programming

7 What is the main limitation of Dijkstra’s Algorithm?

A. It cannot handle cycles.
B. It is slower than Bellman-Ford.
C. It cannot handle negative weight edges.
D. It only works on directed graphs.

8 What is the time complexity of Dijkstra’s Algorithm using a binary heap (priority queue)?

A. O(V log E)
B. O(E log V)
C. O(V^2)
D. O(E + V log V)

9 Which algorithm can detect a negative weight cycle in a graph?

A. Prim's Algorithm
B. Bellman-Ford Algorithm
C. BFS
D. Dijkstra’s Algorithm

10 How many iterations does the Bellman-Ford algorithm run to guarantee shortest paths in a graph with V vertices?

A. V
B. E
C. V + 1
D. V - 1

11 What is the time complexity of the Bellman-Ford algorithm?

A. O(VE)
B. O(V + E)
C. O(V^2)
D. O(E log V)

12 The Floyd Warshall algorithm is used to solve which problem?

A. Minimum Spanning Tree
B. Network Flow
C. Single-Source Shortest Path
D. All-Pairs Shortest Path

13 What is the time complexity of the Floyd Warshall algorithm?

A. O(E^2)
B. O(V^2)
C. O(VE)
D. O(V^3)

14 Floyd Warshall algorithm uses which algorithmic paradigm?

A. Divide and Conquer
B. Branch and Bound
C. Dynamic Programming
D. Greedy Approach

15 In the relaxation step if (d[u] + c(u, v) < d[v]), what does d[v] represent?

A. The number of edges from source to v
B. The current known shortest distance from source to v
C. The shortest distance from u to v
D. The weight of edge (u, v)

16 Which traversal is most appropriate for topological sorting?

A. DFS
B. Floyd Warshall
C. BFS
D. Dijkstra

17 If a graph is disconnected, which traversal will fail to visit all vertices if started from a single source?

A. Both BFS and DFS
B. BFS only
C. DFS only
D. Neither

18 In Dijkstra's algorithm, what is the initial distance value assigned to the source vertex?

A. -1
B. 0
C. Infinity
D. 1

19 What does A[i][j] represent in the final matrix of the Floyd Warshall algorithm?

A. Boolean indicating if i and j are connected
B. Number of edges between i and j
C. Shortest distance from i to j
D. Length of the longest path from i to j

20 Which algorithm is strictly faster for sparse graphs when finding the single-source shortest path with non-negative weights?

A. Matrix Multiplication
B. Floyd Warshall
C. Bellman-Ford
D. Dijkstra (with Heap)

21 During DFS, if we encounter an edge to a vertex that is currently in the recursion stack, what does this indicate?

A. A disconnected component
B. A bridge
C. A cycle
D. A shortest path

22 Bellman-Ford works on which type of graphs?

A. Trees only
B. DAGs only
C. Undirected graphs with positive weights only
D. Directed graphs with negative weights (no negative cycles)

23 What is the space complexity of the Floyd Warshall algorithm?

A. O(V^3)
B. O(V)
C. O(V^2)
D. O(E)

24 Which algorithm calculates the shortest path from a single source to all other vertices?

A. Kruskal's Algorithm
B. Johnson's Algorithm
C. Dijkstra's Algorithm
D. Floyd Warshall

25 In BFS, nodes are visited in an order based on their:

A. Distance from the source
B. Alphabetical order
C. Weight
D. Finish time

26 In the context of Bellman-Ford, what happens if the graph contains a negative weight cycle?

A. The algorithm converts negative weights to positive.
B. The algorithm loops infinitely.
C. The algorithm returns the correct shortest path.
D. The algorithm can report the existence of the cycle.

27 The recurrence relation D[i][j] = min(D[i][j], D[i][k] + D[k][j]) belongs to which algorithm?

A. Floyd Warshall
B. Dijkstra
C. Bellman-Ford
D. DFS

28 Which of the following is an application of DFS?

A. Finding the shortest path in unweighted graphs
B. Broadcasting in a network
C. GPS Navigation systems
D. Solving the maze problem

29 If we use an adjacency matrix to represent a graph for Dijkstra's algorithm, the time complexity becomes:

A. O(E log V)
B. O(E + V)
C. O(V^3)
D. O(V^2)

30 What is the maximum number of edges in a connected undirected graph with V vertices?

A. V
B. V - 1
C. V^2
D. V(V-1)/2

31 Which traversal algorithm uses less memory (space complexity) for a very deep but narrow tree?

A. Bellman-Ford
B. Dijkstra
C. DFS
D. BFS

32 Which of the following algorithms can handle directed graphs with negative edges?

A. Bellman-Ford
B. Dijkstra
C. Prim
D. Kruskal

33 What is the initial state of the distance array in Dijkstra's algorithm for all vertices except the source?

A. 1
B. Infinity
C. Undefined
D. 0

34 In a Dense Graph (where E is close to V^2), which algorithm is generally preferred for Single Source Shortest Path?

A. Bellman-Ford
B. Floyd Warshall
C. Dijkstra using Priority Queue
D. Dijkstra using Array

35 A 'Cross Edge' is a concept encountered in which algorithm?

A. BFS
B. Floyd Warshall
C. DFS
D. Bellman-Ford

36 To reconstruct the shortest path after running Dijkstra’s or Bellman-Ford, what additional information must be stored?

A. The edge weights
B. The degree of nodes
C. The visit time
D. The parent (predecessor) of each node

37 Can Floyd Warshall algorithm detect negative cycles?

A. No, never.
B. Yes, if the total sum of weights is negative.
C. Yes, if a diagonal element distance becomes negative.
D. Only if the graph is undirected.

38 Which algorithm calculates the Transitive Closure of a graph?

A. Bellman-Ford
B. Dijkstra
C. Prim
D. Floyd Warshall

39 In BFS, what are the colors usually associated with nodes during processing?

A. 0, 1, 2
B. Red, Green, Blue
C. True, False, Null
D. White, Gray, Black

40 Dijkstra's algorithm can be implemented efficiently using:

A. Max-Priority Queue
B. Stack
C. Min-Priority Queue
D. Queue

41 If you need to find the shortest path between two specific nodes (u, v), which algorithm is typically stopped early?

A. Dijkstra
B. Kruskal
C. Bellman-Ford
D. Floyd Warshall

42 Which algorithm is capable of handling a graph with cycles?

A. BFS
B. Dijkstra
C. DFS
D. All of the above

43 The process of updating the distance of a vertex v using a neighbor u is called:

A. Initialization
B. Relaxation
C. Exploration
D. Visitation

44 What is the minimum number of edges required to connect a graph with N vertices?

A. N - 1
B. N
C. 0
D. N / 2

45 Which algorithm is most sensitive to the order of edges processed if not using a specific data structure?

A. BFS
B. Bellman-Ford
C. Floyd Warshall
D. None

46 In a graph where edge weights represent probabilities of success, how do we transform the problem to use Shortest Path algorithms?

A. Use 1/weight
B. Use 1 - weight
C. Use -log(weight)
D. Use weight^2

47 Breadth-First Search is equivalent to Level-Order Traversal in which data structure?

A. Tree
B. Graph
C. Array
D. Stack

48 Which graph representation is most space-efficient for sparse graphs?

A. Adjacency List
B. Incidence Matrix
C. Adjacency Matrix
D. 2D Array

49 In the classification of edges in DFS, what is a 'Forward Edge'?

A. An edge from a node to its ancestor
B. The edge connecting parent to child in the DFS tree
C. An edge to a previously visited node in a different branch
D. An edge from a node to a descendant that is not a child

50 Why is Bellman-Ford not preferred over Dijkstra for graphs with non-negative weights?

A. Bellman-Ford is harder to implement
B. Bellman-Ford requires more space
C. Bellman-Ford has a higher time complexity
D. Bellman-Ford gives incorrect results for positive weights