How can the algorithm backtrack up, if each node only holds a left and right pointer? This is the part that's confusing me the most. Also, how would the algorithm recognize that the node that it's backtracking up to is the correct one? What is the algorithm for that?
The backtracking is a property of recursive functions. Take for example:
function f(n) print n if n>=1 then f(n-1) end print n + "again!"
end
What happens is that, if i call f(2), f(2) will proceed to call f(1). Notice how, that at this point of time, the first call for f isn't finished yet, but it must wait till f(1) is done, and it will "automatically" backtrack to f(2) to print "2 again!"
Hope this is clear. Look up recursion or leave another comment if you need more help!
@lcc0612 Thank you very much for your reply! I had a simple concept of recursive functions, but never knew that recursive functions return to previous calls. Thanks to you, I now understand how this works :)
@lcc0612 I've been having trouble with recursion for a long time, and I always avoid it, but here it seems it can not be left out. Can you recommend any good videos on recursion that would help me understand the binary tree sorting algorithms?
Thanks a lot for that! My understanding of post-order traversal is rather shaky, and I originally had a segment that explained it, but it looked wrong so i took it out. At least now I know where the mistake is! =D
I originally incorporated that into this episode, but there were some errors and I didn't have time to re-record, so I had to cut out some stuff, and remove post-order traversal completely. I'l see what I can do about this!
Do you have to catch a bus? The video is very fast to understand.
montee322 2 months ago 2
How can the algorithm backtrack up, if each node only holds a left and right pointer? This is the part that's confusing me the most. Also, how would the algorithm recognize that the node that it's backtracking up to is the correct one? What is the algorithm for that?
NeoXC 10 months ago
@NeoXC
The backtracking is a property of recursive functions. Take for example:
function f(n) print n if n>=1 then f(n-1) end print n + "again!"
end
What happens is that, if i call f(2), f(2) will proceed to call f(1). Notice how, that at this point of time, the first call for f isn't finished yet, but it must wait till f(1) is done, and it will "automatically" backtrack to f(2) to print "2 again!"
Hope this is clear. Look up recursion or leave another comment if you need more help!
lcc0612 10 months ago
@lcc0612 Thank you very much for your reply! I had a simple concept of recursive functions, but never knew that recursive functions return to previous calls. Thanks to you, I now understand how this works :)
NeoXC 10 months ago
@lcc0612 I've been having trouble with recursion for a long time, and I always avoid it, but here it seems it can not be left out. Can you recommend any good videos on recursion that would help me understand the binary tree sorting algorithms?
they0killed0kenny 3 months ago
@they0killed0kenny
To be honest, I haven't really come across any that's really simple and easy to understand. I'll send you a message if I ever see one.
lcc0612 3 months ago
Wow you talk fast!
grayman105 10 months ago
Way too fast....
mikeye9 1 year ago
Thanks for the help.
meedowi 1 year ago
@meedowi
Cheers! Glad I could be a help!
lcc0612 1 year ago
great job
cloudgiant 1 year ago
@cloudgiant
Thank you very much! I'm glad I could be of help!
lcc0612 1 year ago
Preorder and Inorder are correct. Great Work!
Postorder is incorrect.
The following rule applies to postorder. Postorder will always end with the root.
2 1 4 3 7 8 11 10 9 6 5
Post Order pseudocode
If root is null return
Postorder(left)
Postorder(right)
Postorder(root)
Reference: Java Software Structures by Lewis Chase
cody8092 1 year ago 4
@cody8092
Thanks a lot for that! My understanding of post-order traversal is rather shaky, and I originally had a segment that explained it, but it looked wrong so i took it out. At least now I know where the mistake is! =D
lcc0612 1 year ago
Fantastic Video! Bravo!
BourneInDenver 1 year ago
@BourneInDenver
Thanks! Glad you found it helpful!
lcc0612 1 year ago
thanks! that was interesting..
egeneral27 1 year ago
u should do one on traversal of trees
zachgoestoeuro 1 year ago
@zachgoestoeuro
I originally incorporated that into this episode, but there were some errors and I didn't have time to re-record, so I had to cut out some stuff, and remove post-order traversal completely. I'l see what I can do about this!
lcc0612 1 year ago