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

2.3 Tree traversal (10 pts) Given T, the following binary tree: 15 21 10 19 24 4

ID: 3739585 • Letter: 2

Question

2.3 Tree traversal (10 pts) Given T, the following binary tree: 15 21 10 19 24 4) 8 12 67 and two tree walk algorithms, that both print the node keys along the way REcWALK(x) ITERWALK(T) 1 Let Q be an empty Queue 2 ENQUEUE (Q, T.root) 3 while Q is not empty 4 if x == NIL return 3 ifx.left?NIL 5 ifx.right?NIL 7 PRINT(?.key) RECWALKWRAPPER(T) REcWALK(x.left) PRINT(x.key) if x.right NIL RecWALK(x.right) ENQUEUE(Q,x.right) if x.left fNIL ENQUEuE(Q, x.left) 1 REcWALK(T.root) Assign each algorithm its unique, correct expected output on the console, among those listed below: 115,7,3,2,4,10, 8, 12,21, 19,24,22,67 2 2,4,3,8,12,10,7,19,22,67,24,21,15 3 2,3,4,7,8, 10, 12,15, 19,21, 22,24, 67 415,7,21,3,10,19,24, 2,4, 8, 12,22,67 5 67,22,24, 19,21, 12,8, 10,4,2,3,7, 15 6 15, 21,7,24, 19,10,3,67,22, 12,8,4,2 ITERWALK -- RECWALKWRAPPER

Explanation / Answer

answer of iterwalk is 6.

ths is because in this algorithm after printing a root element then its children are added from right to left order in the queue to be printed in the next iteration.

answer of recwalk is 2.

this is because in this algorithm the left most leaf is printed then the right node of it parent then the parent.it goes in this fashion recursively.