hello everyone
So after we finished building the Binary Search Tree, Aarav confidently said,
“Traversal? Easy. It’s just printing stuff.” Rahul looked at him like he just failed recursion 101 and replied, “Bro… there are THREE types of tree traversals. THREE. Try not to break the tree.” And that’s how today’s adventure of Preorder, Inorder, and Postorder began.
What’s Happening Here?
We’re still working with the same BST, but now we’re exploring it in different ways:
Preorder (Root - Left - Right)
Rahul took this one because he likes being first everywhere . He literally starts by printing the node itself before checking anything else like entering a room and announcing, “Rahul has arrived!”
Inorder (Left - Root - Right)
Aarav said this one is “the most peaceful” because it gives sorted output. He liked it because he doesn’t need to think, just go left then root then right. Simple enough for him .
Postorder (Left - Right - Root)
I (Daksh) handled this one. Why? Because I always clean up last and Postorder prints the node at the end. Left subtree, right subtree, and THEN the node. Perfect for someone who finishes everything “later” .
How We Divided the Work
Rahul: Did Preorder instantly
“ROOT first, everything else later. Just like my priorities.”
Aarav: Showed off Inorder
“Sorted output, thank you very much.”
Me (Daksh): Printed Postorder
“This feels like rewriting an exam last minute.
Code:
| ← Previous | 🏠 Homepage |
No comments:
Post a Comment