SlideShare a Scribd company logo
1 of 2
Binary Trees in C
Write a C function that accepts a pointer to a binary tree and a pointer to a node of the tree and
returns the level of the node in the tree.
Solution
Answer:
sturct binarytreenode {
int data;
struct binarytreenode *left;
struct binarytreenode *right;
}
int find(struct binarytreenode *tree, struct binarytreenode *u, int height)
{
int leftheight,rightheight;
if(tree==NULL)
return(-1);
if(tree==u)
return(height);
leftheight=find(tree->left,u,height+1);
if (leftheight != -1)
return(leftheight);
else
return(find(tree->right,u,height+1));
}
main()
{
struct binarytreenode *root, *u
height(root, u, 0);
}
Binary Trees in C Write a C function that accepts a pointer to a binar.docx

More Related Content

More from curtisp2

Calculate the cell potential (Ecell for the following lead concentrati.docx
Calculate the cell potential (Ecell for the following lead concentrati.docxCalculate the cell potential (Ecell for the following lead concentrati.docx
Calculate the cell potential (Ecell for the following lead concentrati.docxcurtisp2
 
Calculate -OH-- concentration of solutions with the following pH value.docx
Calculate -OH-- concentration of solutions with the following pH value.docxCalculate -OH-- concentration of solutions with the following pH value.docx
Calculate -OH-- concentration of solutions with the following pH value.docxcurtisp2
 
Cafeteria plan has following advantages- 1-Employees more likely to ap.docx
Cafeteria plan has following advantages- 1-Employees more likely to ap.docxCafeteria plan has following advantages- 1-Employees more likely to ap.docx
Cafeteria plan has following advantages- 1-Employees more likely to ap.docxcurtisp2
 
C++ a) What is a null pointer- b) Give an example of a function that r.docx
C++ a) What is a null pointer- b) Give an example of a function that r.docxC++ a) What is a null pointer- b) Give an example of a function that r.docx
C++ a) What is a null pointer- b) Give an example of a function that r.docxcurtisp2
 
By treating a student as aSolutionInvitation of appliction for admissi.docx
By treating a student as aSolutionInvitation of appliction for admissi.docxBy treating a student as aSolutionInvitation of appliction for admissi.docx
By treating a student as aSolutionInvitation of appliction for admissi.docxcurtisp2
 
By how much will the pH change if 0-025 mol of HCl is added to 1-00 L.docx
By how much will the pH change if 0-025 mol of HCl is added to 1-00 L.docxBy how much will the pH change if 0-025 mol of HCl is added to 1-00 L.docx
By how much will the pH change if 0-025 mol of HCl is added to 1-00 L.docxcurtisp2
 
Build a trie of the following terms using- a- A pointer representation.docx
Build a trie of the following terms using- a- A pointer representation.docxBuild a trie of the following terms using- a- A pointer representation.docx
Build a trie of the following terms using- a- A pointer representation.docxcurtisp2
 

More from curtisp2 (7)

Calculate the cell potential (Ecell for the following lead concentrati.docx
Calculate the cell potential (Ecell for the following lead concentrati.docxCalculate the cell potential (Ecell for the following lead concentrati.docx
Calculate the cell potential (Ecell for the following lead concentrati.docx
 
Calculate -OH-- concentration of solutions with the following pH value.docx
Calculate -OH-- concentration of solutions with the following pH value.docxCalculate -OH-- concentration of solutions with the following pH value.docx
Calculate -OH-- concentration of solutions with the following pH value.docx
 
Cafeteria plan has following advantages- 1-Employees more likely to ap.docx
Cafeteria plan has following advantages- 1-Employees more likely to ap.docxCafeteria plan has following advantages- 1-Employees more likely to ap.docx
Cafeteria plan has following advantages- 1-Employees more likely to ap.docx
 
C++ a) What is a null pointer- b) Give an example of a function that r.docx
C++ a) What is a null pointer- b) Give an example of a function that r.docxC++ a) What is a null pointer- b) Give an example of a function that r.docx
C++ a) What is a null pointer- b) Give an example of a function that r.docx
 
By treating a student as aSolutionInvitation of appliction for admissi.docx
By treating a student as aSolutionInvitation of appliction for admissi.docxBy treating a student as aSolutionInvitation of appliction for admissi.docx
By treating a student as aSolutionInvitation of appliction for admissi.docx
 
By how much will the pH change if 0-025 mol of HCl is added to 1-00 L.docx
By how much will the pH change if 0-025 mol of HCl is added to 1-00 L.docxBy how much will the pH change if 0-025 mol of HCl is added to 1-00 L.docx
By how much will the pH change if 0-025 mol of HCl is added to 1-00 L.docx
 
Build a trie of the following terms using- a- A pointer representation.docx
Build a trie of the following terms using- a- A pointer representation.docxBuild a trie of the following terms using- a- A pointer representation.docx
Build a trie of the following terms using- a- A pointer representation.docx
 

Recently uploaded

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 

Recently uploaded (20)

Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 

Binary Trees in C Write a C function that accepts a pointer to a binar.docx

  • 1. Binary Trees in C Write a C function that accepts a pointer to a binary tree and a pointer to a node of the tree and returns the level of the node in the tree. Solution Answer: sturct binarytreenode { int data; struct binarytreenode *left; struct binarytreenode *right; } int find(struct binarytreenode *tree, struct binarytreenode *u, int height) { int leftheight,rightheight; if(tree==NULL) return(-1); if(tree==u) return(height); leftheight=find(tree->left,u,height+1); if (leftheight != -1) return(leftheight); else return(find(tree->right,u,height+1)); } main() { struct binarytreenode *root, *u height(root, u, 0); }