In binary trees, the views and types refer to different perspectives and classifications of the tree structure.
Types of Views in Binary Tree are :
1
/ \
2 3
/ \ / \
4 5 6 7
/ \ \ /
8 9 10 11
- Horizontal View: The horizontal view of a binary tree shows the nodes from left to right at each level. Nodes at the same level are listed in the order of their appearance, from left to right.
1 2 3 4 5 6 7 8 9 10 11
- Vertical View: The vertical view of a binary tree shows the nodes from top to bottom, where nodes in the same vertical line are displayed in the order of their occurrence from top to bottom.
8
4
2 9 10
1 5 6 11
3 7
- Left View: The left view of a binary tree shows the leftmost node at each level. It represents the visible nodes when looking at the tree from the left side.
1 2 4 8
- Right View: The right view of a binary tree shows the rightmost node at each level. It represents the visible nodes when looking at the tree from the right side.
1 3 7 11
- Top View: The top view of a binary tree displays the nodes visible when viewing the tree from the top. It shows the nodes on the vertical lines that intersect the topmost node at each horizontal distance.
8 4 2 1 3 7 11
- Bottom View: The bottom view of a binary tree displays the nodes visible when viewing the tree from the bottom. It shows the nodes on the vertical lines that intersect the bottom-most node at each horizontal distance.
8 9 10 5 6 11 7
Time & Space complexity for each type of view in a binary tree:
View Type | Time Complexity | Space Complexity |
---|---|---|
Horizontal View | O(n) | O(n) |
Vertical View | O(n log n) | O(n) |
Left View | O(n) | O(n) |
Right View | O(n) | O(n) |
Top View | O(n log n) | O(n) |
Bottom View | O(n) | O(n) |
Types of Binary Trees:
- Full Binary Tree: A binary tree in which every node has either 0 or 2 children.
1
/ \
2 3
/ \
4 5
- Complete Binary Tree: A binary tree in which all levels, except possibly the last one, are completely filled, and all nodes are as left as possible.
1
/ \
2 3
/ \ /
4 5 6
- Perfect Binary Tree: A binary tree in which all internal nodes have two children, and all leaf nodes are at the same level.
1
/ \
2 3
/ \ / \
4 5 6 7
- Balanced Binary Tree: A binary tree in which the heights of the left and right subtrees of every node differ by at most one.
1
/ \
2 3
/ \
4 5
- Binary Search Tree (BST): A binary tree in which for every node, all values in its left subtree are less than its value, and all values in its right subtree are greater than its value.
4
/ \
2 5
/ \ \
1 3 6
- Skewed Binary Tree: is a special type of binary tree in which all the nodes are either in the left subtree or the right subtree.
1
/
2
/
3
/
4
OR
1
\
2
\
3
\
4
Binary Tree Type | Time Complexity | Space Complexity |
---|---|---|
Full Binary Tree | O(n) | O(n) |
Complete Binary Tree | O(n) | O(n) |
Perfect Binary Tree | O(log n) | O(log n) |
Balanced Binary Tree | O(log n) | O(log n) |
Binary Search Tree (BST) | Average Case: O(log n) | O(n) |
Note: also read about Binary Trees: Structure & Tree travels
Follow Me
If you like my post please follow me to read my latest post on programming and technology.
https://www.instagram.com/coderz.py/
https://www.facebook.com/coderz.py
Staying up to the mark is what defines me. Hi all! I’m Rabecca Fatima a keen learner, great enthusiast, ready to take new challenges as stepping stones towards flying colors.
Leave a Comment