Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
Which data structure is primarily used to implement Breadth-First Search (BFS)?
Not quite. Try another option.
Answer: Queue
BFS explores the neighbor nodes first before moving to the next level neighbors, which follows the First-In-First-Out (FIFO) principle handled by a Queue.
Question 2 of 50
Which data structure is primarily used to implement Depth-First Search (DFS)?
Not quite. Try another option.
Answer: Stack
DFS explores as far as possible along each branch before backtracking, which follows the Last-In-First-Out (LIFO) principle handled by a Stack (or recursion stack).
Question 3 of 50
What is the time complexity of BFS for a graph represented using an adjacency list with V vertices and E edges?
Not quite. Try another option.
Answer: O(V + E)
In BFS using an adjacency list, every vertex is enqueued once and every edge is inspected once, resulting in O(V + E).
Question 4 of 50
What is the time complexity of DFS for a graph represented using an adjacency matrix with V vertices?
Not quite. Try another option.
Answer: O(V^2)
With an adjacency matrix, finding the neighbors of the current vertex requires checking all V entries in the row, leading to O(V^2) total time.
Question 5 of 50
Which algorithm is best suited for finding the shortest path in an unweighted graph?
Not quite. Try another option.
Answer: BFS
BFS explores nodes level by level. In an unweighted graph, the first time a node is reached during BFS, it is via the shortest path.
Question 6 of 50
Dijkstra’s Algorithm is based on which algorithmic paradigm?
Not quite. Try another option.
Answer: Greedy Approach
Dijkstra's algorithm makes a locally optimal choice at each step (selecting the unvisited node with the smallest tentative distance) to find the global optimum.
Question 7 of 50
What is the main limitation of Dijkstra’s Algorithm?
Not quite. Try another option.
Answer: It cannot handle negative weight edges.
Dijkstra’s algorithm assumes that once a node is processed, its distance is final. Negative edges can contradict this assumption by providing a shorter path later.
Question 8 of 50
What is the time complexity of Dijkstra’s Algorithm using a binary heap (priority queue)?
Not quite. Try another option.
Answer: O(E log V)
With a binary heap, extracting the minimum takes O(log V) and is done V times. Decreasing the key takes O(log V) and can occur E times. Often simplified to O(E log V) or O((E+V)log V).
Question 9 of 50
Which algorithm can detect a negative weight cycle in a graph?
Not quite. Try another option.
Answer: Bellman-Ford Algorithm
Bellman-Ford can detect negative cycles if, after V-1 iterations, a further relaxation step can still reduce the distance to a vertex.
Question 10 of 50
How many iterations does the Bellman-Ford algorithm run to guarantee shortest paths in a graph with V vertices?
Not quite. Try another option.
Answer: V - 1
In a graph with V vertices, the longest simple path can have at most V-1 edges. Therefore, V-1 iterations are sufficient to propagate weights.
Question 11 of 50
What is the time complexity of the Bellman-Ford algorithm?
Not quite. Try another option.
Answer: O(VE)
The algorithm iterates V-1 times, and in each iteration, it relaxes all E edges. Thus, the complexity is O(VE).
Question 12 of 50
The Floyd Warshall algorithm is used to solve which problem?
Not quite. Try another option.
Answer: All-Pairs Shortest Path
Floyd Warshall computes the shortest paths between every pair of vertices in the graph.
Question 13 of 50
What is the time complexity of the Floyd Warshall algorithm?
Not quite. Try another option.
Answer: O(V^3)
The algorithm uses three nested loops (source, destination, and intermediate node), each iterating up to V times.
Question 14 of 50
Floyd Warshall algorithm uses which algorithmic paradigm?
Not quite. Try another option.
Answer: Dynamic Programming
It builds the solution by considering intermediate vertices incrementally, using previously computed shortest paths.
Question 15 of 50
In the relaxation step if (d[u] + c(u, v) < d[v]), what does d[v] represent?
Not quite. Try another option.
Answer: The current known shortest distance from source to v
d[v] stores the tentative shortest distance found so far from the source vertex to vertex v.
Question 16 of 50
Which traversal is most appropriate for topological sorting?
Not quite. Try another option.
Answer: DFS
Topological sorting is typically implemented using DFS by pushing a node to a stack only after all its adjacent nodes have been visited.
Question 17 of 50
If a graph is disconnected, which traversal will fail to visit all vertices if started from a single source?
Not quite. Try another option.
Answer: Both BFS and DFS
Standard BFS and DFS only traverse the component containing the source node. To visit all vertices in a disconnected graph, an outer loop iterating over all vertices is required.
Question 18 of 50
In Dijkstra's algorithm, what is the initial distance value assigned to the source vertex?
Not quite. Try another option.
Answer: 0
The distance from the source to itself is always 0.
Question 19 of 50
What does A[i][j] represent in the final matrix of the Floyd Warshall algorithm?
Not quite. Try another option.
Answer: Shortest distance from i to j
The final matrix contains the weight of the shortest path between every pair of vertices (i, j).
Question 20 of 50
Which algorithm is strictly faster for sparse graphs when finding the single-source shortest path with non-negative weights?
Not quite. Try another option.
Answer: Dijkstra (with Heap)
Dijkstra is O(E log V). For sparse graphs (E ~ V), this is much faster than Bellman-Ford (O(VE)) or Floyd Warshall (O(V^3)).
Question 21 of 50
During DFS, if we encounter an edge to a vertex that is currently in the recursion stack, what does this indicate?
Not quite. Try another option.
Answer: A cycle
An edge pointing back to an ancestor in the DFS tree (a node currently in the recursion stack) is called a back-edge and indicates a cycle.
Question 22 of 50
Bellman-Ford works on which type of graphs?
Not quite. Try another option.
Answer: Directed graphs with negative weights (no negative cycles)
Bellman-Ford is specifically designed to handle directed graphs that may contain negative weight edges, provided there are no negative weight cycles.
Question 23 of 50
What is the space complexity of the Floyd Warshall algorithm?
Not quite. Try another option.
Answer: O(V^2)
It requires a 2D matrix of size V x V to store the distances between all pairs.
Question 24 of 50
Which algorithm calculates the shortest path from a single source to all other vertices?
Not quite. Try another option.
Answer: Dijkstra's Algorithm
Dijkstra's (and Bellman-Ford) are Single-Source Shortest Path algorithms. Floyd Warshall is All-Pairs.
Question 25 of 50
In BFS, nodes are visited in an order based on their:
Not quite. Try another option.
Answer: Distance from the source
BFS visits nodes layer by layer, which corresponds to their unweighted distance (number of edges) from the source.
Question 26 of 50
In the context of Bellman-Ford, what happens if the graph contains a negative weight cycle?
Not quite. Try another option.
Answer: The algorithm can report the existence of the cycle.
Bellman-Ford can detect the cycle by performing one extra relaxation pass after the (V-1)th iteration. If distances change, a negative cycle exists.
Question 27 of 50
The recurrence relation D[i][j] = min(D[i][j], D[i][k] + D[k][j]) belongs to which algorithm?
Not quite. Try another option.
Answer: Floyd Warshall
This logic checks if going from i to j via intermediate node k is cheaper than the direct path (or previously calculated path) from i to j.
Question 28 of 50
Which of the following is an application of DFS?
Not quite. Try another option.
Answer: Solving the maze problem
DFS is ideal for maze solving as it explores one path deeply before backtracking, effectively simulating a strategy of 'keep going until you hit a wall'.
Question 29 of 50
If we use an adjacency matrix to represent a graph for Dijkstra's algorithm, the time complexity becomes:
Not quite. Try another option.
Answer: O(V^2)
Without a priority queue (using a linear search for the min distance node), Dijkstra takes O(V^2), which is actually better for dense graphs (where E ~ V^2).
Question 30 of 50
What is the maximum number of edges in a connected undirected graph with V vertices?
Not quite. Try another option.
Answer: V(V-1)/2
In a complete undirected graph, every vertex is connected to every other vertex.
Question 31 of 50
Which traversal algorithm uses less memory (space complexity) for a very deep but narrow tree?
Not quite. Try another option.
Answer: BFS
BFS must store all nodes at the current level in the queue, which can be up to V/2 in the worst case. DFS only stores the current path.
Question 32 of 50
Which of the following algorithms can handle directed graphs with negative edges?
Not quite. Try another option.
Answer: Bellman-Ford
Bellman-Ford is specifically capable of handling negative weights, unlike Dijkstra or the MST algorithms.
Question 33 of 50
What is the initial state of the distance array in Dijkstra's algorithm for all vertices except the source?
Not quite. Try another option.
Answer: Infinity
All nodes are initialized to Infinity to represent that they are currently unreachable, except the source which is 0.
Question 34 of 50
In a Dense Graph (where E is close to V^2), which algorithm is generally preferred for Single Source Shortest Path?
Not quite. Try another option.
Answer: Dijkstra using Array
Using an array (linear search) gives O(V^2). Using a binary heap gives O(E log V) which becomes O(V^2 log V) in a dense graph. O(V^2) is better.
Question 35 of 50
A 'Cross Edge' is a concept encountered in which algorithm?
Not quite. Try another option.
Answer: DFS
In DFS classification of edges, a cross edge connects two nodes where neither is an ancestor of the other in the DFS tree.
Question 36 of 50
To reconstruct the shortest path after running Dijkstra’s or Bellman-Ford, what additional information must be stored?
Not quite. Try another option.
Answer: The parent (predecessor) of each node
By storing the predecessor node that successfully relaxed the distance, one can backtrack from the destination to the source to find the path.
Question 37 of 50
Can Floyd Warshall algorithm detect negative cycles?
Not quite. Try another option.
Answer: Yes, if a diagonal element distance becomes negative.
Normally the distance from a node to itself is 0. If dist[i][i] becomes negative, it implies a path from i to i with negative total weight (a cycle).
Question 38 of 50
Which algorithm calculates the Transitive Closure of a graph?
Not quite. Try another option.
Answer: Floyd Warshall
Floyd Warshall can be adapted to find the transitive closure (reachability) by using boolean AND/OR operations instead of min/add.
Question 39 of 50
In BFS, what are the colors usually associated with nodes during processing?
Not quite. Try another option.
Answer: White, Gray, Black
Standard CLRS notation uses White (unvisited), Gray (visiting/in queue), and Black (visited/processed).
Question 40 of 50
Dijkstra's algorithm can be implemented efficiently using:
Not quite. Try another option.
Answer: Min-Priority Queue
A Min-Priority Queue efficiently retrieves the vertex with the smallest tentative distance.
Question 41 of 50
If you need to find the shortest path between two specific nodes (u, v), which algorithm is typically stopped early?
Not quite. Try another option.
Answer: Dijkstra
Dijkstra's algorithm can be terminated as soon as the destination node v is extracted from the priority queue.
Question 42 of 50
Which algorithm is capable of handling a graph with cycles?
Not quite. Try another option.
Answer: All of the above
All these algorithms utilize a mechanism (like a visited array or distance check) to handle cycles and prevent infinite loops.
Question 43 of 50
The process of updating the distance of a vertex v using a neighbor u is called:
Not quite. Try another option.
Answer: Relaxation
Relaxation is the step where we check if a path through u offers a shorter route to v than the currently known path.
Question 44 of 50
What is the minimum number of edges required to connect a graph with N vertices?
Not quite. Try another option.
Answer: N - 1
A tree is a minimally connected graph, and a tree with N vertices has N-1 edges.
Question 45 of 50
Which algorithm is most sensitive to the order of edges processed if not using a specific data structure?
Not quite. Try another option.
Answer: Bellman-Ford
While the final result is the same, the speed of convergence in Bellman-Ford can vary depending on the order edges are relaxed, though the worst-case complexity remains O(VE).
Question 46 of 50
In a graph where edge weights represent probabilities of success, how do we transform the problem to use Shortest Path algorithms?
Not quite. Try another option.
Answer: Use -log(weight)
To maximize product of probabilities (P1 * P2...), we minimize sum of negative logs (-log(P1) + -log(P2)...).
Question 47 of 50
Breadth-First Search is equivalent to Level-Order Traversal in which data structure?
Not quite. Try another option.
Answer: Tree
BFS on a tree starting from the root visits nodes level by level, exactly like Level-Order Traversal.
Question 48 of 50
Which graph representation is most space-efficient for sparse graphs?
Not quite. Try another option.
Answer: Adjacency List
Adjacency List uses O(V + E) space, whereas Adjacency Matrix uses O(V^2). For sparse graphs (E << V^2), the list is much smaller.
Question 49 of 50
In the classification of edges in DFS, what is a 'Forward Edge'?
Not quite. Try another option.
Answer: An edge from a node to a descendant that is not a child
A forward edge connects a vertex to one of its descendants in the DFS tree (skipping levels).
Question 50 of 50
Why is Bellman-Ford not preferred over Dijkstra for graphs with non-negative weights?
Not quite. Try another option.
Answer: Bellman-Ford has a higher time complexity
Bellman-Ford is O(VE) while Dijkstra is O(E log V). For most graphs, Dijkstra is significantly faster.
That's unit 6
Answer a few questions and your score shows up here.
Nearly through. Did unit 6 of CSE205 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 6 of CSE205 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.