Data sturcture and algorithm week 6
Data sturcture and algorithm week 6
Semester – II Semester
EA2331201010152
1. Explain the types of tree data structure with a neat diagram.
1. Binary Tree:
o A binary tree has a maximum of two children per node (left child and right child).
o The first node (without a parent) is called the root node.
o Binary trees are further classified based on additional properties:
▪ Full Binary Tree: Every node except leaves (leaf nodes have no children) has two
children.
▪ Complete Binary Tree: All levels are completely filled except possibly the last level,
which has all nodes filled in from the left side.
Diagram:
A (Root)
/ \
B C
/ \ /
D E F
2. Ternary Tree:
o A ternary tree allows a maximum of three children per node (left, middle, and right).
Diagram:
A (Root)
/ \ /
B C D
Diagram:
A (Root)
/ \ / \
B C D E
/ \ \
F G H
Diagram:
50 (Root)
/ \
EA2331201010152
30 70
/ \ / \
20 40 60 80
5. AVL Tree:
o An AVL tree is a self-balancing binary search tree.
o It maintains a height balance between left and right subtrees, ensuring efficient search and
insertion operations (guaranteed time complexity of O(log n)).
Diagram (AVL trees are more complex to visualize; the balance property is maintained during
operations):
30 (Root)
/ \
20 40
/ \ / \
10 25 35 50
6. Red-Black Tree:
o Another self-balancing binary search tree similar to AVL trees.
o It maintains balance using red and black color properties on nodes, ensuring logarithmic
search and insertion times.
30 (Root - Black)
/ \
20 (Red) 40 (Black)
/ \ / \
10 25 35 50 (Red)
7. B-Tree:
o A B-tree is a balanced m-way search tree (where m is a fixed branching factor) designed for
efficient disk storage and retrieval of data.
o It allows a node to have more than two children, improving search and insertion performance
for large datasets.
These are some of the most common tree data structures. The choice of tree depends on the specific needs of
your application, such as data.
EA2331201010152