What is a Binary Tree?
A binary tree is a hierarchical data structure, unlike linear ones like arrays, stacks, or linked lists. The term "binary" means a node can have at most two children.
- Example: Folders inside folders in a computer can be represented as a tree.
- In a binary tree, every node can have 0, 1, or 2 children, but never more than 2.
Key Terminology
- Root: The topmost node (starting point) of the tree.
- Children: Nodes directly below a given node.
- Leaf Node: A node with zero children.
- Subtree: A node and all its descendants beneath it. For more on this, see the Comprehensive Guide to Core Data Structures and Algorithms.
- Ancestors: All parent, grandparent, great-grandparent nodes up to the root. For example, for a given node, its parent, grandparent, etc., are its ancestors.
Types of Binary Trees
There are five main types. For a broader overview of data structures, check out the Comprehensive Guide to Data Structures: Arrays to Graphs Explained.
1. Full Binary Tree
- Every node has either 0 or 2 children.
- A node with 1 child is not allowed.
2. Complete Binary Tree
- All levels are completely filled except possibly the last level.
- The last level must have all nodes as left as possible.
- Example: A last level with nodes only on the left is fine; nodes on the right only is not.
3. Perfect Binary Tree
- All leaf nodes are at the same level.
- Every internal node has exactly 2 children.
4. Balanced Binary Tree
- The height of the tree is at most O(log n), where n is the number of nodes.
- This ensures efficient searching. (Balanced trees are covered in detail in the binary search tree series.)
5. Degenerate (Skew) Tree
- Every node has exactly one child.
- It is essentially a linked list in tree form (either left-skewed or right-skewed).
Summary
- A binary tree is a hierarchical structure where each node has ≤2 children.
- Key terms: root, children, leaf, subtree, ancestors.
- Five types: full, complete, perfect, balanced, and degenerate.
- Understanding these basics is essential for solving binary tree interview questions, such as those found in Tree Views & Traversals: Zig-Zag, Boundary, Top, Bottom, Left & Right View Problems.
so before starting the video i'd love to thank relevel for sponsoring this entire tree series so if you're tired of
waiting for companies to respond to your applications through different job portals the next few seconds are very
very important for you because reliable by an academy is india's first hiring platform that can get you a job within a
week itself yes all you have to do is to register for the relevant test and within a week your interview will be
scheduled with india's top companies and the top budding unicorns so what are you waiting for
make sure you check out the links in the description and apply for the relevant test because it is free
hey everyone welcome to the first lecture of the free cut tv series so today's lecture will be about
introduction to binary trees now what is binary tree so as of now you would be knowing arrays
stacks queues linked list those are linear data structure whenever i talk about trees they are hierarchical data
structures they follow in hierarchy now what is in hierarchy if you have seen in computers you have folders right let's
say this is the initial folder that you have and inside that you have one more folder inside that you might have one
more folder inside that you might have one more folder inside that another folder or these kind of things can be
represented using trees whenever i associate a term binary
that's basically zero and one so a binary tree basically says inside a guy that can be at facts two
guys okay at max two guys so at max like over here there are two guys over here there's only one over here there's one
over here there's one over there here there's no so whenever i say that in an hierarchy
structure i can have at max 2 guys that is when i can call it as a binary trees okay so that's the simple
definition of a binaries now why is binary important because there are a lot of questions related to binary trees
that are asked in interviews yes a lot of times you will find a question related to binary so that is why we will
be having this entire series on binary trees so before moving on uh
let's discuss about some terms whichever is the head or starting whatever you can call it that that is known as the root
of the tree root the starting point and if this is the node and it has couple of guys
these guys are called the children yes these guys um this is the children this is the children okay uh for example this
guy is the children of this guy this guy is a children of this guy okay i hope you understood the children concept if
there's one guy beneath it beneath it whatever we have those are children's cool
now there's one more concept leaf this is known as the leaf node what's the leaf node a node which does
not have children's okay that's known as the leaf notes there's another concept as sub tree now let's assume you're
standing here okay and this entire portion okay this entire portion will be the sub tree this
portion will be the sub tree for this node cool let's say you're standing here this entire portion will be the sub tree
let's say standing here this entire portion will be the sub tree let's say standing here this entire portion will
be the sub tree okay the node and the beneath guys beneath guys are the subtree of a node now there's one
more concept which is known as ancestors what does ancestors
so if you stand over here for this guy this is the parent this is the grandparent this is the grand
grandparent this is the grand grandparent so basically all the grand grand grand grand whatever parents you
have these guys are called ancestors for this guy this this is an ancestor this is an ancestor this is an ancestor this
is an ancestor okay for this guy only this guy is an ancestor for this guy this and this is an ancestor for this
guy this this this is an ancestor so i hope you have understood the concept of ancestors root children leaf node now
there is something there are a couple of other terms but that are not important uh you will you're just requiring these
terms in order to understand the tree series so now let's talk about the types of binary trees so one two three four
five there are five types of binary trees and the first one is full binary tree what is the full binary tree
every node will either have zero or two children now for an example i can say this
is a full binary tree because this node has two children this node has zero children this node
has two children this node has zero children this node has zero children i can say this
also has a full binary because this node has two children this node has two children this node has two children this
node has zero this node has zero this node has zero this node has zero so this can also be called as a full binary
trees whereas you cannot call something uh like this
as a full binary tree why because this guy has two children but this guy only has a single children so it either can
have zero or eight either can have a couple of children's okay i hope you've understood full binary tree
now let's talk about complete barrier trees now the next type is complete barrier trees it states all levels are
completely filled all levels should be completely filled except the last level okay and the last
level has all the nodes as left as possible so if i draw one of the binary trees
i can say that this is a complete binary trees because if you check the levels this is what you
call levels okay level zero or one level one or two level like one two three you can call it if you refer it as one based
indexing this level has all the notes this level has all the roots this level has all the nodes so all levels are
completely filled again i can call this as i can call this as a complete manner
tree this level is filled this level is filled this level has this guys missing this level has
these guys missing but again that's allowed if you carefully read it it says accept the last level the last level
cannot have everything filled now can you have something like this no
because it clearly states the last level has all nodes in left this is on right
so this is not possible whereas this is possible the last level is not completely filled
but the guy is as left as possible okay so this is again a complete binary tree so just need to make sure all the levels
are filled and the last level if not completely filled everything should be on the left every understood complete
binary tree the next type of binary is a perfect binary tree basically states all leaf nodes are at the same level so this
is a perfect binary tree because you can see these are the leaf nodes and all of them are at the same
level again this is not a perfect binary tree because this is a leaf node this is a leaf node and this is the leaf node so
they're not at the same level it has to be on the same level like this is a binary because they are at the same
level so that's the definition of perfect binary tree now the next one is a balanced binary it states height can
be at a maximum of log n when log n n is number of nodes for an example if i give you n equal to let's say 8 okay so
log base 2 n is around
3 so you cannot have a greater height than 3 that means you cannot have a tree like this at maximum the height of
the tree should be 3 like the height
and this is generally done to efficiently search or inc like improve the time complexity uh we will be doing
the other variant of binary trees that is binary search trees where we will be understanding this that's why i'm not
going deep into balance binaries as of now what's the next one degenerate trees what is the degenerate
tree whenever it's a skew tree for example if n is four this is something like this
degenerate skew trees if it is going like this it's essentially a linked list only right whether that's straight line
so that's the definition of linked list whenever every node every node has a single
children that's the definition of degenerate trees so i hope you've understood the terms related to binary
trees and the types of binary trees in this video so i hope you've understood the entire explanation as well as the
code just in case you did please please please make sure you like this video because it took a lot of efforts to make
this entire tree series also if you wish you can definitely drop in a comment that will keep motivating me to make
such further series also if you're new to the channel please do consider subscribing because i'm going to bring
in such more cds in the upcoming future as well with this uh let's wrap up this video let's read in the next lecture bye
bye [Music]
A binary tree is a hierarchical data structure where each node can have at most two children, unlike linear structures like arrays or linked lists where elements are arranged sequentially. It represents relationships like folder structures in a computer, with a single root node at the top and branches extending downward.
Key terms include: Root (the topmost node), children (nodes directly below a given node), leaf nodes (nodes with zero children), subtree (a node and all its descendants), and ancestors (all parent/grandparent nodes up to the root, e.g., a node's parent and grandparent).
The five main types are: Full Binary Tree (every node has 0 or 2 children, not 1), Complete Binary Tree (all levels filled except possibly the last, which must have nodes as left as possible), Perfect Binary Tree (all leaf nodes at the same level, all internal nodes have 2 children), Balanced Binary Tree (height is O(log n) for efficient search), and Degenerate Tree (each node has exactly 1 child, resembling a linked list).
A full binary tree requires that every node have either zero or two children, so no node can have exactly one child. This structure ensures that all internal nodes contribute to full branching, making it useful for certain tree-based algorithms.
A complete binary tree allows all levels to be completely filled except the last, which must have nodes as far left as possible, while a perfect binary tree requires all leaf nodes to be on the same level and every internal node to have exactly 2 children. Perfect trees are a stricter subset of complete trees.
A degenerate binary tree, also called a skew tree, has every node with exactly one child, making it essentially a linked list in tree form. It can be left-skewed (all children on the left) or right-skewed (all on the right), leading to O(n) height and inefficient search.
Understanding binary tree types and terms is essential because they form the foundation for solving tree-based algorithmic problems in interviews. Each type has specific properties that affect traversal, search efficiency, and memory usage, and knowing these helps you choose the right approach for problems like building heaps, BSTs, or balancing trees.
Keep this summary
Save it to LunaNotes and it becomes a real note in your library — editable, searchable, and ready to turn into flashcards or a diagram. Free to start.
Save to LunaNotesOr summarise for another video.
32K+ people have turned 65K+ videos into notes
“Very useful tool. I'm using it for the last couple weeks and I'm loving it so far. Makes learning on YouTube a great experience.”
This summary and transcript were automatically generated using AI with the Free YouTube transcript summary tool by LunaNotes.
Related summaries
Tree Views & Traversals: Zig-Zag, Boundary, Top, Bottom, Left & Right View Problems
Master 7 essential binary tree problems in this comprehensive tutorial by Love Babbar. Learn to implement zig-zag (spiral) traversal, boundary traversal, vertical order traversal, and all view-type problems (top, bottom, left, and right views) with clean C++ code and step-by-step explanations.
Comprehensive Guide to Core Data Structures and Algorithms
Explore foundational concepts in data structures, computational complexity, and advanced algorithms. This guide covers arrays, linked lists, stacks, queues, priority queues, union-find, trees, hash tables, Fenwick trees, suffix arrays, balanced BSTs, and indexed priority queues, with insights on implementation and performance optimization.
Comprehensive Guide to Data Structures: Arrays to Graphs Explained
Explore fundamental concepts of data structures from arrays, lists, stacks, queues to trees and graphs. Learn definitions, real-world examples, implementation strategies, and algorithmic insights for efficient data organization and manipulation.
Introduction to Data Structures and Algorithms
This video provides a comprehensive introduction to data structures and algorithms, explaining key concepts such as data, data structures, their purpose, classifications, and operations. It also covers algorithms, their properties, and practical implementation examples.
How Computers Work: From Binary Numbers to CPU Design Explained
This comprehensive guide explains how computers work from the ground up, starting with binary number representation and building toward CPU design. The video covers decimal to binary conversion, binary addition and subtraction, and the fundamental principles behind how computers process information using just zeros and ones.
Most viewed summaries
A Comprehensive Guide to Using Stable Diffusion Forge UI
Explore the Stable Diffusion Forge UI, customizable settings, models, and more to enhance your image generation experience.
Kolonyalismo at Imperyalismo: Ang Kasaysayan ng Pagsakop sa Pilipinas
Tuklasin ang kasaysayan ng kolonyalismo at imperyalismo sa Pilipinas sa pamamagitan ni Ferdinand Magellan.
Mastering Inpainting with Stable Diffusion: Fix Mistakes and Enhance Your Images
Learn to fix mistakes and enhance images with Stable Diffusion's inpainting features effectively.
Pamamaraan at Patakarang Kolonyal ng mga Espanyol sa Pilipinas
Tuklasin ang mga pamamaraan at patakaran ng mga Espanyol sa Pilipinas, at ang epekto nito sa mga Pilipino.
How to Install and Configure Forge: A New Stable Diffusion Web UI
Learn to install and configure the new Forge web UI for Stable Diffusion, with tips on models and settings.
Found this summary useful?
Take it with you. One click puts it in your own LunaNotes library.
Save to LunaNotes