CHAPTER 6. GRAPH. CSEB324 DATA STRUCTURES & ALGORITHM. A. Nodes/vertices: A, B, C, G, D, E, F Edges : AB, BC, CG, BD, CE, AF and DF. B. C. G. D. E. F. Introduction. Graph : A graph G consists of two: a set V of vertices or nodes and a set E of edges/arcs that connect the
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
DATA STRUCTURES & ALGORITHM
1 2 3 4
1 0 11 0
2 0 0 11
3 0 0 0 1
4 11 0 0
(a) A directed graph and (b) its adjacency matrix
(a) A weighted un directed graph and (b) its adjacency matrix
(a) A directed graph and (b) its adjacency list
(a) A weighted undirected graph and (b) its adjacency list
NOTE: it is common to include cross links between corresponding edges, when needed to mark the edges previously visited. e.g. (v,w) = (w,v).
1. Depth First Search (DFS)
2. Breadth First Search (BFS)
Step1: Choose any node in the graph. Designate it as search node and mark it as visited.
Step2: Using adjacency matrix of the graph, find a node adjacent to the search node (connected by an edge from the search node) that has not been visited yet. Designatethis as search node and mark it as visited.
Step3: Repeat step 2 using the new search node. If no nodes satisfying step 2 can be found, return to the previous search node and continue from there
Step4: When a return to the previous search node in step 3 is impossible, the search from the originally chosen search node is complete.
Step5: if the graph still contains unvisited nodes, choose any node that has not been visited and repeat steps 1 through 4.
Step1: Begin with any node in the graph and mark it as visited.
Step2: Proceed to the next node having an edge connection to the node in step 1. Mark it as Visited.
Step3: Come back to the node in step 1, descend along an edge towards an unvisited node, and mark the new node as visited.
Step4: Repeat step 3 until all nodes adjacent to the node in step 1 have been marked as visited.
Step5: Repeat step 1 through 4 starting from the node visited in step 2, then starting from the node visited in step 3 in the order visited.