You are on page 1of 4

1.

Which of the following algorithms can be used to most efficiently determine the presence
of a cycle in a given graph?
A.
B.
C.
D.

Depth First Search.


Breadth First Search.
Prim's Minimum Spanning Tree Algorithm.
Kruskal' Minimum Spanning Tree Algorithm.

2. Traversal of a graph is different from tree because


A.
B.
C.
D.

There can be a loop in graph so we must maintain a visited flag for every vertex.
DFS of a graph uses stack, but in order 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.

3. The Breadth First Search algorithm has been implemented using the queue data structure.
One possible order of visiting the nodes of the following graph is

A.
B.
C.
D.

MNOPQR
NQMPOR
QMNPRO
QMNPOR

4. Let G be an undirected graph. Consider a depth-first traversal of G, and let T be the


resulting depth-first search tree. Let u be a vertex in G and let v be the first new

(unvisited) vertex visited after visiting u in the traversal. Which of the following
statements is always true?

A.
B.
C.
D.

{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.

5. Given two vertices in a graph s and t, which of the two traversals (BFS and DFS) can be
used to find if there is path from s to t?
A.
B.
C.
D.

Only BFS
Only DFS
Both BFS and DFS
Neither BFS nor DFS

6. Which of the following is an advantage of adjacency list representation over adjacency


matrix representation of a graph?
A. In adjacency list representation, space is saved for sparse graphs.
B. DFS and BSF can be done in O (V + E) time for adjacency list representation. These
operations take O (V^2) time in adjacency list representation. Here is V and E is
number of vertices and edges respectively.
C. Adding a vertex in adjacency list representation is easier than adjacency matrix
representation.
D. All of the above.
7. Suppose we run Dijkstras single source shortest-path algorithm on the following edge
weighted directed graph with vertex P as the source. In what order do the nodes get
included into the set of vertices for which the shortest path distances are finalized?

A.
B.
C.
D.

P, Q, R, S, T, U.
P, Q, R, U, S, T.
P, Q, R, U, T, S.
P, Q, T, R, U, S.

8. Which of the following algorithm can be used to efficiently calculate single source
shortest paths in a Directed Acyclic Graph?
A.
B.
C.
D.

Dijkstra.
Bellman-Ford.
Topological Sort.
Strongly Connected Component.

9. Given a directed graph where weight of every edge is same, we can


efficiently find shortest path from a given source to destination using?
A. Breadth First Traversal.
B. Dijkstra's Shortest Path Algorithm.
C. Neither Breadth First Traversal nor Dijkstra's algorithm can be used.
D. Depth First Search.
10. Let G (V, E) an undirected graph with positive edge weights. Dijkstra's single-source
shortest path algorithm can be implemented using the binary heap data structure with
time complexity:
A.
B.
C.
D.

O(| V |2)
O (| E | + | V | log | V |)

O (| V | log | V |)
O ((| E | + | V |) log | V |)

Answers.
1. A
2. D
3. C
4. C
5. C
6. D
7. B
8. C
9. A
10. D

You might also like