checkout the findPredecessor() function here - github.com/chkarthik1729/Programming-Practice/blob/master/Data%20Structures/Trees/MorrisInorderTreeTraversal.c
Before visiting 13, we're checking whether there is anything in the left tree. If there is, the entire left subtree needs to be processed before we process 13. The last node in the left subtree that will be processed is it's inorder predecessor, 11. So, we think in terms of predecessor.
If we are calculating predecessor on the fly, and we know predecessor is the right most element in the left subtree, so when we check for condition predecessor -> right exist don't you think we will get the root node as predecessor as we earlier pointed right of predecessor to root, as a result of which when we find predecessor second time , right most node of the left subtree will be the root as we made a connection from prev_pred and root node. in short the predecessor we get first time and the predecessor we get after we have made connection will be different. If i was't clear reply and ill try to explain with examples
I would assume that the function find predecessor makes a check to see if the predecessor found==current, as mentioned in this article www.geeksforgeeks.org/inorder-tree-traversal-without-recursion-and-without-stack/
Good job bro. Thanks a lot. Publish more videos, you explain well. With a month or so of videos you may reach thousands of subscribers. :)
Good video brother. Waiting for more.
Thanks for the appreciation brother. Will do a video on arrays shortly.
Awesome expalantion, thanks (y)
nice explanation!
all the best😊
great video,Nice way of explaining.
Awesome explanation, thanks brother :)
great explanation ....very helpful .. GOOD JOB! :D
Superb brother !
hi Karthik, good content, please do videos on DP, greedy, graphs etc
Thanks man, great vid
thanks brother
😢sorry ,why we need to set predecessor->right = Null
Can you make a tell me how you became so good in competitive programming.
I am so bad at it.
Good video but how to find predecessor?
checkout the findPredecessor() function here - github.com/chkarthik1729/Programming-Practice/blob/master/Data%20Structures/Trees/MorrisInorderTreeTraversal.c
maximum from the left subtree.
Bro why are you not making morr video
Great explanation but plz just speak not so hurriedly.
13 is coming after 11, so 13 is successor of 11 right? why we say as predecessor. I mean, i dont know just want to clarify it.
Before visiting 13, we're checking whether there is anything in the left tree. If there is, the entire left subtree needs to be processed before we process 13. The last node in the left subtree that will be processed is it's inorder predecessor, 11. So, we think in terms of predecessor.
Good explaination but you're talking so fast (like me :P) . Had to rewind multiple times.
why we are removing links after visiting , what will happen if we doesn't remove it.........?
If we modify the tree, any further operations on the tree would not behave as expected.
@@karthikchennupati6177 what would be the time complexcity of this algo ?
Time Complexity: O(n) - The control gets passed onto any node atmost twice. (1. Initially and 2. After processing left subtree)
If we are calculating predecessor on the fly,
and we know predecessor is the right most element in the left subtree,
so when we check for condition predecessor -> right exist don't you think we will get the root node as predecessor as we earlier pointed right of predecessor to root,
as a result of which when we find predecessor second time , right most node of the left subtree will be the root as we made a connection from prev_pred and root node.
in short the predecessor we get first time and the predecessor we get after we have made connection will be different.
If i was't clear reply and ill try to explain with examples
I would assume that the function find predecessor makes a check to see if the predecessor found==current, as mentioned in this article www.geeksforgeeks.org/inorder-tree-traversal-without-recursion-and-without-stack/
bhai why so angry