Standard ways of traversing a graph, Data Structure & Algorithms

Q. Which are the two standard ways of traversing a graph?  Explain them with an example of each. 

Ans:

 

The two ways of traversing a graph are written below

i. The depth-first traversal     of a graph is same as the depth-first traversal of a tree. Since a graph does not have any root, when we do a depth-first traversal, we must specify the vertex at which to begin. Depth-first traversal of a graph visits a vertex and then recursively visits all the vertices adjacent to that particular node. The catch is that the graph may have cycles, but the traversal must visit each and every vertex at most once. The solution to the trouble is to keep track of the nodes that have been visited, so that the traversal does not undergo the fate of infinite recursion.

ii. The breadth-first traversal     of a graph is same as the breadth-first traversal of the tree. Breadth-first tree traversal first of all visits all the nodes at the  depth zero (which is the root), then it visits all the nodes at depth one, and this process continues. Since a graph does not has root, when we perform a breadth-first traversal, we should specify the vertex at which to start the traversal. Furthermore, we can define the depth of the given vertex to be the length of the shortest path from the starting vertex to the vertex given to us.

Hence, breadth-first traversal first visits the beginning vertex, then all the vertices adjacent to the starting vertex, and the all the vertices adjacent to those, and it continues.

 

Posted Date: 7/10/2012 6:01:03 AM | Location : United States







Related Discussions:- Standard ways of traversing a graph, Assignment Help, Ask Question on Standard ways of traversing a graph, Get Answer, Expert's Help, Standard ways of traversing a graph Discussions

Write discussion on Standard ways of traversing a graph
Your posts are moderated
Related Questions
Determine the Components of Illumination The light reaching the eye when looking at a surface has clearly come from a source (or sources) of illumination and bounced off the su

Write an algorithm, using a flowchart, which inputs the heights of all 500 students and outputs the height of the tallest person and the shortest p erson in the school.

Example 3: Travelling Salesman problem Given: n associated cities and distances among them Find: tour of minimum length that visits all of city. Solutions: How several

Q. Write down an algorithm to insert a node in between any two nodes in a linked list         Ans. Insertion of a the node after the given element of the listis as follows

1. Apply the variant Breadth-First Search algorithm as shown in Figure 2 to the attached graph. This variant is used for computing the shortest distance to each vertex from the sta

The best average behaviour is shown by  Quick Sort

how to define the size of array

For the following graph find the adjacency matrix and adjacency list representation of the graph.

This unit dealt along with the methods of physically storing data in the files. The terms fields, records & files were described. The organization types were introduced. The sev

It is a naturally occurring sorting method exemplified through a card player arranging the cards dealt to him. He picks up the cards like they are dealt & added them into the neede