Question

Provide pseudocode post-order traversal for general trees using stack.

Provide pseudocode post-order traversal for general trees using stack.

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

Using two stack:

1. Push root into Stack_One.

  • while(Stack_One is not empty)
    • Pop the node from Stack_One and push it into Stack_Two.
    • Push the left and right child nodes of popped node into Stack_One.
  • End Loop
  • Pop out all the nodes from Stack_Two and print it.

Using one stack:

1.1 Create an empty stack

2.1 Do following while root is not NULL

a) Push root's right child and then root to stack.

b) Set root as root's left child.

2.2 Pop an item from stack and set it as root.

a) If the popped item has a right child and the right child

   is at top of stack, then remove the right child from stack,

   push the root back and set root as root's right child.

b) Else print root's data and set root as NULL.

2.3 Repeat steps 2.1 and 2.2 while stack is not empty.

Add a comment
Know the answer?
Add Answer to:
Provide pseudocode post-order traversal for general trees using stack.
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
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