Awesome q2a theme
0 votes
38 views

Depth first search is equivalent to which of the following traversal in Binary trees

  1. Pre – Order traversal
  2. Level Order traversal
  3. In – Order traversal
  4. Post – Order traversal
in Others by (53 points) | 38 views

1 Answer

0 votes

Option A is the correct answer

In PRE-ORDER traversal we first take the left node into consideration

and

In the case of DFS also, the same behaviour can be observed when it comes to the binary tree

by (731 points)
+2
why not post order ?
0
yes, post-order will be ans. rt??

because root printed at last.
0
visiting the nodes is different than printing the nodes
0
means??

U mean here visiting like post-order. but printing can be anything??
+1

@srestha @shaik_masthan

Answer is PRE-ORDER 

In DFS  you can traverse the tree either from Left-to-right or right-to-left.

 

In case of left-to-right, you can follow the same method as PRE-Order because in preorder also we generally visit the node for the first time and then print it, which is same as the left-to-right traversal in DFS.

But, if you start traversing the tree in Post-order manner then, in case of leaf node it seems to be perfect but in case of internal nodes which have two children as leaf node, parent node will be visited first but not be printed then left node will be visited and printed after that, parent node will be printed and then right leaf node will be visited printed but this output will never match to the DFS traversal’s output because parent node should be printed first in order to match the output with DFS output, and this is possible only in case of PRE-ORDER.

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
Welcome to GATE CSE Doubts, where you can ask questions and receive answers from other members of the community.
Top Users Jan 2020
  1. shashin

    1262 Points

  2. Deepakk Poonia (Dee)

    346 Points

  3. Vimal Patel

    343 Points

  4. Debapaul

    265 Points

  5. Satbir

    194 Points

  6. Pratyush Priyam Kuan

    158 Points

  7. tp21

    151 Points

  8. SuvasishDutta

    151 Points

  9. pranay562

    142 Points

  10. DukeThunders

    97 Points

Monthly Top User and those within 60% of his/her points will get a share of monthly revenue of GO subject to a minimum payout of Rs. 500. Current monthly budget for Top Users is Rs. 75.
3,085 questions
1,538 answers
9,232 comments
89,827 users