It seems to me like pre-order traversal and DFS are same as in both the cases we traverse from root till the left branch and back to root and then to the right branch recursively. Could any please correct me if I am wrong?
Thanks in advance!
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.Sign up to join this community
pre order traversal is a traversal, it visits every node in a binary tree
Depth First Search is a search, it goes around an arbitrary graph looking for a certain node (that it works best in a non cyclic graph (a.k.a. tree) is irrelevant)
this alone is a large enough difference to call them difference names
Yes, but it should be the opposite way:
DFS is similar to
PreOrder is more relevant to binary trees and parsers.
It is used to compare with other traversal orders of a binary tree:
Topological Sort is similar to Post Order traversal (push the node into stack after visiting all the adjacent nodes).
To traverse a binary tree in Preorder, following operations are carried-out
That is in the below image the pre order traversal would be, 1,2,3,6,4,5,7,8,9,10,11,12
In the same image 1,2,3,4,5,6,7,8,9,10,11,12 would be for DFS
Pre Order Source : Wiki