Binary Trees
Binary Trees
GROUP 5
TREE TRAVERSAL:
There are three common ways to traversal a
binary tree:
Inorder Traversal: Left subtree, root, right
subtree.
Preorder Travelrsal: Root, left subtree, right
subtree.
Postorder Traversal: left subtree,right
BINARY
subtree, SEARCH
root.
TREES:
A Binary Search Trees (BSTs) is a fundamental
data structure in computer science that
organizes data in a hierarchical manner. It has
the following properties:
PROPERTIES:
1. Node Structure: Each node in a
BTS contains three parts:
Data: the value stored in the node.
Left Child: A pointer to the left child node.
Right Child: A pointer to the right child
node .
2. Ordering Property : For any node in the
BTS:
All nodes in its left subtree have values less
than the node’s value. All nodes in its right
subtree have values greater than the node’s
value.
Output:
2.IMPLEMENTNG BINARY TREES
Implementing a binary tree involves creating a
data structure to represent the nodes and their
connections.
BASIC CREATING A
STRUCTION OF BINARY TREE
A NODE:
COMMON OPERATIONS ON BINARY
TREES:
1. Traversal:
Inorder Traversal: Left, Root, Right
Preorder Traversal: Root, Left, Right
Postorder Traversal: Left, Right, Root
2. INSERTION
Find the appropriate position to insert the
new node based on a specific order (e.g.,
sorted order for binary search trees).
Create a new node and link it to the parent
node.
3.DELETION
Find the node to be deleted.
Consider three cases:
Node with no children: Simply remove the
node.
Node with one child: Replace the node
with its child.
4. SEARCHNG
•Traverse the tree, comparing the data at
each node with the target value.
•If a match is found, return the node;
otherwise, continue the search.
Output: