Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Complete binary tree and balanced binary tree

What is the difference between a balanced binary tree and a complete binary tree?
Is it true to say every complete binary tree is a balanced tree?
How about the other way around?

like image 587
sheidaei Avatar asked Feb 07 '13 16:02

sheidaei


People also ask

What is complete binary tree?

A complete binary tree is a binary tree in which all the levels are completely filled except possibly the lowest one, which is filled from the left. A complete binary tree is just like a full binary tree, but with two major differences. All the leaf elements must lean towards the left.

What is the significant difference between binary tree and balanced binary tree in terms of memory?

B-Tree : B-Tree is known as a self-balancing tree as its nodes are sorted in the inorder traversal. Unlike the binary trees, in B-tree, a node can have more than two children. B-tree has a height of logM N (Where 'M' is the order of tree and N is the number of nodes).

What is balanced binary tree?

A balanced binary tree, also referred to as a height-balanced binary tree, is defined as a binary tree in which the height of the left and right subtree of any node differ by not more than 1. To learn more about the height of a tree/node, visit Tree Data Structure.


1 Answers

A balanced binary tree is the binary tree where the depth of the two subtrees of every node never differ by more than 1.

A complete binary tree is a binary tree whose all levels except the last level are completely filled and all the leaves in the last level are all to the left side.

Below is a balanced binary tree but not a complete binary tree. Every complete binary tree is balanced but not the other way around.

        1      1     1    1   1     1  1  

As implies, in a complete tree, always the level difference will be no more than 1 so it is always balanced.

like image 176
3 revs, 3 users 56% Avatar answered Sep 21 '22 21:09

3 revs, 3 users 56%