Professional Documents
Culture Documents
Graph Ds
Graph Ds
Terminology
Graph Directed, Undirected and mixed Graph Adjacent nodes and isolated node Incident Initating (originating), Terminating (ending) and loop node
Terminology
Terminology
Path
Elementary path (edge simple) Simple path (node simple)
Terminology
Cycle (circuit)
Elementary Cycle
Acyclic graph
Representation of Graph
Adjacency Matrix Adjacency List Using Linked List (i.e. Sparse Matrix method)
Graph Representation
Adjacency Matrix
Graph Representation
Adjacency list for graph
V1 V2 V3 V4 V2 V4 V1 V1 V2 V4 V2
1 2 3 4
V1 V2 V3 V4
V2 V1 V1
V4
V2
V4
V2
distance between some starting node and the remaining nodes of the graph Shortest distance is the minimum number of edges traversed in order to travel from the node to the specific node being examined Starting at node v, this distance is calculated by examining all incident edges to node v, and then moving on to an adjacent node w and repeating the process.
BFS Algorithm
Node Structure
REACH NODENO DATA DIST LISTPTR
DESTIN
EDGEPTR
Edge structure
BFS Algorithm
Procedure: BFS(INDEX) INDEX current node being processed LINK points to the edge being examined REACH denotes whether node is traversed or not QUEUE name of the queue QINSERT and QDELETE queue handling procedures
BFS Algorithm
1.
[Initialize the first nodes DIST number and place node queue]
REACH[INDEX] true DIST[INDEX] 0 Call QINSERT(QUEUE, INDEX)
2. 3. 4.
5.
6.
[Finished]
Return
of a general graph.
DFS Algorithm
Procedure: DFS(INDEX, COUNT) INDEX current node being processed LINK points to the edge being examined REACH denotes whether node is traversed or not DFN depth first search number
DFS Algorithm
1.
[Update the depth first search number, set and mark current node]
COUNT COUNT + 1 DFN[INDEX] COUNT REACH[INDEX] true
2.
3.
[If node has not been marked, label it and make recursive call]
If not REACH[DESTIN(LINK)] then Call DFS (DESTIN(LINK), COUNT) LINK EDGEPTR(LINK) (Examine next adjacent node)
4.
End of Chapter