Binary Trees Explained in 4 Minutes!
Key Takeaways
Explains binary trees in 4 minutes
Full Transcript
Today we will talk about binary trees. Now, I know, on a surface level, this concept may seem quite tough, but follow along with me, and you'll realize it's a fairly simple and basic concept. So, let's go ahead and understand the topic. Now, what is a binary tree? Imagine you have a tree. This tree has a trunk, which we call the root, and branches that go down. Now, a binary tree is a little special. Each branch can have only two children. Each note can have only two children. When we talk about trees in computer programming, we call this structure a binary tree. Each node stores data and links its left and right branches. So, what is a node? A node is a point or element in our tree, and each node has three things: data that stores a value: the left child, which is on the left side of the note, and the right child, which is on the right side of the note. For example, if a node is 10, then its data is 10. Its left child is five and its right child can be 20. So now if we talk about the structure of a binary tree or if we want to think of a binary tree in the form of a tree, then it will look something like this. Here 10 is the root node. To the left of 10, we have the left child five and to the right, we have the right child 20. To the left of five, we have three and to the right, we have seven. To the left of 20, we have 15 and to the right, we have 25. And now that you have understood what a binary tree is, let us see the code example of this thing. That means if we want to code a binary tree in Python, then first of all we will create a Node class in which the data, left and right child will be stored. This is a very simple code. When you create an object of this node, your data will be stored in that node. Now we create its binary tree. That means, as I told earlier, our 10 is the root, five is the left child and 20 is the right child. If we implement this in the code, then it will look something like this. Now we have a binary tree. Now that our binary tree is created, the question that comes to our mind is how do we traverse this tree. Traversal means visiting the notes of the tree in a specific order. Traversal can be done in three ways in a binary tree. Pre- order traversal, in-order reversal and post-order reversal. In pre-order we first visit the root, then the left child, then the right child. The result of this reversal will be 10 5 3 7 then 20 15 25. In in-order reversal we first visit the left child, then the root note, then the right child. The result of this traversal will be 3 5 7 10 15 20 25. And in post-order we visit the left child, then the right child, then the root note. The result of this reversal will be 3 7 5 15 25 20 10. Meaning, pre-order is when we first write the root, then the left child and the right child. In-order is when we go to the left child, root and right child. And post-order is when we visit the left child, right child and then Coming back to the root, how do we search in a binary tree? So imagine we have a binary tree created and now we need to search for a particular value within it. So how can we do that? Let's look at the code. Suppose we need to search for seven in our binary tree. Its code will be [music]. This code will check whether seven is in our tree or not. Now, when we talk about the use of binary trees, they are very important in programming and help us do many things efficiently. For example, this creates our binary search tree when we need to search quickly; heap when we need the minimum or maximum element quickly; and expression trees when we need to evaluate mathematical expressions. Now you must have understood what a binary tree is and how it works. You now know that in a binary tree, each note has only two children, and we can search and traverse within them. This concept helps you [music]. Understanding complex and creating your own trees is something I understand. The concept of binary trees is a little complicated and implement it in your own code, it becomes quite easy, I hope you understand it, do let us know in the comments if you want us to simplify it further, happy coding
Original Description
Struggling to understand Binary Trees? 🌳 Don’t worry! In just 4 minutes, we’ll break it down in the easiest way possible. Learn the fundamentals, key concepts, and tricks to understand Binary Trees quickly and efficiently. Whether you're preparing for coding interviews or diving into data structures, this quick guide will help you get started! 🚀
📌 What You’ll Learn:
✅ What is a Binary Tree?
✅ Key properties and types of Binary Trees
✅ How to traverse a Binary Tree (In-order, Pre-order, Post-order)
✅ Real-world applications of Binary Trees
✅ Simple steps to solve Binary Tree problems
🔹 Perfect for beginners & intermediate coders looking to master Binary Trees!
Welcome to the Three 90 Challenge by GeeksforGeeks!
✅ Complete 90% of your course in 90 days
✅ Get 90% of your fee refunded!
Yes, you read that right! 🌟 Over ₹5 CRORE in refunds processed already, and YOURS could be next.
Start the challenge now: https://gfgcdn.com/tu/U4a/
Follow us for more tips, knowledge, and resources:
📱 Download GeeksforGeeks' Official App: https://play.google.com/store/apps/details?id=free.programming.programming
💬 Twitter: https://twitter.com/geeksforgeeks
🧑💼 LinkedIn: https://www.linkedin.com/company/geeksforgeeks
📷 Instagram: https://www.instagram.com/geeks_for_geeks/
💌 Telegram: https://t.me/geeksforgeeks_official
📌 Pinterest: https://in.pinterest.com/geeksforgeeks/
🎮 Discord: https://discord.gg/geeksforgeeks
-----
Time Stamps:
0:00 Intro
0:39 What is Node?
1:20 Binary Tree Code Example
2:00 Ways of Traversal
2:54 Search in Binary Tree?
3:14 Where do we use a Binary Tree?
-----
Hashtags:
#BinaryTree #DataStructures #TreeTraversal #GeeksforGeeks #CodingInterview #CompetitiveProgramming #LearnToCode #ProgrammingTips #Algorithms #Tech #interviewpreparation #gfg #gfgcourses
YouTube Tags:
Binary tree, tree traversal, binary tree explained, binary tree tutorial, binary tree in 4 minutes, coding interview, binary tree for beginners, coding, programming, IT jobs, j
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from GeeksforGeeks · GeeksforGeeks · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
How I got into Walmart | Shailesh Sharma
GeeksforGeeks
Upgrade yourself In 29 Days | GeeksforGeeks
GeeksforGeeks
Learn AWS Fundamentals For Free
GeeksforGeeks
Conversation With Young Achievers | Meet the winners of Bi-Wizard Coding Contest | GeeksforGeeks
GeeksforGeeks
Meet The Winners Of Bi-Wizard Coding Contests | GeeksforGeeks
GeeksforGeeks
Interview Prep Strategies | PayPal
GeeksforGeeks
OLX Interview Preparation Strategies | Hukam Singh
GeeksforGeeks
Meet Some More Winners Of Bi-Wizard Coding Contests | GeeksforGeeks
GeeksforGeeks
Live Mock DSA
GeeksforGeeks
Microsoft Azure For Absolute Beginners
GeeksforGeeks
Python for Data Science | Data Science Master Bootcamp | Arpit Jain
GeeksforGeeks
Getting Started with Data Analysis | Data Science Master Bootcamp | Ashish Jangra
GeeksforGeeks
How to prepare theory subjects for SDE interviews | Geeks Summer Carnival 2022
GeeksforGeeks
Get Your Tickets To The Geeks Summer Carnival | GeeksforGeeks
GeeksforGeeks
TED Talk Data Analysis Project | Data Science Master Bootcamp | Ashish Jangra
GeeksforGeeks
How I Secured AIR 9 in GATE'22 | Tushar
GeeksforGeeks
Learn Java Backend Development | Geeks Summer Carnival | GeeksforGeeks
GeeksforGeeks
How to Recognize which Data Structure to use in a question | Geeks Summer Carnival | GeeksforGeeks
GeeksforGeeks
Learn Data Structures and Algorithms | GeeksforGeeks
GeeksforGeeks
Interview experience at Flipkart | GeeksforGeeks
GeeksforGeeks
Lets Prepare for GATE'23 the Right Way | Sakshi Singhal | GeekSummerCarnival
GeeksforGeeks
Highest Paying Jobs in 2022 | Ishan Sharma | Geeks Summer Carnival 2022 | GeeksforGeeks
GeeksforGeeks
Geeks Summer Carnival 2022 | 5th April- 11th April | GeeksforGeeks
GeeksforGeeks
Preparing for SDE interviews | Soham Mukherjee | Geeks Summer Carnival 2022 | GeeksforGeeks
GeeksforGeeks
Full Stack Development with React & Node | Utkarsh Malik | Geeks Summer Carnival | GeeksforGeeks
GeeksforGeeks
Introduction to Open Source and Roadmap to GSOC 2022 | Geeks Summer Carnival 2022 | GeeksforGeeks
GeeksforGeeks
Web Scraping in Action | Geeks Summer Carnival 2022 | GeeksforGeeks
GeeksforGeeks
Getting Hired at BITCS via GfG Job Portal | Get Hired With GeeksforGeeks
GeeksforGeeks
How to build a faster landing Page | Geeks Summer Carnival 2022 | GeeksforGeeks
GeeksforGeeks
Geeks Summer Carnival | 5th To 11th April, 2022 | GeeksforGeeks
GeeksforGeeks
How to get ideas for Startup | Geeks Summer Carnival 2022 | GeeksforGeeks
GeeksforGeeks
Journey from Tier 3 to JusPay | GeeksforGeeks
GeeksforGeeks
Geeks Summer Carnival 2022 | GeeksforGeeks
GeeksforGeeks
Dispelling Myths and Pre conceptions of Programming Languages
GeeksforGeeks
Must Do System Design Questions
GeeksforGeeks
Understanding Sorting Techniques in an hour | Keerti Purswani | Geeks Summer Carnival
GeeksforGeeks
Get Hired at NEC | Job-A-Thon 8
GeeksforGeeks
Journey from Tier 3 college to Microsoft | GeeksforGeeks
GeeksforGeeks
Get Hired with GeeksforGeeks at SuperK | Job A Thon 8
GeeksforGeeks
GeeksforGeeks: Redesigned
GeeksforGeeks
From Tier 3 to cracking multiple interviews | GeeksforGeeks
GeeksforGeeks
Live Mock DSA
GeeksforGeeks
Youtube Data Analysis | Ashish Jangra | GeeksforGeeks
GeeksforGeeks
DSA Self-Paced Course Preview | Sandeep Jain | GeeksforGeeks
GeeksforGeeks
GATE Live Classes | Prepare for GATE CS 2023 | GeeksforGeeks
GeeksforGeeks
Journey from JIIT to Adobe
GeeksforGeeks
Life Is Unfair Ft. Shonty badmash | LIVE Discord Session | A GeeksforGeeks Exclusive
GeeksforGeeks
Interview Experience at Google | Tech Dose
GeeksforGeeks
Live Mock DSA
GeeksforGeeks
Interview Experience @ Amazon | GeeksforGeeks
GeeksforGeeks
My journey through the tech world from India to US | Vidushi | GeeksforGeeks
GeeksforGeeks
Complete Interview Preparation Course | GeeksforGeeks
GeeksforGeeks
Live Mock DSA
GeeksforGeeks
Getting Hired at FiftyFive Technologies | Job-a-thon 9.0
GeeksforGeeks
GFG Karlo, Ho Jayega | GeeksforGeeks ft. Khaleel Ahmed
GeeksforGeeks
How I got job offers from 2 big companies : Arcesium & Microsoft | GeeksforGeeks
GeeksforGeeks
LINUX for Beginners | GFG x Itversity
GeeksforGeeks
My interview experience at Walmart | GeeksforGeeks
GeeksforGeeks
Get Hired at Speckyfox
GeeksforGeeks
Live Mock DSA
GeeksforGeeks
Related Reads
Chapters (6)
Intro
0:39
What is Node?
1:20
Binary Tree Code Example
2:00
Ways of Traversal
2:54
Search in Binary Tree?
3:14
Where do we use a Binary Tree?
🎓
Tutor Explanation
DeepCamp AI