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

Binary Tree

A binary tree is a data structure where each node has at most two children, with unique labels and specific value relationships. There are various categories of binary trees, including skewed, complete, incomplete, full, and perfect binary trees. The document also outlines algorithms for searching and inserting items in a binary tree.

Uploaded by

A1Virus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Binary Tree

A binary tree is a data structure where each node has at most two children, with unique labels and specific value relationships. There are various categories of binary trees, including skewed, complete, incomplete, full, and perfect binary trees. The document also outlines algorithms for searching and inserting items in a binary tree.

Uploaded by

A1Virus
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

BINARY

TREE
DR. MD. ASRAF ALI
ASSOCIATE PROFESSOR DPT. OF SWE
WHAT IS BINARY TREE ?

• A binary tree is a tree data


structure in which each node has at
most two childrens, which are
referred to as the left child and
the right child is called binary tree.
CONDITION OF BINARY TREE
1)Each parents node’s has at most two child
nodes.
2)Each node’s label will be unique.
3)Parents node’s value will be less than right
child node, and parents node’s value will be
bigger than left child node.
CATEGORY OF BINARY TREE
a)Skewed binary tree.
b)Complete binary tree.
c)Incomplete binary tree.
d)Full binary tree.
e)Perfect Binary Tree.
SKEWED BINARY TREE
A binary tree which is dominated solely by left child nodes
or right child nodes is called skewed binary tree.

right skewed binary tree


COMPLETE BINARY TREE
A complete binary tree is a binary tree in which every
node has two Childs, except the leaf nodes.

complete binary tree


INCOMPLETE BINARY TREE
An incomplete binary tree is a binary tree in which any node
does not has two Childs , except the leaf nodes.

incomplete binary tree


FULL BINARY TREE/PERFECT BINARY TREE

A perfect binary tree is a tree in which every node other


than the leaves has two children and with
all leaf nodes at the same depth.

Perfect binary tree


SEARCHING ALGORITHM OF BINARY TREE
Algorithm BST(x) // here x is searching item.
{
found := false // here we assume that found is false(Boolean type) at first.
t := tree // here tree means root of a binary tree.
while(t ≠ 0 and found=false) // t ≠ 0 means t ≠ null ………means have no any node /
parents / root of a binary tree
{
if( x = (t → data) ) {
found = true;
}
else if ( x < (t → data) ) {
t : = ( t → Lchild); // Lchild means left child
}
else {
t : = ( t → Rchild); // Rchild means right child
}
}
if (found = false) then { write “Item not found” } ;
else { write “Item found” } ;
} // END
INSERTION ALGORITHM OF BINARY TREE
Algorithm BTI(x) // here x is inserting item.
{
found := false // here we assume that found is false(Boolean type) at first.
p := tree // here tree means root of a binary tree.
while(p ≠ 0 and found=false) // p ≠ 0 means p ≠ null ………means have no any node / parents /
root of a binary tree
{
q := p;
if( x = (p → data) ) {
found = true;
}
else if ( x < (p → data) ) {
p : = ( p → Lchild); // Lchild means left child
}
else {
p : = ( p → Rchild); // Rchild means right child
}
}
In this step’s algorithm is (go to next slide) → → → → → → → → → → → → → →
If(found = false) then Lchild;
data ; Rchild;

{
p : = new tree node //here new tree node means create a node such
(p → Lchild)= 0 ; (p → data)= x ; (p → Rchild)= 0 ;
if(tree ≠ 0 ) {
if(x < (q-data) ) {
q → Lchild : = p ;
}
else {
q → Rchild : = p ;
}
}
else {
tree : = p // if tree is null then here create root of a tree
}
}
//Back to previous slide.
THE END

You might also like