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

Let root be a reference to the root of a BST, s denotes a stack What does the fo

ID: 3696426 • Letter: L

Question

Let root be a reference to the root of a BST, s denotes a stack

What does the following pseudo code do for the tree below?

s.push (root);

while (!s.empty ()) {

tmp = s.pop ();

print (tmp.item);

if (tmp.right != null) {

s.push (tmp.right);

}

if (tmp.left != null) {

s.push (tmp.left);

}

}

Answer:

If we change s be be a queue, and s.push () to be s.insert (), as well as s.pop () to be s.remove () what does the modified code do for the tree?

Amswer:

elence to the root of a BST,s denotesa What does the following u) following pseudo - code do for the tree below?

Explanation / Answer

Answer:

The pseudocode is the implementation of post order traversal of a binary search tree ,it is a snippet of code where we get

as output after the execution of all lines of code.Here the concept is to navigate down to leftmost node using left pointer.On navigating down push the root and root’s right child on to stack. On reaching the leftmost node display it if it doesn’t have any right child and if it has a right child then modify the root element so that the right child is oganised before the root.

Answer : 2 - 9 - 3 - 7 - 7 - 42