Back to Browse

Height of Binary Tree 🌳| Recursion | DFS | Binary Tree | πŸ§‘β€πŸ’» C++, Java & Python | GeeksforGeeks

492 views
Oct 9, 2023
8:13

Hello everyone, welcome to my channel where I solve the "Problem of the Day" from Geeksforgeeks and LeetCode. Today's problem is "Height of BinaryTree" which is an easy level question and was asked by companies like Zoho, Amazon, Microsoft, DE Shaw and 8 other companies. πŸš€ The problem statement is: Given a binary tree, find its height. πŸ€” The height of a binary tree is the number of edges between the tree's root and its furthest leaf. For example, the height of a tree with a single node is 1. 🌱 In this video, I will explain how to solve this problem using recursion. I will show you a one liner code that is very time efficient and space efficient. The one liner code uses the ternary operator and the max function to find the height of the left and right subtrees and return the maximum of them plus one. πŸ’― 00:00 Understanding the question 01:40 How is the concept of Recursion used to solve this question 05:35 Formula used in the Recursion 05:53 Base condition of the Recursion 06:47 Coding the approach The code for this problem in C++, Java and Python languages are available in my github repo. πŸ”— Link to the repo: https://github.com/AlgoZenithNITC/GFG_POTD_Solutions_AlgoZenithNITC/tree/main I hope you enjoyed this video and learned something new. If you did, please give it a thumbs up πŸ‘ and share it with your friends. Also, don't forget to subscribe to my channel πŸ”” and hit the bell icon to get notified when I upload new videos. Thank you for watching and see you in the next video. 😊

Download

1 formats

Video Formats

360pmp410.0 MB

Right-click 'Download' and select 'Save Link As' if the file opens in a new tab.

Height of Binary Tree 🌳| Recursion | DFS | Binary Tree | πŸ§‘β€πŸ’» C++, Java & Python | GeeksforGeeks | NatokHD