Inorder,preorder,postorder will only work on bst?

is these traversals were only for a binary tree ?? will they work on normal tree ??

Pre-and-Post Order: Yes; works exactly the same way for a non-Binary Tree as for a Binary Tree.

In-order: Doesn’t inherently make sense - you’ll have to come up with a notion of what it means for a subset of a node v's children to be “to the left of” v and for the complementary subset of v's children to be “to the right of” v. Once you’ve decided how to perform this partitioning, it’s easy.

4 Likes