dsa2
dsa2
and Algorithms
N Radhakrishnan
Assistant Professor
Anna University, Chennai
Topics
Types of Data Structures
Examples for each type
Tree Data Structure
Basic Terminology
Tree ADT
Traversal Algorithms
Binary Trees
• Binary Tree Representations
• Binary Tree ADT
• Binary Tree Traversals
That is, binary trees are not just trees all of whose nodes have
two or fewer children.
Not only are the two trees in the above Figure are different
from each other, but they have no relation to the ordinary tree
consisting of a root and a single child of the root:
Figure above shows the incomplete binary tree and the natural
mapping of its nodes into an array which leaves some gaps.
Parent
Data
Left Right
Advantages
• Direct Access
• Finding the Parent / Children is fast
Disadvantages
• Wastage of memory
• Insertion and Deletion will be costlier
• Array size and depth
Advantages
• No wastage of memory
• Insertion and Deletion will be easy
Disadvantages
• Does not provide direct access
• Additional space in each node.
1. Initialize a queue.
2. Enqueue the root.
3. Repeat steps 4–7 until the queue is empty.
4. Dequeue a node x from the queue.
5. Visit x.
6. Enqueue the left child of x if it exists.
7. Enqueue the right child of x if it exists.