wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Graph

Total questions: 64

Worksheet time: 44mins

Name
Class
Date
1.

In a simple graph, the number of edges is equal to twice the sum of the degrees of the vertices.

a)

True

b)

False

2.

A connected graph T without any cycles is called .......

a)

Free graph

b)

no cycle graph

c)

non cycle graph

d)

circular graph

3.

A graph is said to be (a)   if every node u in G is adjacent to every other node v in G.

4.

What would be the DFS traversal of the given Graph?

a)

ABCDE

b)

AEDCB

c)

EDCBA

d)

ADECB

5.

The topological sorting of any DAG can be done in ________ time

a)

cubic

b)

quadratic

c)

linear

d)

logarithmic

6.

What sequence would the BFS traversal of the given graph yield?

a)

A F D B C E

b)

C B A F D

c)

A B D C F

d)

A B C D E F

7.

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 matrix representation. Here is V and E are 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

8.

Which of the following statements is/are TRUE for an undirected graph?

P: Number of odd degree vertices is even

Q: Sum of degrees of all vertices is even

a)

P Only

b)

Q Only

c)

Both P and Q

d)

Neither P nor Q

9.

Which of the following is true?

a)

Prim’s algorithm initialises with a vertex

b)

Prim’s algorithm initialises with a edge

c)

Prim’s algorithm initialises with a vertex which has smallest edge

d)

Prim’s algorithm initialises with a forest

10.

Consider the given graph. What is the weight of the minimum spanning tree using the Prim’s algorithm, starting from vertex a?

a)

23

b)

28

c)

27

d)

11

11.

Prim’s algorithm is a ______

a)

Divide and conquer algorithm

b)

Greedy algorithm

c)

Dynamic Programming

d)

Approximation algorithm

12.

Consider the graph shown below. Which of the following edges form the MST of the given graph using Prim’s algorithm, starting from vertex 4.

a)

(4-3)(5-3)(2-3)(1-2)

b)

(4-3)(3-5)(5-1)(1-2)

c)

(4-3)(3-5)(5-2)(1-5)

d)

(4-3)(3-2)(2-1)(1-5)

13.

What is the time complexity of Dijikstra’s algorithm?

a)

O(N)

b)

O(N3)

c)

O(N2)

d)

O(logN)

14.

Dijkstra’s Algorithm cannot be applied on ______________

a)

Directed and weighted graphs

b)

Graphs having negative weight function

c)

Unweighted graphs

d)

Undirected and unweighted graphs

15.

Consider the following graph. If b is the source vertex, what is the minimum cost to reach f vertex?

a)

8

b)

9

c)

4

d)

6

16.

In the given graph, identify the shortest path having minimum cost to reach vertex E if A is the source vertex.

a)

a-b-e

b)

a-c-e

c)

a-c-d-e

d)

a-c-d-b-e

17.

The Data structure used in standard implementation of Breadth First Search is?

a)

Stack

b)

Queue

c)

Linked List

d)

Tree

18.

A person wants to visit some places. He starts from a vertex and then wants to visit every place connected to this vertex and so on. What algorithm he should use?

a)

Depth First Search

b)

Breadth First Search

c)

Trim’s algorithm

d)

Kruskal’s algorithm

19.

Which of the following is not an application of Breadth First Search?

a)

Finding shortest path between two nodes

b)

Finding bipartiteness of a graph

c)

GPS navigation system

d)

Path Finding

20.

What are the appropriate data structures for following algorithms?

1) Breadth First Search                      

    2) Depth First Search                           

3) Prim's Minimum Spanning Tree

4) Kruskal' Minimum Spanning Tree

a)

1) Stack

2) Queue

3) Priority Queue 4) Union Find

b)

1) Queue

2) Stack

3) Priority Queue 4) Union Find

c)

1) Stack

2) Queue

3) Union Find

4) Priority Queue

d)

1) Priority Queue 2) Queue

3) Stack

4) Union Find

21.

A complete, undirected, weighted graph GGG is defined on vertices {0,1,2,…,n−1}\{0,1,2,\dots,n-1\}{0,1,2,…,n−1}.

Find the structure of the Minimum Spanning Tree (MST) in the following cases:

(a) Weight of edge (u,v)=∣u−v∣(u,v) = |u - v|(u,v)=∣u−v∣

(b) Weight of edge (u,v)=u+v(u,v) = u + v(u,v)=u+v

a)

(a) Star centered at 0
(b) Path: 0−1−2−⋯−(n−1)0 - 1 - 2 - \cdots - (n-1)0−1−2−⋯−(n−1)

b)

(a) Path: 0−1−2−⋯−(n−1)0 - 1 - 2 - \cdots - (n-1)0−1−2−⋯−(n−1)
(b) Star centered at 0

c)

(a) Complete graph
(b) Path: 0−1−2−⋯−(n−1)0 - 1 - 2 - \cdots - (n-1)0−1−2−⋯−(n−1)

d)

(a) Star centered at n−1n-1n−1
(b) Star centered at 1

22.

We are interested in the shortest paths from A. Output the sequence of vertices identified by the Dijkstra’s algorithm for single source shortest path when the algorithm is started at node A.

(a)  

23.

Let G be the directed, weighted graph shown in below figure graph. We are interested in the shortest paths from A. (q) Write down sequence of vertices in the shortest path from A to F. (b) What is the cost of the shortest path from A to E?

(a)  

24.

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 matrix representation. Here is V and E are 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

25.

In the following graph, discovery time stamps and finishing time stamps of Depth First Search (DFS) are shown as x/y, where x is discovery time stamp and y is finishing time stamp.
It shows which of the following depth first forest?

a)

{a, b, e} {c, d, f, g, h}

b)

{a, b, e} {c, d, h} {f, g}

c)

{a, b, e} {f, g} {c, d} {h}

d)

{a, b, c, d} {e, f, g} {h}

26.

Consider a segment tree built on an array of N elements. What is the minimum number of node updates required to rebuild the entire tree if the original array is reversed?

a)

n

b)

n-1

c)

2n-1

d)

nlogn

27.

In an undirected connected planar graph G, there are eight vertices and five faces. The number of edges in G is _________.

a)

10

b)

11

c)

12

d)

6

28.

Consider the following undirected graph with edge weights as shown:
The number of minimum-weight spanning trees of the graph is ___________.

a)

3

b)

4

c)

5

d)

2

29.

The cyclomatic complexity of the flow graph of a program provides  

a)

an upper bound for the number of tests that must be conducted to ensure that all statements have been executed at most once

b)

a lower bound for the number of tests that must be conducted to ensure that all statements have been executed at most once

c)

an upper bound for the number of tests that must be conducted to ensure that all statements have been executed at least once

d)

a lower bound for the number of tests that must be conducted to ensure that all statements have been executed at least once

30.

What is the largest integer m such that every simple connected graph with n vertices and n edges contains at least m different spanning trees?

a)

1

b)

2

c)

3

d)

n

31.

Which of the following data structure is useful in traversing a given graph by depth first search?

a)

Stack

b)

List

c)

Queue

d)

None

32.

What is the worst case efficiency for a path compression algorithm?

a)

O(M log N)

b)

O(N log N)

c)

O(log N)

d)

O(N)

33.

Let G be a weighted undirected graph and e be an edge with maximum weight in G. Suppose there is a minimum weight spanning tree in G containing the edge e. Which of the following statements is always TRUE?  

a)

There exists a cutset in G having all edges of maximum weight.

b)

There exists a cycle in G having all edges of maximum weight

c)

Edge e cannot be contained in a cycle.

d)

All edges in G have the same weight

34.

What is the maximum number of edges in an acyclic undirected graph with n vertices?

a)

n-1

b)

n

c)

n+1

d)

2n-1

35.

The most efficient algorithm for finding the number of connected components in an undirected graph on n vertices and m edges has time complexity.

a)

theta(n)

b)

theta(m)

c)

theta(m+n)

d)

theta(mn)

36.

Consider an undirected unweighted graph G. Let a breadth-first traversal of G be done starting from a node r. Let d(r, u) and d(r, v) be the lengths of the shortest paths from r to u and v respectively, in G. lf u is visited before v during the breadth-first traversal, which of the following statements is correct?

a)


d(r, u) < d (r, v)

b)

d(r, u) > d(r, v)

c)

d(r, u) <= d (r, v)

d)

none

37.

How many undirected graphs (not necessarily connected) can be constructed out of a given set V= {V 1, V 2,…V n} of n vertices ?

a)

n(n-l)/2

b)

2^n

c)

n!

d)


2^(n(n-1)/2)

38.

Which of the following statements is/are TRUE for an undirected graph? 

P: The number of odd-degree vertices is even 

Q: Sum of degrees of all vertices is even

a)

P Only

b)

Q Only

c)

Both P and Q

d)

Neither P and Q

39.

Consider an undirected random graph of eight vertices. The probability that there is an edge between a pair of vertices is 1/2. What is the expected number of unordered cycles of length three?

a)

1/8

b)

1

c)

7

d)

8

40.

In which scenario would a directed acyclic graph (DAG) be most suitable?

a)

Representing dependencies between tasks in a project schedule

b)

Modeling a social network with friend connections

c)

Finding the shortest path between two nodes in a weighted graph

d)

Performing breadth-first search (BFS) on a graph

41.

How many undirected graphs (not necessarily connected) can be constructed out of a given set V = {v1, v2, ... vn} of n vertices?

a)

n(n-1)/2

b)


2n

c)

n!

d)


2n(n-1)/2

42.

A sink in a directed graph is a vertex i such that there is an edge from every vertex j ≠ i to i and there is no edge from i to any other vertex. A directed graph G with n vertices is represented by its adjacency matrix A, where A[i] [j] = 1 if there is an edge directed from vertex i to j and 0 otherwise. The following algorithm determines whether there is a sink in the graph G. Choose the correct expressions for E3  

a)


(A[i][j] && !A[j][i])

b)

(!A[i][j] && A[j][i])

c)


(!A[i][j] | |  A[j][i])

d)


(A[i][j] | | !A[j][i])

43.

For the undirected, weighted graph given below, which of the following sequences of edges represents a correct execution of Prim's algorithm to construct a Minimum Span­ning Tree?

a)

(a, b), (d, f), (f, c), (g, i), (d, a), (g, h), (c, e), (f, h)

b)

(c, e), (c, f), (f, d), (d, a), (a, b), (g, h), (h, f), (g, i)

c)

(d, f), (f, c), (d, a), (a, b), (c, e), (f, h), (g, h), (g, i)

d)


(h, g), (g, i), (h, f), (f, c), (f, d), (d, a), (a, b), (c, e)

44.

Consider a directed graph with n vertices and m edges such that all edges have same edge weights. Find the complexity of the best known algorithm to compute the minimum spanning tree of the graph?

a)

O(m+n)

b)

O(m logn)

c)


O(mn)

d)

O(n logm)

45.

You are given a graph containing n vertices and m edges and given that the graph doesn’t contain cycle of odd length. Time Complexity of the best known algorithm to find out whether the graph is bipartite or not is ?

a)

O(m+n)

b)

O(1)

c)

O(mn)

d)


O(n2)

46.

Let G be a simple graph with 20 vertices and 8 components. If we delete a vertex in G, then number of components in G should lie between ____.

a)


8 and 20

b)

8 and 19

c)

7 and 19

d)

7 and 20

47.

Let G be the graph with 100 vertices numbered 1 to 100. Two vertices i and j are adjacent if |i−j|=8 or |i−j|=12. The number of connected components in G is

a)

8

b)

4

c)

12

d)

25

48.

What is the primary difference between a directed graph and a undirected graph?

a)

A directed graph has nodes with unique identifiers, while an undirected graph does not.

b)

A directed graph has edges with direction, while an undirected graph does not.

c)

There is no difference between them.

d)


A directed graph has nodes with unique identifiers, while an undirected graph does not.

49.

In a graph of n nodes and n edges, how many cycles will be present?

a)

Exactly 1

b)

At most 1

c)

At most 2

d)

Depend on graph

50.

Why is the state graph for tic-tac-toe a directed graph rather than an undirected graph

a)

Once a move is made, it cannot be unmade.

b)

There is an odd number of vertices.

c)

There is an odd number of edges

d)

There is more than one player in the game.

51.

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?

a)
  • Breadth first search.

b)
  • Depth first search.

c)
  • A cycle-finding algorithm.

d)
  • A shortest-path algorithm.

52.
  1. If G is an directed graph with 20 vertices, how many boolean values will be needed to represent G using an adjacency matrix?


a)

20

b)

40

c)

200

d)

400

53.
  1. How many linked lists are used to represent a graph with n nodes and m edges, when using an edge list representation,

a)

m

b)

n

c)

m+n

d)

mn

54.

How are loops represented in an edge-list representation of a graph?

a)
  • A vertex will be on its own edge-list.

b)
  • The edge-list will be a circular linked list.

c)
  • The edge-list will be empty for that particular vertex.

d)
  • The edge-list will be full for that particular vertex.

55.

What is the expected number of operations needed to loop through all the edges terminating at a particular vertex given an adjacency matrix representation of the graph? (Assume n vertices are in the graph and m edges terminate at the desired node.)

a)
  • O(m)

b)
  • O(n)

c)
  • O(m²)

d)
  • O(n²)

56.

For the figure as below, which edge does not occur in the depth first spanning tree resulting from depth first search starting at node B:

a)

F → E

b)

E → C

c)

C → G

d)

C → F

57.

The set of all edges generated by DFS tree starting at node B is:

a)

B A D C G F E

b)

A D

c)

B A C D G F E

d)

Cannot be generated

58.

The set of all edges generated by BFS tree starting at node B is:

a)

B A D C G F E

b)

A D

c)

B A C D G F E

d)

Cannot be generated

59.

Which of the following statements is/are true?
I. Adjacency list representation is better for sparse graph than adjacency matrix representation.
II. Finding whether there is an edge between any two node s in a graph is easier in Adjacency list representation.
III. Adding a vertex in adjacency list representation is easier than adjacency Matrix representation.

a)

I only

b)

I & III only

c)

II & III only

d)

I, II & III

60.

An undirected graph G has n nodes. Its adjacency matrix is given by an nxn square matrix whose (I) diagonal elements are ‘0’s (II) Non-diagonal elements are ‘1’s. Which one of the following is True?

a)

Graph G has no minimum spanning tree (MST)

b)

Graph G has unique MST’s each of cost n–1

c)

Graph G has multiple distinct MST’s each of cost n–1

d)

Graph G has multiple spanning trees of different costs

61.

How many distinct spanning trees do exist in an undirected cycle graph of n vertices?

a)

n

b)

n+1

c)

n–1

d)

n+2

62.

If every node in a graph ‘G’ is adjacent to equal number of nodes, then the graph G is said to be

a)

Regular

b)

Finite

c)

Complete

d)

Strongly connected

63.

Consider an undirected graph G with 100 nodes. The maximum number of edges to be included in G so that the graph is not connected is

a)

2451

b)

4851

c)

4950

d)

9801

64.

A connected (all vertices have at least one neighbour), undirected graph of N vertices has (N-1) edges. Number of spanning tree that can be constructed are

a)

1

b)

N

c)

N - 1

d)

N × (N-1)