Graphs
Graphs
How many strongly connected components are there in the above graph?
Answer is 5. A directed graph is strongly connected if there is a path between all pair of
vertices.
The strongly components are:
1. A-B-F-C
2. E
3. D
4. G
5. H
so totally 5
Q2: Consider a complete undirected graph with vertex set {0, 1, 2, 3, 4}. Entry Wij in the
matrix W below is the weight of the edge {i, j}. Answer the 1 and 2
0 1 8 1 4
1 0 12 4 9
8 12 0 7 3
1 4 7 0 2
4 9 3 2 0
2. The time complexity to calculate the number of edges in this graph whose
information in stored in form of the above adjacency matrix is ____________
a) O(V)
b) O(E2)
c) O(E)
d) O(V2)
Q3: For the adjacency matrix of a directed graph the row sum is the _________ degree
and the column sum is the ________ degree.
a) in, out
b) out, in
c) in, total
d) total, out
Answer: b
Explanation: Row number of the matrix represents the tail, while Column number
represents the head of the edge.
1. Draw a picture of the directed graph that has the above adjacency list
representation.
A B C D
A 0 1 1 1
B 1 0 0 0
C 0 1 0 1
D 0 0 0 0
Q6: How many minimum spanning trees are possible using Kruskal’s algorithm for a given
graph –
• If all edges weight are distinct, minimum spanning tree is unique.
• If two edges have same weight, then we have to consider both possibilities and find
possible minimum spanning trees.
Q7: The number of elements in the adjacency matrix of a graph having 7 vertices is
__________
a) 7
b) 14
c) 36
d) 49
Q8: Given an adjacency matrix A = [ [0, 1, 1], [1, 0, 1], [1, 1, 0] ], how many ways are
there in which a vertex can walk to itself using 2 edges.
a) 2
b) 4
c) 6
d) 8
Q9: If A[x+3][y+5] represents an adjacency matrix, which of these could be the value of
x and y.
a) x=5, y=3
b) x=3, y=5
c) x=3, y=3
d) x=5, y=5
Q10: For a given graph G having v vertices and e edges which is connected and has no
cycles, which of the following statements is true?
a) v=e
b) v = e+1
c) v + 1 = e
d) None of the mentioned
Q11: Suppose you have a directed graph representing all the flights that an airline flies.
What algorithm might be used to find the best sequence of connections from one city to
another?
Q12: What graph traversal algorithm uses a queue to keep track of vertices which need to
be processed?
• A. Breadth-first search.
• B. Depth-first search