Graphs - Traversals Traversal of Graphs Depth First Traversals (or search) – DFS Traversal

600 Words3 Pages
Graphs - Traversals Traversal of Graphs Depth First Traversals (or search) – DFS Traversal performed using stack. Similar to preorder sort of Trees Process all Vertex’s descendants Start with first vertex – process it (mark as processed) Identify an adjacent vertex and process it (mark as processed) Repeat C until a vertex is reached which has no unmarked adjacent vertices Trace back in graph and process another vertex as in ( c) Repeat until all vertices are processed DFS Applications Finding connected components. Topological sorting. Finding 2-(edge or vertex)-connected components. Finding 3-(edge or vertex)-connected components. Finding the bridges of a graph. Generating words in order to plot the Limit Set of a…show more content…
Least distance for travel – How do you calculate? - Sum of distances of lines for each path. Could also be cost based or travel time based. Dijkstra’s Algorithm Helps calculate shortest path between two nodes in a Graph Assign Infinity distance value to all nodes (except starting) and mark all nodes as unvisited and create a set of the unvisited nodes For starting node, consider all unvisited neighboring nodes and calculate distance from starting node. If the distance assigned is Zero or non-zero value greater than calculated value, assign the calculated value. Else keep the assigned value When all unvisited neighbors of the current node are considered, mark the current node as Visited and remove from unvisited Set. If the destination node is marked as “visited” or if there are no nodes in the unvisited set with non-infinity value, the algorithm is finished. If the destination node is marked as visited, the distance value of the node is the smallest distance from source. Else there is no connection between source and destination. Identify the unvisited node with the smallest distance value and repeat from 3 Dijkstra’s Algorithm Shortest distance from Hyderabad to Vijayawada (not to scale)
Open Document