It can be done by using colored dfs .. Done initially making all the node with some color say white . During dfs when a node is encountered then change it color say black and when all it's neighbours r visited mark it as black .when a white node is ever encountered then there is a Cycle.
On 9/11/11, annarao kataru <kataruanna...@gmail.com> wrote: > can any one write the code for checking the graph is connected and > contains any cycles or not ? using bfs technique ( plz code in > java ) > > > thanks in advance.......... > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- Somnath Singh -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.