SlideShare a Scribd company logo
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
 
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
mallik3000
 
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
mallik3000
 
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
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
 
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
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 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
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
 
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
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
 
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
mallik3000
 
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
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

Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
rosedainty
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
Steve Thomason
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
PedroFerreira53928
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
GeoBlogs
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
Vivekanand Anglo Vedic Academy
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 

Recently uploaded (20)

Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 

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; }