Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1 Tree traversal Given T, the following binary tree and two tree walk algorithma

ID: 3726572 • Letter: 1

Question

1 Tree traversal Given T, the following binary tree and two tree walk algorithma, that both prat tbr todr lays the way TERWALKT 1 Let S be a stack PusSx) while 5 is not empty listed POP(5) PuxT listed.key) if listed. ryht 10 PusH S, listed night x listed. right 12 else xx.nght Assign each algorithm its snique, conmect expected output on the console, among those listed below 19,12,9,13,15,18,43,21,67,34,70 ® 13,9, 18, 15, 12,21,34, 70,67,43, 19 33.913,12,15,1,19,21,43,34,67,70 4 19 12 43,9,15,21,67,3,13, 18, 34,70 19,43,67,70,34,21, 12, 15, 18,9,13,3 19.43 127.21,15,9,70,34, 18,13,3 ITERWALK 2 Binary Search Tree property la the tree represented in exercise (1) a BSTY Explain 3 In construction We inaert keys in an empty BST, in the order listed below 10,4,5, 12,1,634,50,203 Assumisg we use the insertion algaet m Th18-1NSIR7 apaedCLAS, 123, dzaw the tea alting tree.

Explanation / Answer

Q1.

Tree Traversal:

(a) IterWalk:

In this algorithm, we are using a stack to keep track of nodes.

First, we keep putting the left nodes in stack till reaching a node with no left child. After that, we check if it has a right child or not. If it does not have a right child then print the last left child ( 3 in this case) with poping that child from stack also. Now print the stack node ( 9 in this case) and go for the right child ( 13 in this case).   

By following this, answer to this is 3rd one

[ 3 , 9 , 13 , 12 , 15 , 18 , 19 , 21 , 43 , 34 , 67 , 70 ]

(b) RaceWalk:

In this algorithm, we are just printing the root element and keep moving toward right and print the right node till the leaf node and then move towards left tree.

By following this pattern, answer is 5th one

[ 19 , 43 , 67 , ....]