Question

(4 marks) Consider the binary tree shown in Figure 8. Perform the iterative pre-order tree traversal using a stack as shown t

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Page NO. Date: Solution STEPS TO BE FOLLOWED : create an empty stack and push root node to stack 42 S → so while stack is not

Page No. Date: 012! 42 3 12 29 67 19 55 60 85 es 8.0/P: 42 3 191 12 29 67 19 55 60 35 es 9. 01P 42 3 19 12 29 67 19 55 60 | 3

For the first stack, the value on the stack before entering the loop is the root which is 42 and for the rest of the stacks, iteration wise values have been shown. The visited if needed, because it is not asked in the question, for each iteration will be all the nodes that had been pushed into the stack till that iteration(include the nodes which have been popped too because they were also pushed into the stack once)

Add a comment
Know the answer?
Add Answer to:
(4 marks) Consider the binary tree shown in Figure 8. Perform the iterative pre-order tree traversal...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Suppose a binary tree data (in tiny written size) is stored in an array (A) as...

    Suppose a binary tree data (in tiny written size) is stored in an array (A) as given below and root is placed at “0”index. Note the array indices are in larger written size (0 to 74). Show the traversal data of the given tree for a)      In-Order Traversal b)     Post Order Traversal A 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 3 28 13 36 15 9 22 44 7 10 75 33 19 15...

  • Trees Traversals Please write a Java program to traverse a binary tree in in-order and pre-order,...

    Trees Traversals Please write a Java program to traverse a binary tree in in-order and pre-order, and to plot a binary tree into a 2-dimensional array. You may write many recursive methods for this project. You are not allowed to use any existing Java classes such as ArrayList or Vector or Tree. Please stop your program if the user enters 0 as the tree selection. Your program must run the following Test Case 1 plus two more test cases to...

  • Trees Traversals Please write a Java program to traverse a binary tree in in-order and pre-order, and to plot a binar...

    Trees Traversals Please write a Java program to traverse a binary tree in in-order and pre-order, and to plot a binary tree into a 2-dimensional array. You may write many recursive methods for this project. You are not allowed to use any existing Java classes such as ArrayList or Vector or Tree. Please stop your program if the user enters 0 as the tree selection. Your program must run the following Test Case 1 plus two more test cases to...

  • 1 Binary Search Trees (25 points) Consider the binary tree as shown in Figure 1. 9...

    1 Binary Search Trees (25 points) Consider the binary tree as shown in Figure 1. 9 5 15 10 17 8 Figure 1: Binary Tree: The letter next to each node (e.g., a, b) denotes the tree node, and the number inside each node is the key. 1.1 Correctness (10 points) Is this binary tree a valid binary search tree? In other words, does it satisfy the binary search tree property? If not, which node(s) violates the binary search tree...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT