You are not logged in. Please login at to post your questions!


What is wrong in my implementation of DFS?

I have learnt DFS and tried to implement it. Here is my code -Ideone The expected output should be 1 2 4 3 but my program displays 1 3 4 2. Please help me where I have went wrong.


asked 17 May '16, 19:51

shreerockz15's gravatar image

accept rate: 33%

1 3 4 2 is also a correct DFS ordering for that graph. The difference is due to different ordering. For eg: this outputs as you wanted


answered 17 May '16, 20:01

vsp4's gravatar image

accept rate: 28%

Thanks! I recently learnt it so I thought that just like a learner I might have made a mistake. Thanks again!

(18 May '16, 00:32) shreerockz153★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 17 May '16, 19:51

question was seen: 562 times

last updated: 18 May '16, 00:32