20 votes 20 votes If the binary tree in figure is traversed in inorder, then the order in which the nodes will be visited is ______ DS gate1991 binary-tree easy data-structures descriptive + – Kathleen asked Sep 12, 2014 edited May 8, 2021 by gatecse Kathleen 5.4k views answer comment Share Follow See 1 comment See all 1 1 comment reply rajoramanoj commented Aug 24, 2017 reply Follow Share @ arjun sir if this situation occurs in gate exam then what we do...???? is there any default case..??? 0 votes 0 votes Please log in or register to add a comment.
Best answer 29 votes 29 votes During the in-order traversal algorithm, the left subtree is explored first, followed by root, and finally nodes on the right subtree. In order traversal is $:4 \ 1 \ 6 \ 7 \ 3 \ 2 \ 5 \ 8.$ Keith Kr answered Sep 13, 2014 edited Apr 17, 2021 by Lakshman Bhaiya Keith Kr comment Share Follow See all 6 Comments See all 6 6 Comments reply Sumit1311 commented Jan 27, 2016 reply Follow Share Why node 5 is right child it can be both left or right child? 1 votes 1 votes asu commented May 23, 2016 reply Follow Share by default we consider node 5 as left child/.why here right 2 votes 2 votes sonu commented May 23, 2016 reply Follow Share @Arjun Sir Isnt order cannt be 41672583 ? Here nothing is mentioned whether 3 child subtree is in left or right. 3 votes 3 votes Arjun commented May 24, 2016 reply Follow Share yes, guess the pic is wrong and slanting edge was made straight, 6 votes 6 votes sid1221 commented Oct 25, 2017 reply Follow Share for 3 ary is it 41673258 ? 0 votes 0 votes vaibhavkedia968 commented Aug 27, 2020 reply Follow Share “then the order in which the nodes will be visited is … “ shouldn’t this imply the order in which the nodes are “visited” and not “printed”. 4 1 6 7 3 2 5 8 is the In order But here it is asking the order in which the nodes are visited, and not printed. So according to me the answer should be 7 1 4 6 3 5 2 8 (basically pre order) Can someone please clear this doubt? 2 votes 2 votes Please log in or register to add a comment.
12 votes 12 votes Two ans possible as the fig is little ambiguous Case 1:- if 5 is LHS of 3 Inorder:--4 1 6 7 2 5 8 3 Case 2:- if 5 is RHS of 3 inorder :- 4 1 6 7 3 2 5 8 Rajesh Pradhan answered Aug 26, 2016 Rajesh Pradhan comment Share Follow See 1 comment See all 1 1 comment reply Lakshman Bhaiya commented Oct 26, 2018 reply Follow Share In the given image clearly see $5$ is a right child of $3,$why you take $5$ is left a child of $3$, i mean two cases?? 0 votes 0 votes Please log in or register to add a comment.
2 votes 2 votes 41673258 is traversing possible for this problem Rishi yadav answered Oct 4, 2017 Rishi yadav comment Share Follow See all 0 reply Please log in or register to add a comment.
1 votes 1 votes 4,1,6,7,3,2,5,8 i did it in mind shashankrustagi answered Dec 9, 2020 shashankrustagi comment Share Follow See all 0 reply Please log in or register to add a comment.