DEV Community

Cover image for Full vs Complete BiNARY TREEs
Rounit Ranjan Sinha
Rounit Ranjan Sinha

Posted on

Full vs Complete BiNARY TREEs

To understand this concept about Binary tree we have to learn about Binary tree representation in Array.

When the node is at index i, then the left child is at index 2*i _and _right child will be positioned at index i*2+1 and it's parent must be at i/2

After the binary tree representation as an array we can say

=>
Full Binary tree: If the binary tree is full with all the max nodes it can take corresponding to the height and adding another node to the binary tree will increase the height then it's known as Full BT

How to check max nodes according to the height?
Ans = Using formula_** 2^(h+1) - 1**_, where h is the height of BT

=>
Complete Binary tree: When the binary tree is represented in the form of an Array, and up to the length of the array if all the elements are present then it's complete Binary tree else it's not

Some real life examples to use BT
=>
Navigation Trees:
In website development, hierarchical navigation menus are common. Each menu item can have zero or more sub-items, forming a tree structure. This structure is useful for organizing and displaying a website's navigation hierarchy.
Home
|-- About
| |-- Team
| |-- History
|-- Products
| |-- Product A
| |-- Product B
|-- Contact

=>
Comment Threads:
For comment systems on blogs or forums, replies to comments often form a tree structure. Each comment can have multiple replies, creating a threaded discussion.

Comment 1
|-- Reply 1.1
|-- Reply 1.2
| |-- Reply 1.2.1
Comment 2
|-- Reply 2.1

Image description

Top comments (0)