SlideShare a Scribd company logo
1 of 1
Download to read offline
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

More from AroraRajinder1

Compare and Contrast hollow core fibers for high power delivery an.pdf
Compare and Contrast hollow core fibers for high power delivery an.pdfCompare and Contrast hollow core fibers for high power delivery an.pdf
Compare and Contrast hollow core fibers for high power delivery an.pdf
AroraRajinder1
 
2015Matthew and Michael Goode (cousins) decide to form a partners.pdf
2015Matthew and Michael Goode (cousins) decide to form a partners.pdf2015Matthew and Michael Goode (cousins) decide to form a partners.pdf
2015Matthew and Michael Goode (cousins) decide to form a partners.pdf
AroraRajinder1
 
1. Jose is a Latino client who presents with occupational difficulti.pdf
1. Jose is a Latino client who presents with occupational difficulti.pdf1. Jose is a Latino client who presents with occupational difficulti.pdf
1. Jose is a Latino client who presents with occupational difficulti.pdf
AroraRajinder1
 
Why can some microbial species grow and survive in extreme environ.pdf
Why can some microbial species grow and survive in extreme environ.pdfWhy can some microbial species grow and survive in extreme environ.pdf
Why can some microbial species grow and survive in extreme environ.pdf
AroraRajinder1
 
Which anchors of synthesis Which are cilia and N Which found in plan.pdf
Which anchors of synthesis Which are cilia and N Which found in plan.pdfWhich anchors of synthesis Which are cilia and N Which found in plan.pdf
Which anchors of synthesis Which are cilia and N Which found in plan.pdf
AroraRajinder1
 
What is social welfare policy Why should we study it What is the r.pdf
What is social welfare policy Why should we study it What is the r.pdfWhat is social welfare policy Why should we study it What is the r.pdf
What is social welfare policy Why should we study it What is the r.pdf
AroraRajinder1
 
What are the six classes of nutrients and there functionsSoluti.pdf
What are the six classes of nutrients and there functionsSoluti.pdfWhat are the six classes of nutrients and there functionsSoluti.pdf
What are the six classes of nutrients and there functionsSoluti.pdf
AroraRajinder1
 
Significance of differences between mitosis and meiosis Mit.pdf
Significance of differences between mitosis and meiosis Mit.pdfSignificance of differences between mitosis and meiosis Mit.pdf
Significance of differences between mitosis and meiosis Mit.pdf
AroraRajinder1
 

More from AroraRajinder1 (20)

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

Recently uploaded

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MysoreMuleSoftMeetup
 
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
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
cupulin
 

Recently uploaded (20)

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjjStl Algorithms in C++ jjjjjjjjjjjjjjjjjj
Stl Algorithms in C++ jjjjjjjjjjjjjjjjjj
 
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...When Quality Assurance Meets Innovation in Higher Education - Report launch w...
When Quality Assurance Meets Innovation in Higher Education - Report launch w...
 
8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management8 Tips for Effective Working Capital Management
8 Tips for Effective Working Capital Management
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....diagnosting testing bsc 2nd sem.pptx....
diagnosting testing bsc 2nd sem.pptx....
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
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
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.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); }