- Stores the data in sorted order.
- Easy to find nodes with binary search algorithm with O(logN) complexity.
A Binary tree is a tree where a parent node can have at most 2 children. It can have 0 children but it will never have 3 children or more. Let's see a picture.
You can see that none of the parent nodes have more than 2 children. They have 0-2 children.
That is condition 1.
Condition 2 is:
- Every left child value will be less than the parent value.
- Every right child value will be greater than the parent value.
You can see that every parent and their children are maintaining the above condition.
Now, it is up to you. You can allow duplicate values in the tree. If so, then you will add them to your left or right side.
A node will contain 3 data.
- Left child node reference.
- Right child node reference.
- Actual value.
If a parent has no child or has only one child then the reference value will be null.
- The maximum number of nodes at level 'l' of a binary tree is 2^l.
If you don't know about the levels of the height of a tree please read the blog about trees.
- The maximum number of nodes in a binary tree of height 'h' is 2^h – 1.
- The minimum number of nodes in a binary tree of height 'h' is h+1
There are some variations of binary trees. They are :
- Full binary tree.
- Perfect binary tree.
- Complete binary tree.
- Balanced binary tree.
I will talk about them on other blogs.
I have made a video about how to build a carousel postcard with React, Material-UI, and Swiper.js.
If you are interested you can check the video.
You can also demo the application form here
Please like and subscribe to Cules Coding. It motivates me to create more content like this.
If you have any questions, please comment down below.
You can reach out to me on social media as @thatanjan .
Stay safe. Goodbye.
The Internet has revolutionized our life. I want to make the internet more beautiful and useful.
I ended up being a full-stack software engineer.
I can develop complex full-stack web applications like social media applications or e-commerce sites.
I have developed a social media application called Confession. The goal of this application is to help people overcome their imposter syndrome by sharing our failure stories.
I also love to share my knowledge. So, I run a youtube channel called Cules Coding where I teach people full-stack web development, data structure algorithms, and many more. So, Subscribe to Cules Coding so that you don't miss the cool stuff.
I am looking for a team where I can show my ambition and passion and produce great value for them.
Contact me through my email or any social media as @thatanjan . I would be happy to have a touch with you.
- Email: email@example.com
- linkedin: @thatanjan
- portfolio: anjan
- Github: @thatanjan
- Instagram (personal): @thatanjan
- Instagram (youtube channel): @thatanjan
- Twitter: @thatanjan
- Facebook: @thatanjan
Blogs you might want to read:
- Eslint, prettier setup with TypeScript and react
- What is Client-Side Rendering?
- What is Server Side Rendering?
- Everything you need to know about tree data structure
- 13 reasons why you should use Nextjs
Videos might you might want to watch: