The crux of writing this post was that I was posed a question recently which made me go to my books and re-read, re-work, re-learn or whatever you name it. The question was how would you traverse a graph with cyclic nodes to it, basically a cyclic graph, for which I did a quick visio and I have posted below.
The answer was depth first search and breadth first search, above are the results with the graph.
Depth First Search - Stack
Traverse through all the connected nodes, add to stack. Revisit node in stack when no more unvisited nodes
Result: ABEGFCHD
Breadth First Search - Queue
Traverse all the nodes attached to a vertex, add to the queue and then follow the next item in queue and make it as the vertex and reprocess
Result: ABDGEFCH
The answer was depth first search and breadth first search, above are the results with the graph.
Depth First Search - Stack
Traverse through all the connected nodes, add to stack. Revisit node in stack when no more unvisited nodes
Result: ABEGFCHD
Breadth First Search - Queue
Traverse all the nodes attached to a vertex, add to the queue and then follow the next item in queue and make it as the vertex and reprocess
Result: ABDGEFCH
No comments:
Post a Comment
Please add your valuable comments and also questions that would make me write a post for you.