L11. Iterative Postorder Traversal using 2 Stack | C++ | Java | Binary Tree

preview_player
Показать описание

Find DSA, LLD, OOPs, Core Subjects, 1000+ Premium Questions company wise, Aptitude, SQL, AI doubt support and many other features that will help you to stay focussed inside one platform under one affordable subscription. Have a hassle free one stop solution for up-skilling and preparing.

Рекомендации по теме
Комментарии
Автор

Hi, hope you are well.


Find DSA, LLD, OOPs, Core Subjects, 1000+ Premium Questions company wise, Aptitude, SQL and many other time saving features under one affordable subscription. Have a hassle free one stop solution for up-skilling and preparing yourself.


takeUforward
Автор

We can also see it as preorder-> root left right
swap left, right -> root right left
reverse -> left right root
So in first stack we apply pre-order traversal code, and 2 stack is to reverse it, basically we need 2 stack as we can't move from child to parent in tree

codermal
Автор

This year's only video I have watched at 0.5x.

harshitmalhotra
Автор

we can also use the ans vector which we are going to return as the second stack, but in the end we will have to reverse the vector before returning it.

SaurabhSingh-nvjj
Автор

i shocked when i played this video at 1.75x speed, after read out description I understand what actually happened😂. Anyway but lec is awsome

_jamkhandedattatray
Автор

Understood the concept first and then wrote the code on my own and later found out that it is exactly same as in the video

got confidence....

JayPanchal
Автор

Striver, had to slow down the video speed to understand it better. 😂
Completed this as well.
Steps :
1. initial config : Take the root and put it in the 1st stack.
2. Now, take the top from the 1st stack and put it into the 2nd stack
3. After that, if the top in 2nd stack has left → add it in 1st stack. And if the top in 2nd stack has right → add it in the 1st stack.
4. Now again, take the top from the 1st stack and put it into the 2nd stack. Repeat step 2 & 3 untill 1st stack is empty.
5. Pop the element from the 2nd stack and print.

theSeniorSDE
Автор

Please likeeee, shareeee and :) Also follow me at Insta: Striver_79

Please watch it at 0.5x or 0.75x, I mistakenly uploded at 2x 🥺

takeUforward
Автор

only this video i watched at normal speed, else i watch at 2x.

sahilrao
Автор

You can make everyone understand in 2x too .. that's the quality in you.. Great man!

mohit
Автор

what is the intution behind this solution...you are directly junmping to the solution

DevanshuAugusty
Автор

I was not at all able to come up with this, I hardly give up on problems, this was impossible for me to think fr!

tanishq
Автор

Intutuion here is that if we observe the sequence, then stack 1 just holds the left and then right valuees just to make sure all right thing done first and then left
stack 2 just holds the root immediately so that it will come at the end and then right which was processed by stack 1 will store and then left

omi_iitb
Автор

Striver what is the intuition for using 2 stack 🤔?

Rebantaprat
Автор

explanation is so beautiful, so elegant, just looking like a wow

valiz
Автор

Can't believe on myself that I was able to crack the code of this one in one stack all by myself without any syntax errors! Thanks Striver

kingmysterio
Автор

I was already watching ur vids at 1.5x . But here:-) for a moment I thought my mind was processing the content slowly. lol. Anyways awesome lectures.

iamsalonitayal
Автор

hello sir this series is really great. I tried many series on the youtube but your's one is best thank you so much.

nandkishor
Автор

Rather than taking a stack we can save that in the resultant vector and then reverse it in the end We can save some space

letsrock
Автор

In Stack 1 we make
ROOT RIGHT LEFT ( like we did in preorder -> root left right )
Stack2 is used for reverse : -
if we reverse the Stack1 it will give Postorder which is LEFT RIGHT ROOT

namanchhabra
visit shbcf.ru