Question 1 
Depth First Search  
Breadth First Search  
Prim's Minimum Spanning Tree Algorithm  
Kruskal' Minimum Spanning Tree Algorithm 
Discuss it
Question 2 
There can be a loop in graph so we must maintain a visited flag for every vertex  
DFS of a graph uses stack, but inorrder traversal of a tree is recursive  
BFS of a graph uses queue, but a time efficient BFS of a tree is recursive.  
All of the above 
Discuss it
Question 3 
1) Breadth First Search 2) Depth First Search 3) Prim's Minimum Spanning Tree 4) Kruskal' Minimum Spanning Tree
1) Stack 2) Queue 3) Priority Queue 4) Union Find  
1) Queue 2) Stack 3) Priority Queue 4) Union Find  
1) Stack 2) Queue 3) Union Find 4) Priority Queue  
1) Priority Queue 2) Queue 3) Stack 4) Union Find 
Discuss it
Question 4 
MNOPQR  
NQMPOR  
QMNPRO  
QMNPOR 
Discuss it
Question 5 
{u,v} must be an edge in G, and u is a descendant of v in T  
{u,v} must be an edge in G, and v is a descendant of u in T  
If {u,v} is not an edge in G then u is a leaf in T  
If {u,v} is not an edge in G then u and v must have the same parent in T

Discuss it
In DFS, if 'v' is visited after 'u', then one of the following is true. 1) (u, v) is an edge. u / \ v w / / \ x y z 2) 'u' is a leaf node. w / \ x v / / \ u y zIn DFS, after visiting a node, we first recur for all unvisited children. If there are no unvisited children (u is leaf), then control goes back to parent and parent then visits next unvisited children.
Question 6 
Among the following sequences
I) a b e g h f
II) a b f e h g
III) a b f h g e
IV) a f g h b e Which are depth first traversals of the above graph? (GATE CS 2003)
I, II and IV only  
I and IV only  
II, III and IV only  
I, III and IV only 
Discuss it
In DFS, if a vertex 'v' is visited after 'u', then one of the following is true. 1) (u, v) is an edge. u / \ v w / / \ x y z 2) 'u' is a leaf node. w / \ x v / / \ u y zIn DFS, after visiting a node, we first recur for all unvisited children. If there are no unvisited children (u is leaf), then control goes back to parent and parent then visits next unvisited children.
Question 7 
Strongly Connected Components  
Topological Sorting  
Breadth First Search  
Dijkstra's Shortest Path 
Discuss it
Question 8 
Only BFS  
Only DFS  
Both BFS and DFS  
Neither BFS nor DFS 
Discuss it
Question 9 
There is an edge from currently being visited node to an already visited node.  
There is an edge from currently being visited node to an ancestor of currently visited node in DFS forest.  
Every node is seen twice in DFS.  
None of the bove 
Discuss it
Question 10 
True  
False 
Discuss it
Question 11 
True  
False 
Discuss it
Question 12 
True  
False 
Discuss it
Question 13 
1 2 3 4 5 6  
1 3 2 4 5 6  
1 3 2 4 6 5  
3 2 4 1 6 5 
Discuss it
Question 14 
O(n)  
O(m+n)  
O(n^{2})  
O(mn) 
Discuss it
Question 15 
the shortest path between every pair of vertices.  
the shortest path from W to every vertex in the graph.  
the shortest paths from W to only those nodes that are leaves of T.  
the longest path in the graph 
Discuss it
Question 16 
17  
18  
19  
20 
Discuss it
Question 17 
There must exist a vertex w adjacent to both u and n in G  
There must exist a vertex w whose removal disconnects u and n in G  
There must exist a cycle in G containing u and n  
There must exist a cycle in G containing u and all its neighbours in G. 
Discuss it
Question 18 
{u,v} must be an edge in G, and u is a descendant of v in T  
{u,v} must be an edge in G, and v is a descendant of u in T  
If {u,v} is not an edge in G then u is a leaf in T  
If {u,v} is not an edge in G then u and v must have the same parent in T 
Discuss it
In DFS, if 'v' is visited after 'u', then one of the following is true. 1) (u, v) is an edge. u / \ v w / / \ x y z 2) 'u' is a leaf node. w / \ x v / / \ u y zIn DFS, after visiting a node, we first recur for all unvisited children. If there are no unvisited children (u is leaf), then control goes back to parent and parent then visits next unvisited children.
Question 19 
k  
k + 1  
n  k  1  
n  k 
Discuss it
Question 20 
1  
2  
4  
6 
Discuss it
abcdef adebcf abdcef adbcef abdecf adbecf
Question 21 
Θ(n^{2})  
Θ(m+n)  
Θ(m^{2})  
Θ(n^{4}) 
Discuss it
Since memory is not a constraint here, first we will create a data structure for storing the address of adjacency entries for each adjacency list. For faster retrieval we will create a 2D array of pointers of size (n2) which will point to adjacency entries in the graph. If there is an edge between u and v, then our data structure A[u][v] contains the address of the adjacency entry of v in the adjacency list of u. Otherwise it can be NULL. For more clear picture, refer to the image given below.
This can be done in O(m+n) time as only one traversal of G is required to create A. Now We will change the dfs algorithm to to set the twin pointer in each entry in each adjacency list.
Algorithm : If we are currently at the vertex v in the dfs function, we can change the loop of traversing all the adjacency entries in the adjacency list of v as follows :
For each node in adj_list[v]:
{
if(visited[node.value] != 0)
{
call_to_dfs(node.value)
}
if(node.twin == NULL){
node.twin = A[node.value][v] //Setting the twin pointers in both the entries
A[node.value][v].twin = A[v][node.value]
}
}
We are assuming that there is a twin field in the struct defined for representing adjacency entries in the Graph. Total time complexity = O(m+n).
Related link: http://www.geeksforgeeks.org/depthfirsttraversalforagraph/
This solution is contributed by Pranjul Ahuja.