6.1. Introduction To Graphs
6.1. Introduction To Graphs
6.1. Introduction To Graphs
Graphs
6.1. Introduction to Graphs:
Graph G is a pair (V, E), where V is a finite set of vertices and E is a finite set of edges.
We will often denote n = |V|, e = |E|.
A graph is generally displayed as figure 6.5.1, in which the vertices are represented by
circles and the edges by lines.
An edge with an orientation (i.e., arrow head) is a directed edge, while an edge with no
orientation is our undirected edge.
If all the edges in a graph are undirected, then the graph is an undirected graph. The
graph in figure 6.5.1(a) is an undirected graph. If all the edges are directed; then the
graph is a directed graph. The graph of figure 6.5.1(b) is a directed graph. A directed
graph is also called as digraph. A graph G is connected if and only if there is a simple
path between any two nodes in G.
A directed graph G is said to be connected, or strongly connected, if for each pair (u, v)
for nodes in G there is a path from u to v and also a path from v to u. On the other
hand, G is said to be unilaterally connected if for any pair (u, v) of nodes in G there is a
path from u to v or a path from v to u. For example, the digraph shown in figure 6.5.1
(e) is strongly connected.
B D v1
A B
E
A C E G v4 v2
C D
v1 v1 v1 v1
v2 v3
v4 v2 v4 v2 v4 v2
We can assign weight function to the edges: wG(e) is a weight of edge e E. The graph
which has such function assigned is called weighted graph.
The number of incoming edges to a vertex v is called in–degree of the vertex (denote
indeg(v)). The number of outgoing edges from a vertex is called out-degree (denote
outdeg(v)). For example, let us consider the digraph shown in figure 6.5.1(f),
Lecture Notes 185 Dept. of Information
Technology
indegree(v1) = 2 outdegree(v1) = 1
indegree(v2) = 2 outdegree(v2) = 0
A path is a sequence of vertices (v1, v2, . . . . . , v k), where for all i, (vi, vi+1) E. A path
is simple if all vertices in the path are distinct. If there is a path containing one or more
edges which starts from a vertex V i and terminates into the same vertex then the path
is known as a cycle. For example, there is a cycle in figure 6.5.1(a), figure 6.5.1(c) and
figure 6.5.1(d).
If a graph (digraph) does not have any cycle then it is called acyclic graph. For
example, the graphs of figure 6.5.1 (f) and figure 6.5.1 (g) are acyclic graphs.
A Forest is a set of disjoint trees. If we remove the root node of a given tree then it
becomes forest. The following figure shows a forest F that consists of three trees T1, T2
and T3.
D B
A Forest F
P X
Y
Q R
Z
C F T2 T3 T1
A graph that has either self loop or parallel edges or both is called multi-graph.
Tree is a connected acyclic graph (there aren’t any sequences of edges that go around
in a loop). A spanning tree of a graph G = (V, E) is a tree that contains all vertices of V
and is a subgraph of G. A single graph can have multiple spanning trees.
3. If we add any edge into T, then the new graph will contain a cycle.
Adjacency matrix.
Adjacency List.
Incidence matrix.
Adjacency matrix:
The matrix is symmetric in case of undirected graph, while it may be asymmetric if the
graph is directed. This matrix is also called as Boolean matrix or bit matrix.
1 1 2 3 4 5
1 0 1 1 0 1
2 3
G1: 2 0 0 1 1 1
3 0 0 0 1 0
4 0 0 0 0 0
(a) 4 5 (b)
5 0 0 1 1 0
Figure 6.5.2(b) shows the adjacency matrix representation of the graph G1 shown in
figure 6.5.2(a). The adjacency matrix is also useful to store multigraph as well as
weighted graph. In case of multigraph representation, instead of entry 0 or 1, the entry
will be between number of edges between two vertices.
In case of weighted graph, the entries are weights of the edges between the vertices.
The adjacency matrix for a weighted graph is called as cost adjacency matrix. Figure
6.5.3(b) shows the cost adjacency matrix representation of the graph G2 shown in
figure 6.5.3(a).
Adjacency List:
In this representation, the n rows of the adjacency matrix are represented as n linked
lists. An array Adj[1, 2, . . . . . n] of pointers where for 1 < v < n, Adj[v] points to a
linked list containing the vertices which are adjacent to v (i.e. the vertices that can be
reached from v by a single edge). If the edges have weights then these weights may
also be stored in the linked list elements. For the graph G in figure 6.5.4(a), the
adjacency list in shown in figure 6.5.4 (b).
1 2 3
1 1 1 2 3
1 1 1
1 2 3
2 0 0
3 0 1 0 3 2
Incidence Matrix:
In this representation, if G is a graph with n vertices, e edges and no self loops, then
incidence matrix A is defined as an n by e matrix, say A = (ai,j), where
Figure 6.5.4(b) shows the incidence matrix representation of the graph G1 shown in
figure 6.5.4(a).
A spanning tree for a connected graph is a tree whose vertex set is the same as the
vertex set of the given graph, and whose edge set is a subset of the edge set of the
given graph. i.e., any connected graph will have a spanning tree.
Weight of a spanning tree w(T) is the sum of weights of all edges in T. Minimum
spanning tree (MST) is a spanning tree with the smallest possible weight.
Example:
G:
A gr a p h G:
T hr e e ( of ma n y p o s s i b l e) s p a n n i n g t r e e s f r o m gr a p h G:
2 2
4
G: 3 5 3
6
1 1
A w e i g ht e d gr a p h G: T h e mi n i m a l s p a n n i n g t r e e f ro m w e i g ht e d gr a p h G:
Minimum spanning tree, can be constructed using any of the following two algorithms:
Both algorithms differ in their methodology, but both eventually end up with the
MST. Kruskal's algorithm uses edges, and Prim’s algorithm uses vertex connections in
determining the MST. In Prim’s algorithm at any instance of output it represents tree
whereas in Kruskal’s algorithm at any instance of output it may represent tree or not.
This is a greedy algorithm. A greedy algorithm chooses some local optimum (i.e.
picking an edge with the least weight in a MST).
Kruskal's algorithm works as follows: Take a graph with 'n' vertices, keep on adding the
shortest (least cost) edge, while avoiding the creation of cycles, until (n - 1) edges
have been added. Sometimes two or more edges may have the same cost.
The order in which the edges are chosen, in this case, does not matter. Different MST’s
may result, but they will all have the same total cost, which will always be the
minimum cost.
2. Repeat the steps 3, 4 and 5 as long as T contains less than n - 1 edges and E is
not empty otherwise, proceed to step 6.
Example 1:
Construct the minimal spanning tree for the graph shown below:
Lecture Notes 190 Dept. of Information
Technology
10 50
1 2
45 40 3
30 35
4 25 5
55
20 15
6
Cost 10 15 20 25 30 35 40 45 50 55
Edge (1, 2) (3, 6) (4, 6) (2, 6) (1, 4) (3, 5) (2, 5) (1, 5) (2, 3) (5, 6)
STAGES IN KRUSKAL’S
EDGE COST REMARKS
ALGORITHM
4
5
6
4
5
6
4
5
6
Example 2:
Construct the minimal spanning tree for the graph shown below:
1 28
10
2
14
6 16
7
24 3
25
5 18
12
22 4
Solution:
Cost 10 12 14 16 18 22 24 25 28
Edge (1, 6) (3, 4) (2, 7) (2, 3) (4, 7) (4, 5) (5, 7) (5, 6) (1, 2)
STAGES IN KRUSKAL’S
EDGE COST REMARKS
ALGORITHM
5
4
5
4
5
4
5
4
A given graph can have many spanning trees. From these many spanning trees, we
have to select a cheapest one. This tree is called as minimal cost spanning tree.
Minimal cost spanning tree is a connected undirected graph G in which each edge is
labeled with a number (edge labels may signify lengths, weights other than costs).
Minimal cost spanning tree is a spanning tree for which the sum of the edge labels is as
small as possible
The slight modification of the spanning tree algorithm yields a very simple algorithm for
finding an MST. In the spanning tree algorithm, any vertex not in the tree but
connected to it by an edge can be added. To find a Minimal cost spanning tree, we
must be selective - we must always add a new vertex for which the cost of the new
edge is as small as possible.
This simple modified algorithm of spanning tree is called prim's algorithm for finding an
Minimal cost spanning tree. Prim's algorithm is an example of a greedy algorithm.
Prim’s Algorithm:
E is the set of edges in G. cost [1:n, 1:n] is the cost adjacency matrix of an n vertex
graph such that cost [i, j] is either a positive real number or if no edge (i, j) exists. A
minimum spanning tree is computed and stored as a set of edges in the array t [1:n-1,
1:2]. (t [i, 1], t [i, 2]) is an edge in the minimum-cost spanning tree. The final cost is
returned.
Use Prim’s Algorithm to find a minimal spanning tree for the graph shown below
starting with the vertex A.
4
B D
4
3 2 1 2
4 E 1
A C 2 G
6
2 F 1
Solution:
The cost adjacency matrix is
0 3 6
3 0 2 4
6 2 0 1 4
4 1 0 2
4 2 0
2 2
4 1
Step 1:
B 3 D Vertex A B C D E F G
Status 0 1 1 1 1 1 1
E Dist. 0 3 6
A 0 6 G Next * A A A A A A
F
Step 2: C
44 D Vertex A B C D E F G
B 3
Status 0 0 1 1 1 1 1
E Dist. 0 3 2 4
A 0 Next * A B B A A A
2 G
F
C
Step 3:
1 D
B 3
4 E Vertex A B C D E F G
Status 0 0 0 1 1 1 1
A 0 2 G
Dist. 0 3 2 1 4 2
Step 4: C 2 F Next * A B C C C A
1 D Vertex A B C D E F G
Status 0 0 0 0 1 1 1
Dist. 0 3 2 1 2 2 4
2 E
A 0 2 4 G Next * A B C D C D
C
2 F
Step 5:
B 3 1 D
Lecture Notes 195 Dept. of Information
Technology
Vertex A B C D E F G
Status 0 0 0 0 1 0 1
Dist. 0 3 2 1 2 2 1
A 0 2 2 E 1 G Next * A B C D C E
C
2 F
Step 6:
Vertex A B C D E F G
B 3 1 D
Status 0 0 0 0 0 1 0
Dist. 0 3 2 1 2 1 1
1 G Next * A B C D G E
A 0 2 2
E
C
1 F
Step 7:
Vertex A B C D E F G
B 3 1 D
Status 0 0 0 0 0 0 0
Dist. 0 3 2 1 2 1 1
2 E
A 0 2 1 G Next * A B C D G E
C 1 F
Warshall’s algorithm requires knowing which edges exist and which does not. It doesn’t
need to know the lengths of the edges in the given directed graph. This information is
conveniently displayed by adjacency matrix for the graph, in which a ‘1’ indicates the
existence of an edge and ‘0’ indicates non-existence.
A l l P a ir s Rec h a b i l it y
A d j ac e nc y M at r i x W a r s h a l l’ s A l g or it h m
M at r i x
It begins with the adjacency matrix for the given graph, which is called A0, and then
updates the matrix ‘n’ times, producing matrices called A1, A2, . . . . . , An and then
stops.
The update rule for computing Ai from Ai-1 in warshall’s algorithm is:
Ai [x, y] = Ai-1 [x, y] ۷ (Ai-1 [x, i] ٨ Ai-1 [i, y]) ---- (1)
Example 1:
Use warshall’s algorithm to calculate the reachability matrix for the graph:
4
1 4
5 6
7 11
1
2 3
7
1 0 1 1 0
2 0 0 1 1
A0 0
3 0 0 0
4 1 1 1 0
The first step is to compute ‘A1’ matrix. To do so we will use the updating rule – (1).
Before doing so, we notice that only one entry in A 0 must remain one in A1, since in
Boolean algebra 1 + (anything) = 1. Since these are only nine zero entries in A 0, there
are only nine entries in A0 that need to be updated.
1 0 1 1 0
2 0 0 1 1
A1
3 0 0 0 0
4
1 1 1 0
1
0 1 1 1
2 0 0 1 1
A2
3 0 0 0 0
4
1 1 1 1
This matrix has only seven 0 entries, and so to compute A 3, we need to do only seven
computations.
1 0 1 1 1
2 0 0 1 1
A3
3 0 0 0 0
4
1 1 1 1
Once A3 is calculated, we use the update rule to calculate A 4 and stop. This matrix is
the reachability matrix for the graph.
Note that according to the algorithm vertex 3 is not reachable from itself 1. This is
because as can be seen in the graph, there is no path from vertex 3 back to itself.
Many graph algorithms require one to systematically examine the nodes and edges of a
graph G. There are two standard ways to do this. They are:
During the execution of these algorithms, each node N of G will be in one of three
states, called the status of N, as follows:
Both BFS and DFS impose a tree (the BFS/DFS tree) on the structure of graph. So, we
can compute a spanning tree in a graph. The computed spanning tree is not a
minimum spanning tree. The spanning trees obtained using depth first search are
called depth first spanning trees. The spanning trees obtained using breadth first
search are called Breadth first spanning trees.
The general idea behind a breadth first traversal beginning at a starting node A is as
follows. First we examine the starting node A. Then we examine all the neighbors of A.
Then we examine all the neighbors of neighbors of A. And so on. We need to keep track
of the neighbors of a node, and we need to guarantee that no node is processed more
than once. This is accomplished by using a QUEUE to hold nodes that are waiting to be
processed, and by using a field STATUS that tells us the current status of any node.
The spanning trees obtained using BFS are called Breadth first spanning trees.
1. Put the starting node A in QUEUE and change its status to the waiting
state (STATUS = 2).
Lecture Notes 199 Dept. of Information
Technology
2. Repeat the following steps until QUEUE is empty:
b. Add to the rear of QUEUE all the neighbors of N that are in the
ready state (STATUS = 1), and change their status to the waiting
state (STATUS = 2).
3. Exit.
6.5.2. Depth first search and traversal:
Depth first search of undirected graph proceeds as follows: First we examine the
starting node V. Next an unvisited vertex 'W' adjacent to 'V' is selected and a depth
first search from 'W' is initiated. When a vertex 'U' is reached such that all its adjacent
vertices have been visited, we back up to the last vertex visited, which has an unvisited
vertex 'W' adjacent to it and initiate a depth first search from W. The search terminates
when no unvisited vertex can be reached from any of the visited ones.
This algorithm is similar to the inorder traversal of binary tree. DFT algorithm is similar
to BFT except now use a STACK instead of the QUEUE. Again field STATUS is used to
tell us the current status of a node.
2. Push the starting node A into STACK and change its status to the waiting state
(STATUS = 2).
a. Pop the top node N from STACK. Process N and change the status of N to
the processed state (STATUS = 3).
b. Push all the neighbors of N that are in the ready state (STATUS = 1), and
change their status to the waiting state (STATUS = 2).
4. Exit.
Example 1:
Consider the graph shown below. Traverse the graph shown below in breadth first
order and depth first order.
D E G
E C, D, G, J, K
F A, C, D
G B, C, E, K
J K
J D, E, K
A Gr a p h G
K E, G, J
Adjacency list for graph G
Current Status
QUEUE Processed Nodes
Node A B C D E F G J K
1 1 1 1 1 1 1 1 1
A 2 1 1 1 1 1 1 1 1
A FCB A 3 2 2 1 1 2 1 1 1
F CBD AF 3 2 2 2 1 3 1 1 1
C BDEG AFC 3 2 3 2 2 3 2 1 1
B DEG AFCB 3 3 3 2 2 3 2 1 1
D EGJ AFCBD 3 3 3 3 2 3 2 2 1
E GJK AFCBDE 3 3 3 3 3 3 2 2 2
G JK AFCBDEG 3 3 3 3 3 3 3 2 2
J K AFCBDEGJ 3 3 3 3 3 3 3 3 2
K EMPTY AFCBDEGJK 3 3 3 3 3 3 3 3 3
For the above graph the breadth first traversal sequence is: A F C B D E G J K.
Current Status
Stack Processed Nodes
Node A B C D E F G J K
1 1 1 1 1 1 1 1 1
A 2 1 1 1 1 1 1 1 1
A BCF A 3 2 2 1 1 2 1 1 1
Lecture Notes 201 Dept. of Information
Technology
F BCD AF 3 2 2 2 1 3 1 1 1
D BCEJ AFD 3 2 2 3 2 3 1 2 1
J BCEK AFDJ 3 2 2 3 2 3 1 3 2
K BCEG AFDJK 3 2 2 3 2 3 2 3 3
G BCE AFDJKG 3 2 2 3 2 3 3 3 3
E BC AFDJKGE 3 2 2 3 3 3 3 3 3
C B AFDJKGEC 3 2 3 3 3 3 3 3 3
B EMPTY AFDJKGECB 3 3 3 3 3 3 3 3 3
For the above graph the depth first traversal sequence is: A F D J K G E C B.
Example 2:
Traverse the graph shown below in breadth first order, depth first order and construct
the breadth first and depth first spanning trees.
A H I Node Adjacency List
A F, B, C, G
B C G B A
C A, G
D E, F
J K E G, D, F
D
F A, E, D
E G A, L, E, H, J, C
F
H G, I
L M
The G ra ph G I H
J G, L, K, M
K J
L G, J, M
TheM L, list
adjacency J for the graph G
If the depth first traversal is initiated from vertex A, then the vertices of graph G are
visited in the order: A F E G L J K M H I C D B. The depth first spanning tree is shown
in the figure given below:
F B
G D
L H C
J I
K M
Depth first Traversal
If the breadth first traversal is initiated from vertex A, then the vertices of graph G are
visited in the order: A F B C G E D L H J M I K. The breadth first spanning tree is
shown in the figure given below:
F B C G
E D L H J
M I K
Traverse the graph shown below in breadth first order, depth first order and construct
the breadth first and depth first spanning trees.
2 3
4 5 6 7
Graph G
1 2 3
2 1 4 5
3 1 6 7
4 2 8
5 2 8
6 3 8
7 3 8
8 4 5 6 7
A dj ac e nc y list fo r g r a p h G
If the depth first is initiated from vertex 1, then the vertices of graph G are visited in
the order: 1, 2, 4, 8, 5, 6, 3, 7. The depth first spanning tree is as follows:
2 3
4 5 6 7
If the breadth first search is initiated from vertex 1, then the vertices of G are visited in
the order: 1, 2, 3, 4, 5, 6, 7, 8. The breadth first spanning tree is as follows:
2 3
4 5 6 7
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<alloc.h>
struct graph
{
int status;
int data;
struct graph *next;
};
typedef struct graph node;
int ctr;
node *start[40];
node *queue;
node* getnode()
{
node *newnode;
newnode=(node*)malloc(sizeof(node));
printf("Enter data:");
scanf("%d",&newnode->data);
newnode->status=1;
newnode->next=NULL;
return(newnode);
}
void createadj_list(int n)
{
int i;
node *newnode,*temp;
for(i=1;i<n;i++)
{
printf("enter data for %d node",i);
while(1)
{
newnode=getnode();
if(newnode->data==-999)
break;
if(start[i]==NULL)
{
start[i]=newnode;
}
else
{
temp=start[i];
while(temp->next!=NULL)
Lecture Notes 205 Dept. of Information
Technology
temp=temp->next;
temp->next=newnode;
}
}
}
}
void main()
{
int i,n,k;
node *temp,*temp1,*temp2,*newnode;
int processednode[20];
int currentnode,startnode;
clrscr();
printf("enter number of nodes in a graph: ");
scanf("%d",&n);
printf("Enter adjacency list of a graph:");
createadj_list(n);
printf("enter starting node:");
scanf("%d",&startnode);
for(k=1;k<n;k++)
{
if(start[k]->data==startnode)
{
temp=start[k];
newnode=makenode(temp->data);
queue=newnode;
break;
}
else
printf("Given starting node is not present");
}
i=0;
do
{
currentnode=queue->data;
processednode[i]=currentnode;
i++;
temp=queue;
queue=queue->next;
free(temp);
for(k=1;k<n;k++)
{
temp=start[k];
if(temp->data==currentnode)
{
temp1=temp;
while(temp1!=NULL)
{
if(temp1->status==1)
{
newnode=makenode(temp1->data);
if(queue==NULL)
queue=newnode;
else
{
temp2=queue;
while(temp2!=NULL)
temp2=temp2->next;
temp2->next=newnode;
EXCERCISES
1. Show that the sum of degrees of all vertices in an undirected graph is twice the
number of edges.
2. Show that the number of vertices of odd degree in a finite graph is even.
4. Show that the number of spanning trees in a complete graph of “n” vertices is 2 n-1
– 1.
5. Prove that the edges explored by a breadth first or depth first traversal of a
connected graph from a tree.
7. Write a “C” function to generate the incidence matrix of a graph from its
adjacency matrix.
10. Write a “C” function to find out whether there is a path between any two vertices
in a graph (i.e. to compute the transitive closure matrix of a graph)
11. Write a “C” function to delete an existing edge from a graph represented by an
adjacency list.
12. Construct a weighted graph for which the minimal spanning trees produced by
Kruskal’s algorithm and Prim’s algorithm are different.
Lecture Notes 207 Dept. of Information
Technology
13. Describe the algorithm to find a minimum spanning tree T of a weighted graph G.
Find the minimum spanning tree T of the graph shown below.
6 5
A B C
1 8
4 2
D E
3
8 6
1 1 5 7
2 4 6 2 7 9
3 3 8 10
4 10 9 5
4
1
2 3 7 8
5 6
6
2 4
8
3
7
36 9 C ADF
C D E
D ABCEFG
25 16 E BDG
28
3
F CDG
F G
17 G FDE
8. For the figure 1 shown above, the breadth first spanning tree visiting [ B ]
sequence is:
A. A B D C F G E C. A B C D E F G
B. A B C D E F G D. none of the above
9. Which is the correct order for Kruskal’s minimum spanning tree algorithm [ B ]
to add edges to the minimum spanning tree for the figure 1 shown
Lecture Notes 209 Dept. of Information
Technology
above:
A. (A, B) then (A, C) then (A, D) then (D, E) then (C, F) then (D, G)
B. (A, D) then (E, G) then (B, D) then (D, E) then (F, G) then (A, C)
C. both A and B
D. none of the above
10. For the figure 1 shown above, the cost of the minimal spanning tree is: [ A ]
A. 57 C. 48
B. 68 D. 32
11. A simple graph has no loops. What other property must a simple graph [ D ]
have?
A. It must be directed. C. It must have at least one vertex.
B. It must be undirected. D. It must have no multiple edges.
12. Suppose you have a directed graph representing all the flights that an [ D ]
airline flies. What algorithm might be used to find the best sequence of
connections from one city to another?
A. Breadth first search. C. A cycle-finding algorithm.
B. Depth first search. D. A shortest-path algorithm.
13. If G is an directed graph with 20 vertices, how many boolean values will [ D ]
be needed to represent G using an adjacency matrix?
A. 20 C. 200
B. 40 D. 400
15. What graph traversal algorithm uses a queue to keep track of vertices [ A ]
which need to be processed?
A. Breadth-first search. C Level order search
B. Depth-first search. D. none of the above
16. What graph traversal algorithm uses a stack to keep track of vertices [ B ]
which need to be processed?
A. Breadth-first search. C Level order search
B. Depth-first search. D. none of the above
17. What is the expected number of operations needed to loop through all [ D ]
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) C. O(m²)
B. O(n) D. O(n²)
18. What is the expected number of operations needed to loop through all [ A ]
the edges terminating at a particular vertex given an adjacency list
representation of the graph? (Assume n vertices are in the graph and m
edges terminate at the desired node.)
A. O(m) C. O(m²)
B. O(n) D. O(n²)
2 1 5 5
B 3 G 4 E FIGURE 3
1 4 6 1
C F
3
For the figure 3, starting at vertex A, which is a correct order for Prim’s
minimum spanning tree algorithm to add edges to the minimum
spanning tree?
A. (A, G) then (G, C) then (C, B) then (C, F) then (F, E) then (E, D)
B. (A, G) then (A, B) then (B, C) then (A, D) then (C, F) then (F, E)
C. (A, G) then (B, C) then (E, F) then (A, B) then (C, F) then (D, E)
D. (A, G) then (A, B) then (A, C) then (A, D) then (A, D) then (C, F)
20. For the figure 3, which is a correct order for Kruskal’s minimum spanning [ C ]
tree algorithm to add edges to the minimum spanning tree?
A. (A, G) then (G, C) then (C, B) then (C, F) then (F, E) then (E, D)
B. (A, G) then (A, B) then (B, C) then (A, D) then (C, F) then (F, E)
C. (A, G) then (B, C) then (E, F) then (A, B) then (C, F) then (D, E)
D. (A, G) then (A, B) then (A, C) then (A, D) then (A, D) then (C, F)
21. Which algorithm does not construct an in-tree as part of its processing? [ ]
A. Dijkstra’s Shortest Path Algorithm
B. Prim’s Minimum Spanning Tree Algorithm
C. Kruskal’s Minimum Spanning Tree Algorithm
D. The Depth-First Search Trace Algorithm
24. For the figure 4, which edge does not occur in the depth first spanning [ B ]
tree resulting from depth first search starting at node B:
A. F E C. C G
B. E C D. C F
Lecture Notes 211 Dept. of Information
Technology
25. The set of all edges generated by DFS tree starting at node B is: [ A ]
A. B A D C G F E C. B A C D G F E
B. A D D. Cannot be generated
26. The set of all edges generated by BFS tree starting at node B is: [ C ]
A. B A D C G F E C. B A C D G F E
B. A D D. Cannot be generated