SlideShare a Scribd company logo
1 of 2
Download to read offline
Write a program that finds the max binary tree height. (This is an extremely short piece of
code!)
Solution
#include
#include
#include
typedef struct node
{
int info;
struct node *left;
struct node *right;
}node;
node *newNode(int data)
{
node *ptr=(node *)malloc(sizeof(node));
ptr->info=data;
ptr->left=NULL;
ptr->right=NULL;
return ptr;
}
int height(node *root)
{
if(root==NULL)
return 0;
int l=height(root->left);
int m=height(root->right);
if(l>m)
return l+1;
else
return m+1;
}
int main()
{
struct node *root1 = newNode(1);
root1->left = newNode(2);
root1->right = newNode(3);
root1->left->left = newNode(4);
root1->left->right = newNode(5);
int m=height(root1);
printf("Height of the tree is :- %d",m);
getch();
return 0;
}

More Related Content

More from mallik3000

Change the creature in this java program to a different one .pdf
Change the creature in this java program to a different one .pdfChange the creature in this java program to a different one .pdf
Change the creature in this java program to a different one .pdf
mallik3000
 
Write a program in c++ that maintains a telephone directory. The Tel.pdf
Write a program in c++ that maintains a telephone directory. The Tel.pdfWrite a program in c++ that maintains a telephone directory. The Tel.pdf
Write a program in c++ that maintains a telephone directory. The Tel.pdf
mallik3000
 
Using the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdfUsing the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdf
mallik3000
 
What is the major purpose of the Federal Reserve System What is the.pdf
What is the major purpose of the Federal Reserve System What is the.pdfWhat is the major purpose of the Federal Reserve System What is the.pdf
What is the major purpose of the Federal Reserve System What is the.pdf
mallik3000
 
What methods can IT use to make sure its initiatives have the suppor.pdf
What methods can IT use to make sure its initiatives have the suppor.pdfWhat methods can IT use to make sure its initiatives have the suppor.pdf
What methods can IT use to make sure its initiatives have the suppor.pdf
mallik3000
 
What is IT infrastructure, and what are the stages and drivers of IT.pdf
What is IT infrastructure, and what are the stages and drivers of IT.pdfWhat is IT infrastructure, and what are the stages and drivers of IT.pdf
What is IT infrastructure, and what are the stages and drivers of IT.pdf
mallik3000
 
What is the difference between a dinoflagellate and a Stramenopi.pdf
What is the difference between a dinoflagellate and a Stramenopi.pdfWhat is the difference between a dinoflagellate and a Stramenopi.pdf
What is the difference between a dinoflagellate and a Stramenopi.pdf
mallik3000
 
The RIF at Keller Technology Inc.IntroductionJan Ricter is the n.pdf
The RIF at Keller Technology Inc.IntroductionJan Ricter is the n.pdfThe RIF at Keller Technology Inc.IntroductionJan Ricter is the n.pdf
The RIF at Keller Technology Inc.IntroductionJan Ricter is the n.pdf
mallik3000
 
A Secure httpsereader.chegg.com#books9781305465114cfi 5. EXPE.pdf
A Secure httpsereader.chegg.com#books9781305465114cfi 5. EXPE.pdfA Secure httpsereader.chegg.com#books9781305465114cfi 5. EXPE.pdf
A Secure httpsereader.chegg.com#books9781305465114cfi 5. EXPE.pdf
mallik3000
 
5. How do splicing and the RNAi mechanism regulate which mRNA molecu.pdf
5. How do splicing and the RNAi mechanism regulate which mRNA molecu.pdf5. How do splicing and the RNAi mechanism regulate which mRNA molecu.pdf
5. How do splicing and the RNAi mechanism regulate which mRNA molecu.pdf
mallik3000
 
The leader algorithm (Horrigan [394]) represents each cluster using a.pdf
The leader algorithm (Horrigan [394]) represents each cluster using a.pdfThe leader algorithm (Horrigan [394]) represents each cluster using a.pdf
The leader algorithm (Horrigan [394]) represents each cluster using a.pdf
mallik3000
 
The financial statements of Hainz Company appear below HAINZ COMPANY .pdf
The financial statements of Hainz Company appear below HAINZ COMPANY .pdfThe financial statements of Hainz Company appear below HAINZ COMPANY .pdf
The financial statements of Hainz Company appear below HAINZ COMPANY .pdf
mallik3000
 

More from mallik3000 (20)

Change the creature in this java program to a different one .pdf
Change the creature in this java program to a different one .pdfChange the creature in this java program to a different one .pdf
Change the creature in this java program to a different one .pdf
 
Canon Corporation had the following static budget at the beginning o.pdf
Canon Corporation had the following static budget at the beginning o.pdfCanon Corporation had the following static budget at the beginning o.pdf
Canon Corporation had the following static budget at the beginning o.pdf
 
Can someone please prove this equation is an identity. Cos^2.pdf
Can someone please prove this equation is an identity. Cos^2.pdfCan someone please prove this equation is an identity. Cos^2.pdf
Can someone please prove this equation is an identity. Cos^2.pdf
 
What happens when the JVM encounters a wait () callSolution=.pdf
What happens when the JVM encounters a wait () callSolution=.pdfWhat happens when the JVM encounters a wait () callSolution=.pdf
What happens when the JVM encounters a wait () callSolution=.pdf
 
Write a program in c++ that maintains a telephone directory. The Tel.pdf
Write a program in c++ that maintains a telephone directory. The Tel.pdfWrite a program in c++ that maintains a telephone directory. The Tel.pdf
Write a program in c++ that maintains a telephone directory. The Tel.pdf
 
Using the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdfUsing the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdf
 
Why are supplies and inventory not considered plant assetsSolut.pdf
Why are supplies and inventory not considered plant assetsSolut.pdfWhy are supplies and inventory not considered plant assetsSolut.pdf
Why are supplies and inventory not considered plant assetsSolut.pdf
 
What is the major purpose of the Federal Reserve System What is the.pdf
What is the major purpose of the Federal Reserve System What is the.pdfWhat is the major purpose of the Federal Reserve System What is the.pdf
What is the major purpose of the Federal Reserve System What is the.pdf
 
What is the role of culture in leader development What culture fact.pdf
What is the role of culture in leader development What culture fact.pdfWhat is the role of culture in leader development What culture fact.pdf
What is the role of culture in leader development What culture fact.pdf
 
What methods can IT use to make sure its initiatives have the suppor.pdf
What methods can IT use to make sure its initiatives have the suppor.pdfWhat methods can IT use to make sure its initiatives have the suppor.pdf
What methods can IT use to make sure its initiatives have the suppor.pdf
 
What is IT infrastructure, and what are the stages and drivers of IT.pdf
What is IT infrastructure, and what are the stages and drivers of IT.pdfWhat is IT infrastructure, and what are the stages and drivers of IT.pdf
What is IT infrastructure, and what are the stages and drivers of IT.pdf
 
What is the difference between a dinoflagellate and a Stramenopi.pdf
What is the difference between a dinoflagellate and a Stramenopi.pdfWhat is the difference between a dinoflagellate and a Stramenopi.pdf
What is the difference between a dinoflagellate and a Stramenopi.pdf
 
True or False O2 can be carried in the blood only when attached to .pdf
True or False O2 can be carried in the blood only when attached to .pdfTrue or False O2 can be carried in the blood only when attached to .pdf
True or False O2 can be carried in the blood only when attached to .pdf
 
The RIF at Keller Technology Inc.IntroductionJan Ricter is the n.pdf
The RIF at Keller Technology Inc.IntroductionJan Ricter is the n.pdfThe RIF at Keller Technology Inc.IntroductionJan Ricter is the n.pdf
The RIF at Keller Technology Inc.IntroductionJan Ricter is the n.pdf
 
Assigned as H6.24- Level 2 lby pure compound has a specific rotation .pdf
Assigned as H6.24- Level 2 lby pure compound has a specific rotation .pdfAssigned as H6.24- Level 2 lby pure compound has a specific rotation .pdf
Assigned as H6.24- Level 2 lby pure compound has a specific rotation .pdf
 
A synthetic mRNA containing the monomer uridine monophosphate as the .pdf
A synthetic mRNA containing the monomer uridine monophosphate as the .pdfA synthetic mRNA containing the monomer uridine monophosphate as the .pdf
A synthetic mRNA containing the monomer uridine monophosphate as the .pdf
 
A Secure httpsereader.chegg.com#books9781305465114cfi 5. EXPE.pdf
A Secure httpsereader.chegg.com#books9781305465114cfi 5. EXPE.pdfA Secure httpsereader.chegg.com#books9781305465114cfi 5. EXPE.pdf
A Secure httpsereader.chegg.com#books9781305465114cfi 5. EXPE.pdf
 
5. How do splicing and the RNAi mechanism regulate which mRNA molecu.pdf
5. How do splicing and the RNAi mechanism regulate which mRNA molecu.pdf5. How do splicing and the RNAi mechanism regulate which mRNA molecu.pdf
5. How do splicing and the RNAi mechanism regulate which mRNA molecu.pdf
 
The leader algorithm (Horrigan [394]) represents each cluster using a.pdf
The leader algorithm (Horrigan [394]) represents each cluster using a.pdfThe leader algorithm (Horrigan [394]) represents each cluster using a.pdf
The leader algorithm (Horrigan [394]) represents each cluster using a.pdf
 
The financial statements of Hainz Company appear below HAINZ COMPANY .pdf
The financial statements of Hainz Company appear below HAINZ COMPANY .pdfThe financial statements of Hainz Company appear below HAINZ COMPANY .pdf
The financial statements of Hainz Company appear below HAINZ COMPANY .pdf
 

Recently uploaded

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 

Recently uploaded (20)

AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food Additives
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdfUGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
UGC NET Paper 1 Unit 7 DATA INTERPRETATION.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Our Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdfOur Environment Class 10 Science Notes pdf
Our Environment Class 10 Science Notes pdf
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 

Write a program that finds the max binary tree height. (This is an ex.pdf

  • 1. Write a program that finds the max binary tree height. (This is an extremely short piece of code!) Solution #include #include #include typedef struct node { int info; struct node *left; struct node *right; }node; node *newNode(int data) { node *ptr=(node *)malloc(sizeof(node)); ptr->info=data; ptr->left=NULL; ptr->right=NULL; return ptr; } int height(node *root) { if(root==NULL) return 0; int l=height(root->left); int m=height(root->right); if(l>m) return l+1; else return m+1; } int main()
  • 2. { struct node *root1 = newNode(1); root1->left = newNode(2); root1->right = newNode(3); root1->left->left = newNode(4); root1->left->right = newNode(5); int m=height(root1); printf("Height of the tree is :- %d",m); getch(); return 0; }