Iterative Postorder Traversal of Binary Tree

  Рет қаралды 79,732

Tushar Roy - Coding Made Simple

Tushar Roy - Coding Made Simple

Күн бұрын

Пікірлер: 69
@HimanshuSharma1981
@HimanshuSharma1981 4 жыл бұрын
This guy was my junior in Grad School, and here I am learning Data structures from him. Kudos Tushar!
@kartikkankurte717
@kartikkankurte717 3 жыл бұрын
This is one of the underated channels
@nikhilsharad9553
@nikhilsharad9553 8 жыл бұрын
Amazing tutorial and your way of explanation is incredibly easy to follow. Thanks for such wonderful tutorials.
@dominiquesilva4756
@dominiquesilva4756 8 жыл бұрын
The method that you used made it very easy for me to understand.
@kevinmeraz8159
@kevinmeraz8159 3 жыл бұрын
Amazing. So simple and clear. Huge help. Thanks!
@satang500
@satang500 9 жыл бұрын
Wow I really like the idea of using two stacks. Writing correct code using only one stack without mistakes for a short time was quite challenging for me. As you commented I'll be expecting your video for using one stack too. :)
@vjnvisakh
@vjnvisakh 8 жыл бұрын
Thanks a lot ... had this single stack code ... but it was getting a bit confusing ( specially while printing the last node -- root). This code is much better and much more logical.Thank you once again Tushar
@xenobob2773
@xenobob2773 4 жыл бұрын
Love how the Indian guys start out with 'Hello Friends'.
@sachinrana309
@sachinrana309 5 жыл бұрын
These videos got me job!!!Thanks a lot
@punitoza84
@punitoza84 7 жыл бұрын
Thanks Tushar, your videos are helping a lot and making the data structures revision far less daunting.
@aakashbhatia
@aakashbhatia 2 жыл бұрын
easy to understand explanation
@sudipsaha9677
@sudipsaha9677 7 жыл бұрын
thanks ..u made my coding journey easy
@karthikr644
@karthikr644 7 жыл бұрын
Very useful, I was struggling to find an approach. This is a neat solution.
@AmoghNatu
@AmoghNatu 6 жыл бұрын
Thanks Tushar. This is a great solution. However, can you also explain the thought process of actually "arriving at the idea of using 2 stacks"? I'm struggling with that? Meaning, how did you get the idea in the first place that we can use 2 stacks to solve this? Can you also put here the thought process of arriving at this solution approach? Many thanks!
@albertt9097
@albertt9097 5 жыл бұрын
you can think of the 2nd stack as a visited tag (another approach to solving this). Or you can think of it as a 2nd push to the stack (a 3rd approach similiar to his other postorder vid)) Lastly you can see it as a reverse preorder visualized here.
@rituagrawal2218
@rituagrawal2218 8 жыл бұрын
Very nice video. Waiting for 1 stack postorder iterative traversal video . :-)
@koustavchatterjee2907
@koustavchatterjee2907 8 жыл бұрын
Java Single Stack Solution code.geeksforgeeks.org/n1XgVe
@rituagrawal2218
@rituagrawal2218 8 жыл бұрын
Thanks Koustav
@cantwaittowatch
@cantwaittowatch 8 жыл бұрын
Very nice tutorial Tushar. I tried using one single stack which needed a counter to keep track of how many times elements have been popped or visited so not to process them again. Gets bit tricky!!!
@fxjing
@fxjing 6 жыл бұрын
very good approach and explanation. thanks.
@muskanroxx22
@muskanroxx22 3 жыл бұрын
The method for using two stacks doesn't seem very intuitive, to me all the iterative codes for Preorder, Inorder, and Postorder don't seem intuitive enough. I am able to understand this but if someone would have asked me to directly come up with an iterative algorithm for traversals it wouldn't strike me. So, do we just learn this as an algorithm- it is what it is? I understand why it works looking at it's implementation, are we supposed to cram some of these things in order to prepare for our interviews?
@savantdude
@savantdude 3 жыл бұрын
let me guess.. you have trouble understanding the fundamentals of CS too?
@jeffereycountryman6771
@jeffereycountryman6771 3 жыл бұрын
very clear. Thank you very much.
@sidk5919
@sidk5919 7 жыл бұрын
thanks gautam gambhir
@tusharroy2525
@tusharroy2525 7 жыл бұрын
lol
@OverLordOfDa3rdWorld
@OverLordOfDa3rdWorld 4 жыл бұрын
Wow, amazing. Thank you so much!
@Null_pointer_exceptn
@Null_pointer_exceptn 9 жыл бұрын
Thanks. we can also use just 1 stack .
@kshawal
@kshawal 8 жыл бұрын
Thanks.. very easy to understand
@rishabh7011
@rishabh7011 4 жыл бұрын
Thank you sir ji
@FamousEgyptboy
@FamousEgyptboy 6 жыл бұрын
very well explained Thank you !
@shwetashukla7291
@shwetashukla7291 5 жыл бұрын
Thanks this was very helpful
@talaviss123
@talaviss123 6 жыл бұрын
very well explained
@engel15496
@engel15496 6 жыл бұрын
Nice video!
@naveennagar09
@naveennagar09 7 жыл бұрын
thank you sir..very well explained :)
@someshsharma1094
@someshsharma1094 8 жыл бұрын
Nice video... Please upload the Postorder Traversal with Single Stack... :)
@urrahman196
@urrahman196 3 жыл бұрын
Great video, please rename it using two stack
@ninadpradhan6566
@ninadpradhan6566 9 жыл бұрын
nice one bud!
@adhishmalviya2408
@adhishmalviya2408 4 жыл бұрын
Nice
@trangbui1910
@trangbui1910 5 жыл бұрын
thank you
@lohittalasila
@lohittalasila 8 жыл бұрын
Thank you :)
@yunus.yildirim
@yunus.yildirim 7 жыл бұрын
Can u add a new lesson for Internal Path Reduction trees?
@raghuram463
@raghuram463 5 жыл бұрын
Does Non-recursive algorithm and Iterative algorithm mean the same for Post order traversal of Binary tree?
@sumeetsood232
@sumeetsood232 4 жыл бұрын
can you please share link where this is done by reccursion, i cannot find it on your channel
@anuragdani9739
@anuragdani9739 8 жыл бұрын
I have a question, why have you implemented with Deque instead of Stack in the implementation?
@Kavishkhullar
@Kavishkhullar 4 жыл бұрын
this particular solution works but why is that? am i just suppose to memorize this logic/algorithm?
@apple2092
@apple2092 7 жыл бұрын
Thanks for sharing and it's a good solution. But I'd more like to know how to figure out such a solution?
@raghavchadha9133
@raghavchadha9133 8 жыл бұрын
data structures book Seymour lipschutz ....traversing binary tree using postorder ..
@bighneshsabat5374
@bighneshsabat5374 8 жыл бұрын
nice explanation,but i need one stack implementation.
@GaganGrewalf095
@GaganGrewalf095 8 жыл бұрын
It will basically be a Depth-First traversal ? We still need some kind of tracking collection to record visited nodes... is that correct ?
@wentaohu1706
@wentaohu1706 6 жыл бұрын
hi Gagan, I can answer your question, based on your assumption: "We still need some kind of tracking collection to record visited nodes", I wrote 2 algorithms to compare , a wrong one and a correct one, and each has detailed explanation, pls check my github repo: github.com/adalucky1234/Tree-Implementation-Java , go to master branch, then you easily find it. Thanks!
@shivajunna
@shivajunna 5 жыл бұрын
How did you come up with two stacks idea?
@creativity4416
@creativity4416 8 жыл бұрын
GOOD ONE (Y)
@raghavchadha9133
@raghavchadha9133 8 жыл бұрын
there is some method ..right child is negative ...what abt that ..it is not considered here
@raghavchadha9133
@raghavchadha9133 8 жыл бұрын
+Tushar Roy we are pushing right child as negative ..nd left child positive ...then. backtrack if no left child .. then process positive ...if there is negative right child ..then we make it positive nd again process it . .its done In my book ..bt my basic question is why we take right child as negative
@raghavchadha9133
@raghavchadha9133 8 жыл бұрын
+Tushar Roy its done using one stack ...bt I watched ur one stack ..bt there also ..there was no negative right child
@prabhakarpalanivel6472
@prabhakarpalanivel6472 6 жыл бұрын
This is more of a "reversed" preorder search followed by reversing the list using another stack
@SangharshSeth
@SangharshSeth 4 жыл бұрын
can you link to a true iterative implementation
@manvityagi6529
@manvityagi6529 4 жыл бұрын
The only bad thing is : He rarely shares the thought process and jumps directly into the solution.
@akshatjain6854
@akshatjain6854 4 жыл бұрын
rightly said
@savantdude
@savantdude 4 жыл бұрын
ahh right, everything has to be fed to you so you can regurgitate it in interviews!
@twndomn
@twndomn 4 жыл бұрын
Assuming this is Java, it's Not recommended to use Stack data structure, use Deque instead. Stack was implemented using vector in the early Java days, outdated and inefficient, also bad for job interview.
@swagatpatra2139
@swagatpatra2139 4 жыл бұрын
public List postorderTraversal(TreeNode root) { Deque q = new LinkedList(); List res = new ArrayList(); if(root == null) return res; q.addLast(root); while(!q.isEmpty()){ TreeNode curr = q.removeLast(); res.add(curr.val); if(curr.left!=null) q.addLast(curr.left); if(curr.right!=null) q.addLast(curr.right); } Collections.reverse(res); return res; }
@Manishkumar-zj9zw
@Manishkumar-zj9zw 7 жыл бұрын
void postorder(node n) { if(n==null) { return; } Stack s1=new Stack(); Stack s2=new Stack(); s1.push(n); while(!s1.isEmpty()) { n=s1.pop(); s2.push(n); if(n.rchild!=null) { s2.push(n.rchild); } if(n.lchild!=null) { s2.push(n.lchild); } } while(!s2.isEmpty()) { n=s2.pop(); System.out.print(n.data+" "); } } whats wrong with it??
@raghavchadha9133
@raghavchadha9133 8 жыл бұрын
pls reply sir
@hum2712
@hum2712 6 жыл бұрын
Hindi m padhiye sir please
Iterative Preorder Traversal of Binary Tree
6:39
Tushar Roy - Coding Made Simple
Рет қаралды 67 М.
Iterative Postorder traversal of binary tree using one stack
14:05
Tushar Roy - Coding Made Simple
Рет қаралды 116 М.
Turn Off the Vacum And Sit Back and Laugh 🤣
00:34
SKITSFUL
Рет қаралды 2,8 МЛН
This Game Is Wild...
00:19
MrBeast
Рет қаралды 152 МЛН
За кого болели?😂
00:18
МЯТНАЯ ФАНТА
Рет қаралды 3 МЛН
Iterative Inorder Traversal (Non-recursive)
16:50
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 58 М.
Tree Traversal Spiral Order
17:46
Tushar Roy - Coding Made Simple
Рет қаралды 43 М.
Iterative Postorder Traversal of a Binary Tree | Animation
27:56
Dinesh Varyani
Рет қаралды 16 М.
Iterative Postorder Traversal using one stack
34:48
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 25 М.
Data structures: Binary Tree
16:17
mycodeschool
Рет қаралды 1,4 МЛН
Iterative Inorder Traversal of Binary Tree
10:30
Tushar Roy - Coding Made Simple
Рет қаралды 122 М.
Post Order Traversal of Binary Tree (Iterative Using 1 Stack)
23:16