Where Traversal Is Used?

Where Traversal Is Used?

In-order traversal is very commonly used on binary search trees because it returns values from the underlying set in order, according to the comparator that set up the binary search tree. Post-order traversal while deleting or freeing nodes and values can delete or free an entire binary tree.

What is traversal example?

In Pre-Order traversal, the root node is visited before the left child and right child nodes. In this traversal, the root node is visited first, then its left child and later its right child. ... In the above example of binary tree, first we visit root node 'A' then visit its left child 'B' which is a root for D and F.

Why do we need inorder traversal?

In case of binary search trees, inorder traversal will traverse nodes in non-decreasing order. This is probably the easiest result if not the most common result. To traverse nodes in non-increasing order, inorder traversal but visiting right subtree before left subtree can be used.

Marcus Vance
Author

Marcus Vance

Marcus Vance is a cybersecurity auditor and technology writer dedicated to educating the public about online safety, data privacy regulations, enterprise security, and emerging cyber threats.