I have skipped Morris Traversal for the past 7 years because I never understood it. Turns out, I only had to watch this 10 minute clip. Thanks a ton man.
there is a problem at 6:45 , after visiting -1 , we got to 2 , then we begin finding predecessor of 2 , Alas , finding predecessor of 2 means going right most in left sub-tree of 2 , here left subtree is -1 , then lets find predecessor ,-1 -> right = 2 , then 2-> right = 5 , 5-> right = 6 , 6-> right = 8 , 8 ->right = 10 , we are moving in totally different direction ....now . Actually this must stop when predecessor is found , but for predecessor , we keep moving right ? Edit: Now I saw the final code , while finding predecessor , you solved the problem by doing , predecessor-> right = current , then break .
Tushar, Great effort on the explanation. But, it seems your algorithm on the board was incomplete (like when the predecessor->right hits the current item itself, then it should stop). Although, you do talk about it while you showcased the code. Also, When you said current becomes current-> right @7:27 , you should actually be pointing at the last else section of your algorithm.
Wow the intro is so good!! now I understand why thread(link) is needed! bc we have to come back root, without stack or recursion! wow Thanks my teacher!!!
There's a LOT of bad articles poorly explaining this, and I gave up after checking a few. This cleared it up pretty quickly. I do wish in his first pass he hadnt abstracted findPredecessor() into some invisible function.
Hi Tushar. I want to thank you for this video. I looked at almost all sources that explain morris traversal but yours actually made everything clear in my mind. Keep making more videos like this. Thanks again.
Excellent explanation of Morris Algorithm !! keep up the good wrk Tushar !! I keenly follow your videos and they are immensely helpful in understanding concepts of Compute rScience.
It’s a good explanation for those looking in to the problem already and stuck with solving it. For those looking in to the problem first time, it would help if the pace of explanation is bit slower.
Thanks for your hard work for making such nice videos! But it would be great if the video explains algorithm derived from concept behind it. What I understand, concpet is the first thing then algo comes. You explan such a way where algo comes first then explain the concept based on the algo! Thank you!
I think the worst case time complexity will be O(n^2). Correct me if I am wrong. Coz we will have to find inorder predecessor for all nodes. And in case of skwed tree, it will take O(n^2) time.
It should be (predecessor.right != current || predecessor.right != null) i.e. instead of && it should be || as both conditions cannot be true at the same time ....
that's the whole point only one needs to be true to exit the loop, if you add || (or) the loop would execute infinitely because like you mentioned both can never be true at the same time.
came here when I didn't get the geeksforgeeks explanation. you have explained it lucidly.
I came like that as well. Lol!
same her bro..
Me too
Me too :-)
Me too:}
Good luck to everyone working hard to be at good tech companies. Thank you for the explanation.
so nice 😊
Thank you Tushar! Your video is always a guarantee of crystal clarity. Kudos!
Thanks for your explanation! I was confused about Morris Traversal, but you video make me clear now.
thanks, sir really nice explanation....!
Great Explanation sirji...
Best explanation ever. Better than pepcoding, better than Striver.
Same thoughts
Man I spent like 2 hours trying to understand the code, but visually seeing it step by step made it finally make sense, thanks!
OK man
I have skipped Morris Traversal for the past 7 years because I never understood it. Turns out, I only had to watch this 10 minute clip. Thanks a ton man.
Great content but this dude is the personification of the universal example of "how NOT to talk while talking to the audience"
Looking For Same Logic Small Code ?
while(root){
if(!root->left){
coutright)suck = suck->right;
suck->right = root;
suck = root->left;
root->left = NULL;
root = suck;
}
}
HAPPY LEARNING :)
And Yes I wanted To Name "suck" ...
Thank you! This was the best explanation I found. Instead of going straight into algorithm, Tushar explained the thought behind it. Great job.
Don't you spit whenever you say "t"?
Almost I gave my 2 hours to understand this algorithms on others channel but when I watched this video I got it. Great explanation.
Out of all Morris algorithm explanations out there, yours is so much better. Thank you!
Patience, friends. Bit by bit.
Nice explanation sir...
there is a problem at 6:45 , after visiting -1 , we got to 2 , then we begin finding predecessor of 2 ,
Alas , finding predecessor of 2 means going right most in left sub-tree of 2 ,
here left subtree is -1 , then lets find predecessor ,-1 -> right = 2 , then 2-> right = 5 , 5-> right = 6 , 6-> right = 8 , 8 ->right = 10 , we are moving in totally different direction ....now .
Actually this must stop when predecessor is found , but for predecessor , we keep moving right ?
Edit: Now I saw the final code , while finding predecessor , you solved the problem by doing , predecessor-> right = current , then break .
thank you for the video!! but at 7:27 current = current.right, but you were pointing to the wrong place on the white board.
Tushar, Great effort on the explanation. But, it seems your algorithm on the board was incomplete (like when the predecessor->right hits the current item itself, then it should stop). Although, you do talk about it while you showcased the code. Also, When you said current becomes current-> right @7:27 , you should actually be pointing at the last else section of your algorithm.
exactly, i was also confused by that pointing...
Wow the intro is so good!! now I understand why thread(link) is needed! bc we have to come back root, without stack or recursion! wow Thanks my teacher!!!
People who are looking for Morris POSTORDER Traversal algorithm and working solution, please visit www.thealgorists.com/Algo/Tree/MorrisPostorder
There's a LOT of bad articles poorly explaining this, and I gave up after checking a few. This cleared it up pretty quickly. I do wish in his first pass he hadnt abstracted findPredecessor() into some invisible function.
Thank You
0:01 turn on subtitles and see Tushar's name 😂😂
I've watched this like 10 times xD
public List inorderTraversal(TreeNode root) {
List res = new ArrayList();
TreeNode curr = root;
while(curr!=null){
if(curr.left == null){
res.add(curr.val);
curr = curr.right;
}
else{
TreeNode pred = findPred(curr);
//link back if right null
if(pred.right == null){
pred.right = curr;
curr = curr.left;
}
// if right not null, we have visited, unlink
else{
pred.right = null;
res.add(curr.val);
curr = curr.right;
}
}
}
return res;
}
TreeNode findPred(TreeNode node){
TreeNode current = node;
node = node.left;
while(node.right != null && node.right != current) node = node.right;
return node;
}
Hi Tushar. I want to thank you for this video. I looked at almost all sources that explain morris traversal but yours actually made everything clear in my mind. Keep making more videos like this. Thanks again.
thhooo
The last, please like this video..damn he spoke at 3x!
Very Good Explanation Thanks
Excellent explanation of Morris Algorithm !! keep up the good wrk Tushar !! I keenly follow your videos and they are immensely helpful in understanding concepts of Compute rScience.
Thank you great explanation
Thanks tushar For explaining in simple manner with algorithm and code.
Awesome explaination!!
Why not to use threaded three in the first place?
Very good explanation!!
Please use a good mic or else edit your audio too
why time complexity is O(n)?
Clean and precise explanation !!
Awesome man... Nice explanation
Super good explanations!
The best video about morris! Love your video!
It’s a good explanation for those looking in to the problem already and stuck with solving it. For those looking in to the problem first time, it would help if the pace of explanation is bit slower.
very clear thank you so much
Thank you! This is the most thorough video explanation on Morris Traversal that I have been able to find.
Thanks for your hard work for making such nice videos!
But it would be great if the video explains algorithm derived from concept behind it.
What I understand, concpet is the first thing then algo comes. You explan such a way where algo comes first then explain the concept based on the algo! Thank you!
Very nice explanation 🙌🙌
Explanation is Awesome !
Loved your explanation
Nice thoking....
Joking aside , nice tutorial.
thanks for the explanation
Can we use this to traverse inorder reversely(right->root->left) ? ig yes ...reply if not
Nice explanation!
Good Explanation. :)
very well explained..thank you so much
we need a way to come back to 5
u Hv written it very small
I am very thankful for your clear explanation and pronunciation!
how is the time complexity O(n)... we are revisiting nodes in a loop many times...
Excellent explanation !!
Awesome! Thank you Tushar!! :D
Great explaination!
Thank you very much for the clear explanation.
I love this guy
Nice Explanation
Finally got it ....
Time complexity?
chummi explaination
his diagram is clean and clear enough to demonstrate the concept
Explanation was very nice , thanks for the vid :D
Nice explanation
Nice explanation
Explanation is excellent , simple request is to talk at steady pace. a bit slower ...then it will be much easier to absorb :)
Nice explained♥️
Thanks, best video on this algorithm!
Are u using recursion or stack to find inorder predecessor
ruclips.net/video/_AQdLuOvjPw/видео.html
nice explanation
The best explanation I found on youtube so far
nice explanation
awesome explanation Much much better than Geeks for geeks
Very clear!
Thank you!
very clear explanation!
Thank you!
Best person to explain complex topics. I wonder why his channel is not very famous?
A+++++ explanation. Really appreciate it!
nice video!
Best explanation of Morris traversal on the internet
you rock!
I think the worst case time complexity will be O(n^2). Correct me if I am wrong. Coz we will have to find inorder predecessor for all nodes. And in case of skwed tree, it will take O(n^2) time.
The TC will still be 2N which is O(N) as the nodes visited at max twice.
your speaking is way better than others
good one!!
Then on Then
could you please make similar videos for Morris traversal for priorder and post order traversal
It should be (predecessor.right != current || predecessor.right != null)
i.e. instead of && it should be || as both conditions cannot be true at the same time ....
that's the whole point only one needs to be true to exit the loop, if you add || (or) the loop would execute infinitely because like you mentioned both can never be true at the same time.
Thank you for all your videos :)
Great walkthrough, thank you!
Amazing
Precise and sweet explanation. thanks :)