Unit 6 - Practice Quiz

CSE205

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

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

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

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

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)
B. O(E)
C. O(V + 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(V^2)
C. O(V + E)
D. O(log V)

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

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

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

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

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

A. It cannot handle cycles.
B. It cannot handle negative weight edges.
C. It is slower than Bellman-Ford.
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^2)
B. O(E + V log V)
C. O(E log V)
D. O(V log E)

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

A. Dijkstra’s Algorithm
B. BFS
C. Bellman-Ford Algorithm
D. Prim'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. V - 1
C. V + 1
D. E

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

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

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

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

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

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

14 Floyd Warshall algorithm uses which algorithmic paradigm?

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

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

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

16 Which traversal is most appropriate for topological sorting?

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

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

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

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

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

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

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

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

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

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

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

22 Bellman-Ford works on which type of graphs?

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

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

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

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

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

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

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

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

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

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

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

28 Which of the following is an application of DFS?

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

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

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

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

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

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

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

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

A. Dijkstra
B. Bellman-Ford
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.
B. 1
C. Infinity
D. Undefined

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

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

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

A. BFS
B. DFS
C. Floyd Warshall
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 parent (predecessor) of each node
C. The visit time
D. The degree of nodes

37 Can Floyd Warshall algorithm detect negative cycles?

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

38 Which algorithm calculates the Transitive Closure of a graph?

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

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

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

40 Dijkstra's algorithm can be implemented efficiently using:

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

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

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

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

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

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

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

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

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

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

A. Bellman-Ford
B. Floyd Warshall
C. BFS
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 -log(weight)
C. Use weight^2
D. Use 1 - weight

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

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

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

A. Adjacency Matrix
B. Adjacency List
C. Incidence 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. An edge from a node to a descendant that is not a child
C. An edge to a previously visited node in a different branch
D. The edge connecting parent to child in the DFS tree

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