Professional Documents
Culture Documents
⃝ Option 1: 0 → 1 → 2 → 3 → 4
⃝ Option 2: 0 → 3 → 2 → 1 → 4
⃝ Option 3: 0 → 4 → 3 → 1 → 2
⃝ Option 4: 0 → 2 → 1 → 3 → 4
• The (i, j)th element of the matrix C which is product of matrix A and matrix B
where both the dimension of matrix A and B is n × n can be written as:
Cij = nk=1 Aik Bkj
P
⃝ Option 1:
⃝ Option 2:
2
⃝ Option 3:
⃝ Option 4:
⃝ Option 1:
⃝ Option 2:
⃝ Option 3:
3
⃝ Option 4:
4. Key Points:
• Weighted shortest path need not have minimum number of Edges.
• Single Sourced Shortest Path: Shortest path from a vertex to every other
vertex.
• All Pair Shortest Path: Shortest path between any two vertex i and j
• Negative Cycle: A negative cycle is one whose weight is negative
• If a graph has a negative cycle, shortest paths are not defined.
• In a weighted graph, the adjacency matrix records the weight where ever there is
an edge and 0 if there is no edge.
• Dijkstra’s Algorithm finds the shortest path between a given node (which is
called the ”source node”) and all other nodes in a graph. This algorithm uses the
weights of the edges to find the path that minimizes the total distance (weight)
between the source node and all other nodes.
1. Answer the following questions based on this graph:
There are six cities A,B,C,D,E and F with time taken to reach from one city to
another is given(in hours)
4
(a) If Aman wants to travel from city A to city F then what is the minimum possible
time it will take for him to reach his destination?
⃝ Option 1: 6 Hours
⃝ Option 2: 8 Hours
⃝ Option 3: 9 Hours
⃝ Option 4: 10 Hours
(b) What is the shortest path between city A to City F?
⃝ Option 1: A → B → C → F
⃝ Option 2: A → C → D → F
⃝ Option 3: A → B → C → D → F
⃝ Option 4: A → C → E → F
Key Points:
• Bellman Ford algorithm helps us find the shortest path from a vertex to all other
vertices of a weighted graph.
• Bellman Ford Algorithm updates distance to each vertex with every iteration
• If Bellman Ford Algorithm does not converge after n-1 iteration then the graph has
a negative cycle.
1. While using Bellman-Ford Algorithm for the graph shown below, let D(v) be the
shortest distance of vertex v from the source vertex after 4 iterations.
(a) Suppose source vertex is A then, which of the following options is correct?
⃝ Option 1: D(B)=3
⃝ Option 2: D(B) = 4
⃝ Option 3: D(D) = 1
⃝ Option 4: D(E)= 7
⃝ Option 5: D(E)=6
5
(b) If the source vertex is changed from vertex A to vertex D. then which of the following
options is (are) correct?
⃝ Option 1: Bellman-Ford algorithm stabilizes after the first iteration.
⃝ Option 2: Bellman-Ford algorithm will not be applicable.
⃝ Option 3: D(C) = 0
⃝ Option 4: None of the Above
Key Points:
6
⃝ Option 2:
⃝ Option 3:
⃝ Option 4:
Key Points:
• Spanning tree is defined as a subset of a connected undirected graph that has all
the vertices covered with the minimum number of edges possible
• A tree on n vertices has exactly n − 1 edges.
• Adding an edge to a tree creates a cycle.
(a) Which of the following are possible trees of the given graph ?
7
⃝ Option 1:
⃝ Option 2:
⃝ Option 3:
⃝ Option 4:
(b) Which of the following is (are) incorrect with respect to the spanning tree G?
⃝ Option 1: For a graph of n vertices G has n − 1 edges
⃝ Option 2: For a graph of n vertices G has n edges
⃝ Option 3: G is not connected
⃝ Option 4: G is cyclic
Key Points: Prim’s Algorithm
• Incrementally Grow the Minimum Cost Spanning Tree using Prim’s Algorithm
• Start with the smallest weight edge graph
• Extend the current tree by adding the smallest edges from the tree to the vertex
not in the tree
8
(a) If we perform Prim’s algorithm on G, then which of the following options may
represent a minimum cost spanning tree?
⃝ Option 1:
⃝ Option 2:
⃝ Option 3:
9
⃝ Option 4:
(b) Which of the following is the order in which edges are added to the minimum cost
spanning tree?
⃝ Option 1:(1,4),(1,2),(2,3),(1,5),(2,6)
⃝ Option 2: (1,4),(2,3),(1,2),(1,5),(2,6)
⃝ Option 3: (2,3),(1,2),(1,5),(2,6),(1,4)
⃝ Option 4: (1,5),(2,6),(1,4),(2,3),(1,2)
(c) What is the weight of the minimum cost spanning tree?
⃝ Option 1:16
⃝ Option 2:18
⃝ Option 3:19
⃝ Option 4: 17
Key Points: Kruskal’s Algorithm
(a) If we perform Kruskal’s algorithm on G, then which of the following options may
represent the minimum cost spanning tree?
10
⃝ Option A:
⃝ Option B:
⃝ Option C:
⃝ Option D:
11