Tree Traversals Unlike linear data structures (Array, Linked List, Queues, Stacks, etc) which have only one logical way to traverse them, trees can be traversed in different ways. Following are the generally used ways for traversing trees. Example Tree Please see this post for Breadth First Traversal. Inorder Traversal: Algorithm Inorder(tree) 1. Traverse the left subtree, i.e., call Inorder(left-subtree) 2. Visit the root. 3. Traverse the right subtree, i.e., call Inorder(right-subtree) Uses of Inorder In case of binary search trees (BST),
Read full article from Tree Traversals | GeeksforGeeks
No comments:
Post a Comment