SlideShare a Scribd company logo
3 TREE
A tree is a (possibly non-linear) data structure made up of nodes or vertices and edges without
having any cycle. The tree with no nodes is called the null orempty tree. A tree that is not
empty consists of a root node and potentially many levels of additional nodes that form a
hierarchy.
Not a tree: cy cle B→C→E→D→B. B has more than one parent (inbound edge
Not a tree: two non-connected parts, A→B and C→D→E. There is more than one root
Not a tree: undirected cy cle 1-2-4-3. 4 has more than one parent (inbound edge
Not a tree: cy cle A→A. A is the root but it also has a parent.
Each linear list is triv ially a tree
# TERMINOLOGIES OF TREES:
1.ROOTS: THE FIRST NODE OF TREE IS CALLED ROOT NODE.
2.PARENTS: In simple words,the node whichhasbranchfromit to anyothernode is calledas
parentnode.Parentnode can alsobe definedas"The node whichhaschild/children".
3. EDGES: the node whichhasa linkfromitsparentnode iscalledaschildnode.Ina tree,any
parentnode can have any numberof childnodes.Ina tree,all the nodesexceptrootare child nodes.
4.CHILD : In simple words,the node whichhasalinkfromitsparentnode iscalledas childnode.
In a tree,anyparentnode can have anynumberof childnodes.
5.SIBLING: a group of nodes with same parents.
6.LEAF: a node with no child.
7. INTERNAL NODE: In a tree data structure,nodesotherthanleaf nodesare called
as Internal Nodes. The rootnode isalsosaidto be Internal Node if the tree hasmore than one
node. Internal nodesare alsocalledas'Non-Terminal'nodes.
8.HEIGHT:(for height of of tree we need to move from downward (root node ) to upward
upto which height of node is asked.) ina tree datastructure,the total numberof egdes fromleaf
node to a particularnode inthe longestpathiscalledas HEIGHT of that Node. Ina tree,heightof the
root node issaidto be heightof the tree.
9. DEGREE: the total numberof childrenof a node iscalledas DEGREE of that Node
10.DEPTH: In a tree data structure,the total numberof egdesfromrootnode to a particular
node iscalledas DEPTH of that Node. Ina tree,the total numberof edgesfromrootnode to a leaf node
inthe longestpathissaidto be Depthof the tree.
11. PATH: the sequence of NodesandEdgesfromone node toanothernode iscalled
as PATH betweenthattwoNodes.
12. SUBTREE: each childfroma node formsa subtree recursively.Everychildnodewillforma
subtree onitsparentnode.
13. LEVEL: ina tree each stepfromtop to bottomiscalledas a Level andthe Level countstarts
with'0' and incrementedbyone ateach level (Step).
Figure 1.
14.DESCENDANT: youjust needtomove formroot node to leaf node (takingrootnode).
Consider fig. 1 letwe needtofind descendantand ancestorfor ‘J’,’G’,’k’.
Thenanswerwill be
>>> descendentof ‘j ‘: A,B,E,J & FOR ‘G’ : A,C,G & FOR ‘K’: A,C,G,K.
15.ANCESTOR: youjustneedtomove formgivennode toroot nodes takingall nodes coming
inbetween.(takinggivennode node).(eg.Same problem )
>>ancestor of ‘j ‘: J,E,B,A & FOR ‘G’ : G,C,A & FOR ‘K’: K,G,C,A.
#####################################################################################
APPLICATIONS OF TREE :
1. Organizationstructureof corporation.
2. Table of contentof books.
3. Dos or window file system.
##############################################
# BINARY TREE
In a normal tree,everynode canhave any numberof children.Binarytree isaspecial type of tree data
structure inwhicheverynode can have a maximumof 2 children.One isknownasleftchildandthe
otheris knownasright child.
TYPE OF BINARY TREES :
1. STRICTLY BINARY TREE
2.COMPLETEBINARYTREE
3. EXTRENDED BINARYTREE
>> STRICTLY BINARYTREE : In a binarytree,everynode canhave a maximumof two children.
But instrictlybinarytree,everynode shouldhave exactlytwochildrenornone.Thatmeansevery
internal node musthave exactlytwochildren.
>>2. COMPLETEBINARY TREE(PerfectBinaryTree)
In a binarytree,everynode canhave a maximumof twochildren.Butinstrictlybinarytree,everynode
shouldhave exactlytwochildrenornone andincomplete binarytree all the nodesmusthave exactly
twochildrenandat everylevel of complete binarytree theremustbe 2^n level numberof nodes.For
example atlevel 2there mustbe 2^2 = 4 nodesandat level 3there mustbe 2^3 = 8 nodes.
A binary tree in which every internal node has exactly two children and all leaf
nodes are at samelevel is called Complete Binary Tree.
Complete binarytree isalsocalledas PerfectBinaryTree.
3.EXTRENDED BINARYTREE
A binarytree can be convertedintoFull Binarytree byaddingdummynodestoexistingnodeswherever
required .The full binary tree obtained by adding dummy nodes to a binary tree is called as
Extended Binary Tree.
########################################
# REPRESENTATION OF BINARY TREE:
(normal trees cann’t be represent as array and link list,justbecauseof there irregular shape.)
1. linked list representation
2. Array representation (Let we have this binary tree.)
1. linked list representation
2. Array representation
(1-D) HERE THE ARRANGEMENT OF DATA IS DONE ON THE BASESE OF “ 2*K , 2*K
+1 “ OFCHILDS OF EVERY NODE . ( K IS THE NODE NUMBER GIVEN ,(STARTS FORM 0).
###############################################
#################################################
###############################################
# BINARY TREE TRAVERSALS
(TO DISPLAY A BINARY TREE WE NEED TO FOLLOW SOME
ORDERS )
1. INORDER
2. PREORDER
3. POSTORDER
(HOPELLY U ALL KNOW HOW TO DO THESE JUST VERIFY ANSWERS )
1. 1. In - Order Traversal( leftChild - root- rightChild )
I - D - J - B - F - A - G - K - C – H
2. Pre - OrderTraversal ( root - leftChild - rightChild)
A - B - D - I - J - F - C - G - K - H
3. Post - OrderTraversal ( leftChild - rightChild - root)
I - J - D - F - B - K - G - H - C – A
Program for all three method is :
#include <stdio.h>
#include <stdlib.h>
struct node
{ intvalue;
struct node*left;
struct node*right;
};
struct node*root;
struct node*insert(structnode*r,intdata);
voidinOrder(structnode*r);
voidpreOrder(structnode*r);
voidpostOrder(structnode*r);
intmain()
{ root= NULL;
int n,i,v;
printf("Howmanydata'sdoyou wantto insert?n");
scanf("%d",&n);
for( i=0; i<n;i++){
printf("Data%d:",i+1); scanf("%d",&v);
root= insert(root,v);}
printf("InorderTraversal:");
inOrder(root);
printf("n");
printf("PreorderTraversal:");
preOrder(root);
printf("n");
printf("PostorderTraversal:");
postOrder(root);
printf("n");
return0; }
struct node*insert(structnode*r,intdata)
{ if(r==NULL)
{ r = (structnode*) malloc(sizeof(structnode));
r->value =data;
r->left=NULL;
r->right= NULL;
}
else if(data<r->value){
r->left=insert(r->left,data);}
else {
r->right= insert(r->right,data);
}returnr; }
voidinOrder(structnode*r)
{ if(r!=NULL){
inOrder(r->left);
printf("%d",r->value);
inOrder(r->right);
}
}
voidpreOrder(structnode*r)
{ if(r!=NULL){
printf("%d",r->value);
preOrder(r->left);
preOrder(r->right);
}
}
voidpostOrder(structnode*r)
{ if(r!=NULL){
postOrder(r->left);
postOrder(r->right);
printf("%d",r->value); }
}
# Threaded Binary Tree
A binarytree isrepresentedusingarrayrepresentationorlinkedlistrepresentation.Whenabinarytree
isrepresentedusinglinkedlistrepresentation,if anynode isnothavinga childwe use NULL pointerin
that position.Inanybinarytree linkedlistrepresentation,there are more numberof NULL pointerthan
actual pointers.Generally,inanybinarytree linkedlistrepresentation,if there are 2N numberof
reference fields,then N+1numberof reference fieldsare filledwithNULL( N+1 are NULL outof 2N ).
ThisNULL pointerdoesnotplayanyrole exceptindicatingthereisnolink(nochild).
Threaded Binary Tree is also a binary tree in which all left child pointers
that are NULL (in Linked list representation) points to its in-order
predecessor, and all right child pointers that are NULL (in Linked list
representation) points to its in-order successor.
(STEPS TO SOLVE THREDED BINARY TREE . (REPRESENT THIS))
1. WRITE INORDER OF TREE.
2. ONE WAY  RIGHT NODE: jointhe inoder successerof of node represented byarrow .
3. TWO WAY -> RIGHT +LEFT NODE : jointhe inorder predecessor.
4. else if nither predecessorof successerispresentof the node thenthatnode isrepresentbyNULL.
# HUFFMAN ALGORITHM (IMPORTANT EVEN)
HOPLLY U CAN DO IT
(THIS ALGO IS GREAT , FOR STORE THE DATA IN ANOTHER WAY (BY ITS WAY) EXCEPT OF OUR
OWN )
*HEIGHT OF TREE FORM IS -> N-1 (WHERE THE ‘N’ IS TOTAL NO. OF ELEMENTS TO BE
ARRANGE.)
An example is
Q. arrange these element 2,3,5,7,9,11 using huffman algorithm ?
Steps are:
1. Add smallest elements at level first.
2. Compare answer with given element if
a. If answer is smaller or equal to any element then proceed to add at upper level.
b. If answer is greater then the other elements , proceed to add any other two smaller
numbers(can include answer or another element).
Made by Gaurav Sharma…
Trees in data structrures

More Related Content

PPT
Tree and Binary Search tree
PPT
Ch13 Binary Search Tree
PPTX
Search tree,Tree and binary tree and heap tree
PPTX
Data structure tree- advance
PPSX
data structure(tree operations)
PPTX
Tree
PPT
Binary trees
PPTX
Binary tree and Binary search tree
Tree and Binary Search tree
Ch13 Binary Search Tree
Search tree,Tree and binary tree and heap tree
Data structure tree- advance
data structure(tree operations)
Tree
Binary trees
Binary tree and Binary search tree

What's hot (20)

PDF
Tree Data Structure by Daniyal Khan
PPTX
Tree in data structure
PPT
PPTX
Data structure tree - beginner
PPT
Binary tree
PPT
Data Structure and Algorithms Binary Tree
PDF
Trees, Binary Search Tree, AVL Tree in Data Structures
PDF
Binary tree
PPT
Trees - Data structures in C/Java
PDF
Binary tree
PPT
Binary Search Tree and AVL
PPT
BINARY SEARCH TREE
PDF
Tree and binary tree
PPT
Chapter 8 ds
PPT
binary tree
PPTX
Binary Tree Traversal
PPTX
Binary tree traversal ppt
PPTX
Data structure tree - intermediate
PPT
Lecture 5 trees
Tree Data Structure by Daniyal Khan
Tree in data structure
Data structure tree - beginner
Binary tree
Data Structure and Algorithms Binary Tree
Trees, Binary Search Tree, AVL Tree in Data Structures
Binary tree
Trees - Data structures in C/Java
Binary tree
Binary Search Tree and AVL
BINARY SEARCH TREE
Tree and binary tree
Chapter 8 ds
binary tree
Binary Tree Traversal
Binary tree traversal ppt
Data structure tree - intermediate
Lecture 5 trees
Ad

Similar to Trees in data structrures (20)

DOCX
data structures Unit 3 notes.docxdata structures Unit 3 notes.docx
PPTX
Data Structures -Non Linear DS-Basics ofTrees
PPT
Algorithm and Data Structure - Binary Trees
PPTX
TREES basics simple introduction .pptx
PPTX
TREES 1.pptx
PPT
Trees
PPT
Unit8 C
PPTX
Trees in Data Structure
PPTX
Data Structures
PPTX
Data Structure of computer science and technology
PPTX
Tree structure and its definitions with an example
PPT
9. TREE Data Structure Non Linear Data Structure
PPTX
UNIT III Non Linear Data Structures - Trees.pptx
PPTX
Basic Tree Data Structure BST Traversals .pptx
PPTX
UNIT III Non Linear Data Structures - Trees.pptx
PDF
Dsc++ unit 3 notes
PPTX
NON-LINEAR DATA STRUCTURE-TREES.pptx
PPTX
Binary tree and operations
PDF
Trees unit 3
PDF
Unit 4.1 (tree)
data structures Unit 3 notes.docxdata structures Unit 3 notes.docx
Data Structures -Non Linear DS-Basics ofTrees
Algorithm and Data Structure - Binary Trees
TREES basics simple introduction .pptx
TREES 1.pptx
Trees
Unit8 C
Trees in Data Structure
Data Structures
Data Structure of computer science and technology
Tree structure and its definitions with an example
9. TREE Data Structure Non Linear Data Structure
UNIT III Non Linear Data Structures - Trees.pptx
Basic Tree Data Structure BST Traversals .pptx
UNIT III Non Linear Data Structures - Trees.pptx
Dsc++ unit 3 notes
NON-LINEAR DATA STRUCTURE-TREES.pptx
Binary tree and operations
Trees unit 3
Unit 4.1 (tree)
Ad

Recently uploaded (20)

PPTX
Construction Project Organization Group 2.pptx
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
DOCX
573137875-Attendance-Management-System-original
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
Well-logging-methods_new................
PPTX
Welding lecture in detail for understanding
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
web development for engineering and engineering
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
OOP with Java - Java Introduction (Basics)
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
Geodesy 1.pptx...............................................
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Construction Project Organization Group 2.pptx
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
573137875-Attendance-Management-System-original
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
Well-logging-methods_new................
Welding lecture in detail for understanding
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Lecture Notes Electrical Wiring System Components
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
web development for engineering and engineering
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
OOP with Java - Java Introduction (Basics)
Model Code of Practice - Construction Work - 21102022 .pdf
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
Geodesy 1.pptx...............................................
R24 SURVEYING LAB MANUAL for civil enggi
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf

Trees in data structrures

  • 1. 3 TREE A tree is a (possibly non-linear) data structure made up of nodes or vertices and edges without having any cycle. The tree with no nodes is called the null orempty tree. A tree that is not empty consists of a root node and potentially many levels of additional nodes that form a hierarchy. Not a tree: cy cle B→C→E→D→B. B has more than one parent (inbound edge Not a tree: two non-connected parts, A→B and C→D→E. There is more than one root Not a tree: undirected cy cle 1-2-4-3. 4 has more than one parent (inbound edge Not a tree: cy cle A→A. A is the root but it also has a parent. Each linear list is triv ially a tree # TERMINOLOGIES OF TREES: 1.ROOTS: THE FIRST NODE OF TREE IS CALLED ROOT NODE.
  • 2. 2.PARENTS: In simple words,the node whichhasbranchfromit to anyothernode is calledas parentnode.Parentnode can alsobe definedas"The node whichhaschild/children". 3. EDGES: the node whichhasa linkfromitsparentnode iscalledaschildnode.Ina tree,any parentnode can have any numberof childnodes.Ina tree,all the nodesexceptrootare child nodes. 4.CHILD : In simple words,the node whichhasalinkfromitsparentnode iscalledas childnode. In a tree,anyparentnode can have anynumberof childnodes. 5.SIBLING: a group of nodes with same parents. 6.LEAF: a node with no child. 7. INTERNAL NODE: In a tree data structure,nodesotherthanleaf nodesare called as Internal Nodes. The rootnode isalsosaidto be Internal Node if the tree hasmore than one node. Internal nodesare alsocalledas'Non-Terminal'nodes. 8.HEIGHT:(for height of of tree we need to move from downward (root node ) to upward upto which height of node is asked.) ina tree datastructure,the total numberof egdes fromleaf node to a particularnode inthe longestpathiscalledas HEIGHT of that Node. Ina tree,heightof the root node issaidto be heightof the tree.
  • 3. 9. DEGREE: the total numberof childrenof a node iscalledas DEGREE of that Node 10.DEPTH: In a tree data structure,the total numberof egdesfromrootnode to a particular node iscalledas DEPTH of that Node. Ina tree,the total numberof edgesfromrootnode to a leaf node inthe longestpathissaidto be Depthof the tree. 11. PATH: the sequence of NodesandEdgesfromone node toanothernode iscalled as PATH betweenthattwoNodes. 12. SUBTREE: each childfroma node formsa subtree recursively.Everychildnodewillforma subtree onitsparentnode. 13. LEVEL: ina tree each stepfromtop to bottomiscalledas a Level andthe Level countstarts with'0' and incrementedbyone ateach level (Step). Figure 1. 14.DESCENDANT: youjust needtomove formroot node to leaf node (takingrootnode).
  • 4. Consider fig. 1 letwe needtofind descendantand ancestorfor ‘J’,’G’,’k’. Thenanswerwill be >>> descendentof ‘j ‘: A,B,E,J & FOR ‘G’ : A,C,G & FOR ‘K’: A,C,G,K. 15.ANCESTOR: youjustneedtomove formgivennode toroot nodes takingall nodes coming inbetween.(takinggivennode node).(eg.Same problem ) >>ancestor of ‘j ‘: J,E,B,A & FOR ‘G’ : G,C,A & FOR ‘K’: K,G,C,A. ##################################################################################### APPLICATIONS OF TREE : 1. Organizationstructureof corporation. 2. Table of contentof books. 3. Dos or window file system. ############################################## # BINARY TREE In a normal tree,everynode canhave any numberof children.Binarytree isaspecial type of tree data structure inwhicheverynode can have a maximumof 2 children.One isknownasleftchildandthe otheris knownasright child. TYPE OF BINARY TREES : 1. STRICTLY BINARY TREE 2.COMPLETEBINARYTREE 3. EXTRENDED BINARYTREE >> STRICTLY BINARYTREE : In a binarytree,everynode canhave a maximumof two children. But instrictlybinarytree,everynode shouldhave exactlytwochildrenornone.Thatmeansevery internal node musthave exactlytwochildren.
  • 5. >>2. COMPLETEBINARY TREE(PerfectBinaryTree) In a binarytree,everynode canhave a maximumof twochildren.Butinstrictlybinarytree,everynode shouldhave exactlytwochildrenornone andincomplete binarytree all the nodesmusthave exactly twochildrenandat everylevel of complete binarytree theremustbe 2^n level numberof nodes.For example atlevel 2there mustbe 2^2 = 4 nodesandat level 3there mustbe 2^3 = 8 nodes. A binary tree in which every internal node has exactly two children and all leaf nodes are at samelevel is called Complete Binary Tree. Complete binarytree isalsocalledas PerfectBinaryTree. 3.EXTRENDED BINARYTREE A binarytree can be convertedintoFull Binarytree byaddingdummynodestoexistingnodeswherever required .The full binary tree obtained by adding dummy nodes to a binary tree is called as Extended Binary Tree.
  • 6. ######################################## # REPRESENTATION OF BINARY TREE: (normal trees cann’t be represent as array and link list,justbecauseof there irregular shape.) 1. linked list representation 2. Array representation (Let we have this binary tree.) 1. linked list representation 2. Array representation (1-D) HERE THE ARRANGEMENT OF DATA IS DONE ON THE BASESE OF “ 2*K , 2*K +1 “ OFCHILDS OF EVERY NODE . ( K IS THE NODE NUMBER GIVEN ,(STARTS FORM 0).
  • 8. ############################################### # BINARY TREE TRAVERSALS (TO DISPLAY A BINARY TREE WE NEED TO FOLLOW SOME ORDERS ) 1. INORDER 2. PREORDER 3. POSTORDER (HOPELLY U ALL KNOW HOW TO DO THESE JUST VERIFY ANSWERS ) 1. 1. In - Order Traversal( leftChild - root- rightChild ) I - D - J - B - F - A - G - K - C – H
  • 9. 2. Pre - OrderTraversal ( root - leftChild - rightChild) A - B - D - I - J - F - C - G - K - H 3. Post - OrderTraversal ( leftChild - rightChild - root) I - J - D - F - B - K - G - H - C – A Program for all three method is : #include <stdio.h> #include <stdlib.h> struct node { intvalue; struct node*left; struct node*right; }; struct node*root; struct node*insert(structnode*r,intdata); voidinOrder(structnode*r); voidpreOrder(structnode*r); voidpostOrder(structnode*r); intmain() { root= NULL; int n,i,v; printf("Howmanydata'sdoyou wantto insert?n"); scanf("%d",&n); for( i=0; i<n;i++){ printf("Data%d:",i+1); scanf("%d",&v);
  • 10. root= insert(root,v);} printf("InorderTraversal:"); inOrder(root); printf("n"); printf("PreorderTraversal:"); preOrder(root); printf("n"); printf("PostorderTraversal:"); postOrder(root); printf("n"); return0; } struct node*insert(structnode*r,intdata) { if(r==NULL) { r = (structnode*) malloc(sizeof(structnode)); r->value =data; r->left=NULL; r->right= NULL; } else if(data<r->value){ r->left=insert(r->left,data);} else { r->right= insert(r->right,data); }returnr; } voidinOrder(structnode*r)
  • 12. A binarytree isrepresentedusingarrayrepresentationorlinkedlistrepresentation.Whenabinarytree isrepresentedusinglinkedlistrepresentation,if anynode isnothavinga childwe use NULL pointerin that position.Inanybinarytree linkedlistrepresentation,there are more numberof NULL pointerthan actual pointers.Generally,inanybinarytree linkedlistrepresentation,if there are 2N numberof reference fields,then N+1numberof reference fieldsare filledwithNULL( N+1 are NULL outof 2N ). ThisNULL pointerdoesnotplayanyrole exceptindicatingthereisnolink(nochild). Threaded Binary Tree is also a binary tree in which all left child pointers that are NULL (in Linked list representation) points to its in-order predecessor, and all right child pointers that are NULL (in Linked list representation) points to its in-order successor. (STEPS TO SOLVE THREDED BINARY TREE . (REPRESENT THIS)) 1. WRITE INORDER OF TREE. 2. ONE WAY  RIGHT NODE: jointhe inoder successerof of node represented byarrow . 3. TWO WAY -> RIGHT +LEFT NODE : jointhe inorder predecessor. 4. else if nither predecessorof successerispresentof the node thenthatnode isrepresentbyNULL.
  • 13. # HUFFMAN ALGORITHM (IMPORTANT EVEN) HOPLLY U CAN DO IT (THIS ALGO IS GREAT , FOR STORE THE DATA IN ANOTHER WAY (BY ITS WAY) EXCEPT OF OUR OWN ) *HEIGHT OF TREE FORM IS -> N-1 (WHERE THE ‘N’ IS TOTAL NO. OF ELEMENTS TO BE ARRANGE.) An example is Q. arrange these element 2,3,5,7,9,11 using huffman algorithm ? Steps are: 1. Add smallest elements at level first. 2. Compare answer with given element if a. If answer is smaller or equal to any element then proceed to add at upper level. b. If answer is greater then the other elements , proceed to add any other two smaller numbers(can include answer or another element). Made by Gaurav Sharma…