Documente Academic
Documente Profesional
Documente Cultură
In G = ( V , E ) ,
V = {A,B,C,D,E,F} and
E = (A,B), (A,C), (A,D), (B,D), (C,D),
(B,E), (E,D)}
Degree of :
A is 3, Bis 3, C is 2, D is 4 ,E is 2 & F is 0
F
F Simple & Closed Path (Cycle) :
A->B>E->D->C->A
Closed Path :
B->E->D->A->C->D->B
Isolated Node: F
Types of Graph Directed
Also called as Digraph or graph.
Each edge e in G is assigned direction.
e is also called an arc.
Terms used:
e begins at u and ends at v.
u is the origin and v is the destination.
u is the predecessor and v is a successor or neighbour of u.
u is adjacent to v and v is adjacent to u.
Out degree of u is number of edges beginning at u.
In degree of u is number of edges ending at u.
u is called a source if it has +ve out degree but zero in degree.
u is called a sink if it has zero out degree but a +ve in degree
(Node C).
Types of Graph Directed
A directed graph G is connected, or strongly connected if for each
pair u,v of nodes in G, there is a path from u to v and there is also
a path from v to u (i.e where any pair of vertices in the graph is
connected by at least one path )
Example: Directed Graph
X Y Z W
W
Representation of Graphs in
Memory Sequential
Disadvantages:
Difficult to insert and delete nodes in G, as the size of the
array may need to be changed and the nodes may need to be
reordered.
If the number of edges in the graph is less, a great deal of
space will be wasted i.e. the matrix will be Sparse.
Representation of Graphs in
Memory Linked
Also called as Adjacency structure.
Contains two lists or files:
A node list NODE
An edge list EDGE
NODE List: each element in the list NODE will correspond to a
node in G and will be a record in the following form.
A Adjacency Lists
A F,C,B
B G,C
F C B C F
D C
E D,C,J
D E G
F D
G C,E
J K J D
K E,G,J
BFS Start with Node A
C B A
F
J K
BFS Start with Node A
C B A,F,C,B
F
J K
A
BFS Start with Node A
A
C B A,F,C,B,D
F
J K
A,F
BFS Start with Node A
C B A,F,C,B,D
F
J K
A,F,C
BFS Start with Node A
C B A,F,C,B,D,G
F
J K
A,F,C,B
BFS Start with Node A
C B A,F,C,B,D,G
F
J K
A,F,C,B,D
BFS Start with Node A
C B A,F,C,B,D,G,E
F
J K
A,F,C,B,D,G
BFS Start with Node A
C B A,F,C,B,D,G,E,J
F
J K
A,F,C,B,D,G,E
BFS Start with Node A
C B A,F,C,B,D,G,E,J
F
B G,C
C F
F C B
D C
E D,C,J
D E G F D
G C,E
J D,K
J K
K E,G
DFS: Start with Node J
F C B
D E G
J
J K
Push J
DFS: Start with Node J
F C B
D E G
J K
Pop/Visit/Mark J
J
DFS: Start with Node J
F C B
D E G K
D
J K
Push neighbors of J
D,K
J
DFS: Start with Node J
F C B
D E G
D
J K Pop/Visit/Mark K
J, K
DFS: Start with Node J
F C B
G
E G E
D
D
J K
Push neighbors of K -
E, G,
J,K
DFS: Start with Node J
F C B
E G E
D
D
J K Pop/Visit/Mark G
J,K,G
DFS: Start with Node J
F C B
C
D E G E
D
J K
Push neighbors of G - C
J,K,G
DFS: Start with Node J
F C B
D E G E
D
J K
Pop/Visit/Mark C
J,K,G,C
DFS: Start with Node J
F C B
F
D E G E
D
J K
Push neighbors of C -
F
J,K,G,C,
DFS: Start with Node J
F C B
D E G E
D
J K
Pop/Mark/Visit F
J,K,G,C, F
DFS: Start with Node J
F C B
D E G E
D
J K
Push neighbors of F -
None
J,K,G,C, F
DFS: Start with Node J
F C B
D E G
D
J K
Pop/Mark/Visit E
J,K,G,C, F,E
DFS: Start with Node J
F C B
D E G
D
J K
Push neighbors of E -
None
J,K,G,C, F,E
DFS: Start with Node J
A
F C B
D E G
J K
J,K,G,C,F,E,D Pop/Mark/Visit D