1 Tree traversal Given T, the following binary tree 19 12 15 21 13 18 34 and two
ID: 3728632 • Letter: 1
Question
1 Tree traversal Given T, the following binary tree 19 12 15 21 13 18 34 and two tree walk algorithms, that both print the node keys along the way: ITeRWALK(T) Let S be a stack x Troot PuSH(S, x) while S is not empty 1 REcWALK(x) 3 4 return 3 PRINT(x.key) 4 if x.righ NIL if x. leftNIL PUSH (S, x. left) xx.left REcWALK(x.right) elseif x.rightNI 6 ifx.leftNIL REcWALK(x.left) listed Pop(S) PRINT listed. key) if listed, right NIL 10 REcWALKWRAPPER(T) 1 REcWALK T.root) 12 13 14 PuSH (S, listed. right) x listed. right else x x.right Assign each algorithm its unique, correct expected output on the console, among those listed below: L 19,129, 3, 13, 15, 18,43, 21, 67, 34, 70 2 3,13,9,18, 15, 12,21, 34,70, 67,43, 19 3 3,9,13, 12,15, 18, 19,21,43,34,67,70 4 19,12,43,9,15,21,67,3, 13, 18, 34,70 5 19,43, 67,70,34,21,12,15,18,9,13,3 6 19,43, 12,67,21, 15,9,70,34,18, 13,3 ITERWALK REcWaLKWRAPPER _Explanation / Answer
ITERWALK traversing thr tree in POST ORDER:
Ans: [2]: 3, 13, 9, 18, 15, 12, 21, 34, 70, 67, 43, 19
RECWALKWRAPPER: print key then traverse right then traverse left
Ans: [5] : 19, 43, 67, 70, 34, 21, 12, 15, 18, 9, 13, 3
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.