SlideShare a Scribd company logo
Hint: Assume the binary tree is properly balanced (the depth of the tree T is O(log N)). For full
credit, your algorithm should run in O(K+log N) average time, where K is the number of keys
printed.
Solution
// Since the language is not specified, I'm doing it in C++.
// Assumption: structure of the tree node:
/*
struct Node{
int data;
Node *left;
Node *right;
};
*/
void method(Node *root, int k1, int k2){
if(root == NULL) return;
method(root->left);
if(root->data >= k1 && root->data <= k2) cout << root->data << " ";
method(root->right);
}

More Related Content

PDF
In class, we talked about all sorts of experiments. I would like to s.pdf
PDF
Jane Lee was employed as a secretary at Burton Trucking. She was fire.pdf
PDF
If a function F) performs the following operations, what knd of cohe.pdf
PDF
How would a subculture appear if a colony containing both S. Marce.pdf
PDF
essay question Explain how everyday life changes for slaves after e.pdf
PDF
Detection versus recognition ... Investigate Face++ at Feel free to.pdf
PDF
Dent disease is a rare disorder of the kidney in which reabsorption o.pdf
PDF
DEFINE maternal determinant (3-4 sentences).SolutionMaternal .pdf
In class, we talked about all sorts of experiments. I would like to s.pdf
Jane Lee was employed as a secretary at Burton Trucking. She was fire.pdf
If a function F) performs the following operations, what knd of cohe.pdf
How would a subculture appear if a colony containing both S. Marce.pdf
essay question Explain how everyday life changes for slaves after e.pdf
Detection versus recognition ... Investigate Face++ at Feel free to.pdf
Dent disease is a rare disorder of the kidney in which reabsorption o.pdf
DEFINE maternal determinant (3-4 sentences).SolutionMaternal .pdf

More from AroraRajinder1 (20)

PDF
Consider a partial function.For every unmapped element in its doma.pdf
PDF
Compare and Contrast hollow core fibers for high power delivery an.pdf
PDF
Can we create an object of type Interface Explain your answer.So.pdf
PDF
Cancel QuestionSolutionSince Descriptive statistics uses the d.pdf
PDF
According to the cladogram, what derived trait is shared by primates .pdf
PDF
A male Flagus fly with the Barkus phenotype is crossed with a female.pdf
PDF
2015Matthew and Michael Goode (cousins) decide to form a partners.pdf
PDF
1. Jose is a Latino client who presents with occupational difficulti.pdf
PDF
You have a small business customer who wants to use a voice over IP .pdf
PDF
Why can some microbial species grow and survive in extreme environ.pdf
PDF
Which prokaryotic group maps most closely to the chlorophyll of plan.pdf
PDF
Which of the following static methods allow an ArrayList of strings t.pdf
PDF
Which of the following factors can affect rate of enzyme activitypH.pdf
PDF
Which anchors of synthesis Which are cilia and N Which found in plan.pdf
PDF
What is social welfare policy Why should we study it What is the r.pdf
PDF
what is a problem we face due to the small size of microbes What is .pdf
PDF
What are the six classes of nutrients and there functionsSoluti.pdf
PDF
Use the data set below to answer the following questions. Complete pa.pdf
PDF
Significance of differences between mitosis and meiosis Mit.pdf
PDF
Suppose that L1 is the list (A (BC) and L2 is the list ((D E) F). .pdf
Consider a partial function.For every unmapped element in its doma.pdf
Compare and Contrast hollow core fibers for high power delivery an.pdf
Can we create an object of type Interface Explain your answer.So.pdf
Cancel QuestionSolutionSince Descriptive statistics uses the d.pdf
According to the cladogram, what derived trait is shared by primates .pdf
A male Flagus fly with the Barkus phenotype is crossed with a female.pdf
2015Matthew and Michael Goode (cousins) decide to form a partners.pdf
1. Jose is a Latino client who presents with occupational difficulti.pdf
You have a small business customer who wants to use a voice over IP .pdf
Why can some microbial species grow and survive in extreme environ.pdf
Which prokaryotic group maps most closely to the chlorophyll of plan.pdf
Which of the following static methods allow an ArrayList of strings t.pdf
Which of the following factors can affect rate of enzyme activitypH.pdf
Which anchors of synthesis Which are cilia and N Which found in plan.pdf
What is social welfare policy Why should we study it What is the r.pdf
what is a problem we face due to the small size of microbes What is .pdf
What are the six classes of nutrients and there functionsSoluti.pdf
Use the data set below to answer the following questions. Complete pa.pdf
Significance of differences between mitosis and meiosis Mit.pdf
Suppose that L1 is the list (A (BC) and L2 is the list ((D E) F). .pdf

Recently uploaded (20)

PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
RMMM.pdf make it easy to upload and study
PPTX
Lesson notes of climatology university.
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Insiders guide to clinical Medicine.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Sports Quiz easy sports quiz sports quiz
PDF
Computing-Curriculum for Schools in Ghana
PDF
01-Introduction-to-Information-Management.pdf
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Cell Structure & Organelles in detailed.
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Final Presentation General Medicine 03-08-2024.pptx
RMMM.pdf make it easy to upload and study
Lesson notes of climatology university.
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
human mycosis Human fungal infections are called human mycosis..pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
TR - Agricultural Crops Production NC III.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Insiders guide to clinical Medicine.pdf
Microbial disease of the cardiovascular and lymphatic systems
Sports Quiz easy sports quiz sports quiz
Computing-Curriculum for Schools in Ghana
01-Introduction-to-Information-Management.pdf
O7-L3 Supply Chain Operations - ICLT Program
Cell Structure & Organelles in detailed.
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx

Hint Assume the binary tree is properly balanced (the depth of the .pdf

  • 1. Hint: Assume the binary tree is properly balanced (the depth of the tree T is O(log N)). For full credit, your algorithm should run in O(K+log N) average time, where K is the number of keys printed. Solution // Since the language is not specified, I'm doing it in C++. // Assumption: structure of the tree node: /* struct Node{ int data; Node *left; Node *right; }; */ void method(Node *root, int k1, int k2){ if(root == NULL) return; method(root->left); if(root->data >= k1 && root->data <= k2) cout << root->data << " "; method(root->right); }