Iterative Postorder Traversal using one stack

  Рет қаралды 25,061

Vivekanand Khyade - Algorithm Every Day

Vivekanand Khyade - Algorithm Every Day

Күн бұрын

Пікірлер: 42
@sayakatta1836
@sayakatta1836 4 жыл бұрын
Anyone who has no idea about coding,he or she can easily understand what you are teaching. Amazing you are. Bring more and more videos
@freemente4731
@freemente4731 5 жыл бұрын
This will give a stack underflow on the 3rd condition part.... as you pop the last item of the stack and the stack becomes empty.... the loop will check the top of the stack which does not exist causing a stack underflow...... solution to that will be to include a condition after the pop to see if the stack is empty or not.. For example : while(root==stack.top()->right) { root=stack.top(); std::cout
@allan1827
@allan1827 4 жыл бұрын
yep;)
@anis_coc6227
@anis_coc6227 6 ай бұрын
Actor 🔥🔥🔥🔥 best teacher ever !!!💪🦾💪💪🔥🦾🔥🦾🔥🔥🦾🔥🦾🔥🦾☠️☠️☠️
@karthikk5895
@karthikk5895 6 жыл бұрын
The condition 3 while loop needs a check whether the stack is empty or not.
@bhagvatsinghrajput2313
@bhagvatsinghrajput2313 3 жыл бұрын
thank you so much sir you helped me a lot for understanding tree traversl
@ramum5424
@ramum5424 5 жыл бұрын
Here, after traversing the children of subtree 'M', if you check for this condition if(p==top.right) { print(top.data); pop(); } At this instance we have only one element 'a'(THE ROOT) in the stack. Now in the 2nd condition, you're again pointing node p to 'A' right child which is 'M', which we've already traversed. Hence causing an infinite loop. So this algorithm works well until traversing the last right subtree of root. We will be able to get the output without the root node in the answer but in an infinite loop. SOLUTION: modify 2nd condition as: (q is a dummy node which points to null) if(!s.empty()) { if(q==stack.top().right) { p=stack.top(); //here p is the root node print(p.data); //prints the root node stack.pop(); //ending infinite loop (now the stack is empty) p=null; } else p=s.peek().right; } else p=null; }
@tridevthakur5397
@tridevthakur5397 4 жыл бұрын
Sir plz continue to make such useful video Thank u sir😊😊
@DhananjayKumar-bd2jg
@DhananjayKumar-bd2jg 3 жыл бұрын
great explanation!
@batsunet
@batsunet 4 жыл бұрын
I love your videos! You've helped me so much in my programming!
@dmputube9
@dmputube9 4 жыл бұрын
p = root; while (true) { if (p) { push(p); p = p->left; continue; } if (isStackEmpty()) break; if (top()->right != null) { p = top()->right; continue; } // process node now currentNode = pop(); process(currentNode); if (! isStackEmpty() && top()->right == currentNode) { // avoid coming back to same node again and loop endlessly, process root of prior currentNode now currentNode = pop(); process(currentNode); } p = null; } believe this looks more clean, overall I trust iterative more than recursive. simply because I can still control size of stack, but not the stack size of recursion.
@surajverma8687
@surajverma8687 4 жыл бұрын
Nice explaination sir
@ashishswaraj2351
@ashishswaraj2351 4 жыл бұрын
3rd condition if(p=Top().right) is correct this should go to the B element .. so I think it's wrong
@durgashanker6491
@durgashanker6491 4 жыл бұрын
Hello Sir, can you please post tutorial on Recursion ?
@aabhishek4911
@aabhishek4911 6 жыл бұрын
One basic doubt , How will you come to the conclusion that 2 nodes are not the same ? if their values or left and right child are not same ? what if 2 nodes having same value and both being the leaf nodes?
@ucleminh1642
@ucleminh1642 3 жыл бұрын
How to use the Queue to Post-Order traversal binary tree
@vijayhathimare4520
@vijayhathimare4520 3 жыл бұрын
if (top().right != null) then ?
@allan1827
@allan1827 4 жыл бұрын
nice explNATION
@Understanding_the_world_withme
@Understanding_the_world_withme 4 жыл бұрын
Thank you sir
@rafaelaraujo7351
@rafaelaraujo7351 4 жыл бұрын
very good
@uditagrawal6603
@uditagrawal6603 5 жыл бұрын
Not working for binary tree : root=1, root.left = 2,root.right = 3, root.left.left = 4, root.left.right = 5,root.right.right = 6,root.left.left.left = 7
@naveen-dd3hu
@naveen-dd3hu 3 жыл бұрын
Node root=new Node(1) root.left=new Node(2) root.left.left=new Node(4)
@snehalumare4067
@snehalumare4067 4 жыл бұрын
Thank You....
@punittiwari7557
@punittiwari7557 5 жыл бұрын
Sir please make a video on Morris Traversal please sir
@svdfxd
@svdfxd 5 жыл бұрын
There is a video posted by Tushar Roy...
@vinaysingh2089
@vinaysingh2089 6 жыл бұрын
sir aap kaise h?? bahut din baad
@vivekanandkhyade
@vivekanandkhyade 6 жыл бұрын
i m good vinay.....soory for the gap...now i can dedicate more time.....keep watching
@an_son_mathew_
@an_son_mathew_ 3 жыл бұрын
💜
@ArpitDhamija
@ArpitDhamija 4 жыл бұрын
i slept 5 times while listening this
@pruthvirajk6019
@pruthvirajk6019 4 жыл бұрын
Did he ask you to watch ! lol ! Dont play jokes.
@samxsharan
@samxsharan 3 жыл бұрын
@Arpit 😂
@hhcdghjjgsdrt235
@hhcdghjjgsdrt235 2 жыл бұрын
I slept 2 times while reading your lengthy informative comment
@lalitkumarmehta6026
@lalitkumarmehta6026 5 жыл бұрын
Please provide code
@Snehal_Javheri
@Snehal_Javheri 4 жыл бұрын
Could you please provide cpp code...Thank You !
@Snehal_Javheri
@Snehal_Javheri 4 жыл бұрын
Sir I have designed code and executed...It is giving me segmentation fault...for STACK.TOP()->Right function....Please help me in this regards....Thank You ! Please send complete code- at s.r.javheri@gmail.com
@hhcdghjjgsdrt235
@hhcdghjjgsdrt235 2 жыл бұрын
I m new to coding and it may have some error. here it is C# void postOrDFS(TreeNode root) { Stack stack = new Stack(); stack.Push(root); HashSet prnted = new HashSet(); while (stack.Count!= 0) { TreeNode temp = stack.Peek(); if (temp.left != null && prnted.Contains(temp.left) == false) { stack.Push(temp.left); } else if (temp.right != null && prnted.Contains(temp.right) == false) { stack.Push(temp.right); } else { prnted.Add(stack.Pop()); Console.WriteLine(temp.val); } } }
@srajensingh4532
@srajensingh4532 6 жыл бұрын
Are sir kaha chale gaye the
@vivekanandkhyade
@vivekanandkhyade 6 жыл бұрын
soory for the gap...now i can dedicate more time.....keep watching
@amanahmed6057
@amanahmed6057 5 жыл бұрын
Sir hindi me padaa do (*˘︶˘*).。.:*♡
@hhcdghjjgsdrt235
@hhcdghjjgsdrt235 2 жыл бұрын
English sikhlo, hindi ka koi value nei hae IT field me
Iterative Inorder Traversal (Non-recursive)
16:50
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 58 М.
Iterative Preorder Traversal using Stack
12:37
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 25 М.
This Game Is Wild...
00:19
MrBeast
Рет қаралды 152 МЛН
Iterative Postorder traversal of binary tree using one stack
14:05
Tushar Roy - Coding Made Simple
Рет қаралды 116 М.
Iterative Postorder Traversal of a Binary Tree | Animation
27:56
Dinesh Varyani
Рет қаралды 16 М.
L10. iterative Inorder Traversal in Binary Tree | C++ | Java | Stack
11:14
INORDER SUCCESSOR in binary search tree[CODE Explained]
21:17
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 45 М.
C Programming Tutorial for Beginners
3:46:13
freeCodeCamp.org
Рет қаралды 14 МЛН
Cracking Enigma in 2021 - Computerphile
21:20
Computerphile
Рет қаралды 2,5 МЛН
How to STUDY so FAST it feels like CHEATING
8:03
The Angry Explainer
Рет қаралды 1,8 МЛН
Clean Code - Uncle Bob / Lesson 3
59:41
UnityCoin
Рет қаралды 355 М.
How To Think Like A Programmer
1:00:07
Coding Tech
Рет қаралды 2,1 МЛН