So I was doing some questions on backtracking and it suddenly hit me, that the implementation of depth first search is same as backtracking. Are they really the same or is my concept going wrong?
Asked
Active
Viewed 54 times
0
-
You've got it somewhat backwards. Backtracking is an implementation of tree traversal. – n. m. could be an AI Jun 06 '22 at 06:21
-
@n.1.8e9-where's-my-sharem. oh i see. thanks for clearing it up! – Anirban Chakraborty Jun 06 '22 at 06:51
-
There are two different questions: one about tree traversal and the other about DFS => no answer. – Jun 06 '22 at 08:34
-
@YvesDaoust well if I'm not wrong DFS is a tree traversal algorithm. I just want to know if that has any relation with backtracking. – Anirban Chakraborty Jun 06 '22 at 10:42
-
Yes, backtracking is a tree traversal as well. – Jun 06 '22 at 13:43
-
A backtracking search is a depth-first traversal of an implicit graph (not necessarily a tree): https://en.wikipedia.org/wiki/Implicit_graph. – Matt Timmermans Jun 07 '22 at 12:32
-
Backtracking to me implies that you're planning on pruning off parts of the search space, whereas a tree/graph traversal is just a traversal--visit all of the nodes. The whole point of backtracking is to _not_ visit all of the nodes if you can possibly help it. For example, solving the n-queens problem with backtracking, you don't just traverse all the nodes, you detect when an unsolvable position has arisen and you backtrack before wasting time exploring that branch further. Does [this answer](https://stackoverflow.com/a/70173332/6243352) basically resolve the question in spite of the title? – ggorlen Jun 08 '22 at 16:05