4.1.7.1 Operations on Tree (Insertion, Deletion, Traversal: In-order, Pre-order, Post-order; Searching)
Computational Structures
In a tree structure, there are some basic operations that help us manage and work with the data. Let's break them down:
- Insertion: Imagine you're adding a new family member to your family tree. Insertion is like finding the right spot in the tree and adding the new member there. We connect the new person to their parent in the tree, making sure they are part of the family structure. Here's how you can insert a new member into the Family Tree:
- Deletion: Sometimes, we need to remove a member from the tree. Deletion is the process of taking someone out of the family tree. We carefully remove them, making sure the rest of the tree still makes sense and stays connected.
- Traversal: Tree traversal like walking through the family tree to visit each member. There are different ways to do this, like starting from the top and visiting each person one by one, or visiting all the children of a person before moving to the next branch. There are three common types of tree traversals are there: In-order, Pre-order, and Post-order. We will use the following simple tree structure with numeric data to understand traversal functions more easily.