filmov
tv
Top View and Bottom View of Binary tree | Iterative Method | Trees
Показать описание
In this video, I have discussed how to find top view and bottom view of a binary tree. This can be done both recursively and iteratively. Here, I have discussed the iterative approach.
Logic: Level order traversal is done and we use a map in which the key is horizontal distance from root and the value is {node, level}. If one node with the same horizontal distance comes again, we check if level of new node is lower or higher than the one stored in the map. If level of new node is lower, then we replace it.
Note: If there are multiple top-most/bottom-most nodes at same level and same horizontal distance, then print the later one in level order traversal.
00:00 Introduction
00:16 What is Top View and Bottom View
01:24 Top View Pseudo Code
11:08 Bottom View Pseudo Code
12:34 Implementation
-------------------------------------------------------------
I live in New Delhi and love explaining programming concepts. I have done M.Tech(BITS Pilani) + B.Tech(PEC, Chandigarh) in Computer Science and am currently working as a software engineer in a MNC.
If you like my content, please like, share my videos and subscribe to the channel.
-------------------------------------------------------------
For other tree tutorials, please refer to the below links:
For in-depth Graph theory and implementation details, please refer to the below playlist:
#DataStructure,#Trees,#FitCoder,#Algorithm,#competitiveprogramming,#binarytree
Logic: Level order traversal is done and we use a map in which the key is horizontal distance from root and the value is {node, level}. If one node with the same horizontal distance comes again, we check if level of new node is lower or higher than the one stored in the map. If level of new node is lower, then we replace it.
Note: If there are multiple top-most/bottom-most nodes at same level and same horizontal distance, then print the later one in level order traversal.
00:00 Introduction
00:16 What is Top View and Bottom View
01:24 Top View Pseudo Code
11:08 Bottom View Pseudo Code
12:34 Implementation
-------------------------------------------------------------
I live in New Delhi and love explaining programming concepts. I have done M.Tech(BITS Pilani) + B.Tech(PEC, Chandigarh) in Computer Science and am currently working as a software engineer in a MNC.
If you like my content, please like, share my videos and subscribe to the channel.
-------------------------------------------------------------
For other tree tutorials, please refer to the below links:
For in-depth Graph theory and implementation details, please refer to the below playlist:
#DataStructure,#Trees,#FitCoder,#Algorithm,#competitiveprogramming,#binarytree
Комментарии