| Q & A Home |
| Math |
| Science |
| History |
| IT & Web |
| Programming |
| Health |
| Business |
| Arts & Humanities |
| Social Studies |
| Engineering & Technology |
| Arts & Entertainment |
| Humanities |
| Sports |
| Auto |
| Hobbies |
| Books and Literature |
| Electronics |
| Food & Drink |
| Jobs & Education |
| Law & Government |
| Travel & Places |
| People & Society |
| Beauty & Health |
| Animals & Plants |
| Other |
Obaidul Haque 29 Jun, 2024 11:55:50 PM 1 54
Best Answer: Trees can be traversed in multiple ways:
Depth-first traversal:
(a) Inorder (Left, Root, Right) : 4 2 5 1 3
(b) Preorder (Root, Left, Right) : 1 2 4 5 3
(c) Postorder (Left, Right, Root) : 4 5 2 3 1
Breadth-First or Level Order Traversal: 1 2 3 4 5
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)
Preorder traversal:
Algorithm Preorder(tree)
1. Visit the root.
2. Traverse the left subtree, i.e., call Preorder(left-subtree)
3. Traverse the right subtree, i.e., call Preorder(right-subtree)
Obaidul Haque 29 Jun, 2024 11:55:50 PM