0% found this document useful (0 votes)
8 views

trees_combinatories

The document provides an overview of various types of binary trees, including binary trees, binary search trees, perfect binary trees, full binary trees, complete binary trees, AVL trees, and red-black trees. It outlines key properties, formulas for calculating the number of nodes, and characteristics of each tree type. Additionally, it discusses the height and structure of AVL and red-black trees, emphasizing their balancing properties.

Uploaded by

Rajat Jaiwal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

trees_combinatories

The document provides an overview of various types of binary trees, including binary trees, binary search trees, perfect binary trees, full binary trees, complete binary trees, AVL trees, and red-black trees. It outlines key properties, formulas for calculating the number of nodes, and characteristics of each tree type. Additionally, it discusses the height and structure of AVL and red-black trees, emphasizing their balancing properties.

Uploaded by

Rajat Jaiwal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Binary Tree is a tree in which every node has 0,1 or 2 child nodes.

 Minimum number of nodes in a binary tree of height h= h+1

 Maximum number of nodes in a binary tree of height h = ( 2^(h+1))-1

o For example for a tree of height h=2

o Minimum number of nodes= 2+1=3

o Maximum number of nodes = 2^(2+1)-1=2^3-1=8-1=7

 Total no of Binary Search Trees with n nodes are =


For n=2, it is 2
For n=3 it is 5
For n=4 it is 14 and so on

Perfect Binary Tree is tree in which every level has maximum number

of nodes at each level.

 Number of nodes at depth d in a perfect binary tree=2^d

 Perfect binary tree of height h has 2^(h+1)-1 nodes

 Number of leaf nodes in a perfect binary tree of height h= 2^h i.e

nodes at last level


 Full Binary Tree is a Tree in which every node can have either 0 or

2 children.

 A Full Binary Tree has n non-leaf(internal) nodes then it has n+1 leaf

nodes.

 Thus total number of nodes =non-leaf nodes+leaf nodes= n+n+1=2n+1

 If it has a total of N nodes, the number of internal nodes is I = (N –1)/2

 If it has a total of N nodes, the number of leaves is L = (N + 1)/2.

 Complete Binary Tree is a Binary Tree in which every level has

maximum number of nodes except possibly the last level and the

insertion is from left to right.

The depth of a complete binary tree with 'n' nodes is log(n+1)-1

 Balanced Binary Tree

AVL Trees

minimum number of nodes of an AVL tree of height h =1+n(h-1)+n(h-2)

maximum height of any AVL-tree with n nodes


maximum height will be when each level will contain minimum number of

node and formula for minimum number of nodes is given above.

Minimum Nodes in an AVL tree with height n = H(n-1) + H(n-2) + 1.

H(0) = 1.

H(1) = 2

H(2) = H(1) + H(0) + 1 = 2+1+1 = 4 this means for 4 nodes

maximum height of AVL tree is 2.

H(3) = H(2) + H(1) +1 = 4+2+1 = 7. i.e, for 7 nodes maximum height

of AVL tree is 3.

And so on.

Red Black Trees

A red-black tree is a binary search tree with one extra attribute for each node: the colour,

which is either red or black.

A red-black tree is a binary search tree which has the following red-black
properties:
1. Every node is either red or black.
2. Every leaf (NULL) is black. .
3. If a node is red, then both its children
are black.
4. Every simple path from a node to a
descendant leaf contains the same
number of black nodes.

A basic red-black tree

Basic red-black tree with


the sentinel nodes added.
Implementations of the
red-black tree algorithms
will usually include the
sentinel nodes as a
convenient means of
flagging that you have
reached a leaf node.

They are the NULL black


nodes of property 2.
The number of black nodes on any path from, but not including, a node x to

a leaf is called the black-height of a node, denoted bh(x).

You might also like