SlideShare ist ein Scribd-Unternehmen logo
1 von 2
Any problem that can be solved with recursion could be re-implemented with loops.
True
False
Solution
Yes True
There are times where using recursion is better than using a loop, and times where using a loop is
better than using recursion. Choosing the "right" one can save resources and/or result in fewer
lines of code.
Are there any cases where a task can only be done using recursion, rather than a loop
Loops without recursion can definitely simulate recursion if given a stack, but what about
recursion, can it solve whatever problems loops can solve
Yes. Recursion to implement loops is a common idiom For example
For example
def foo()
s=0;
i=0;
while i<10
s=s+i;
i=i+1;
return s;
print foo();
the above code can be ritten as:
def foo(s,i);
if i<10;
return foo(s+i,i+1);
return s;
print foo(0,0)

Weitere ähnliche Inhalte

Mehr von rtodd665

Answer the following questions or fill in the blanks using information.docx
Answer the following questions or fill in the blanks using information.docxAnswer the following questions or fill in the blanks using information.docx
Answer the following questions or fill in the blanks using information.docxrtodd665
 
app-tophat-com 21 Solutions Now we can simulate doing a 5-fold dilutio.docx
app-tophat-com 21 Solutions Now we can simulate doing a 5-fold dilutio.docxapp-tophat-com 21 Solutions Now we can simulate doing a 5-fold dilutio.docx
app-tophat-com 21 Solutions Now we can simulate doing a 5-fold dilutio.docxrtodd665
 
Answer- 4-975 light years 2- Round-Trip Visit to a Star Suppose the sp.docx
Answer- 4-975 light years 2- Round-Trip Visit to a Star Suppose the sp.docxAnswer- 4-975 light years 2- Round-Trip Visit to a Star Suppose the sp.docx
Answer- 4-975 light years 2- Round-Trip Visit to a Star Suppose the sp.docxrtodd665
 
Anser in your own words- How did the enclosures law fuel the Industria.docx
Anser in your own words- How did the enclosures law fuel the Industria.docxAnser in your own words- How did the enclosures law fuel the Industria.docx
Anser in your own words- How did the enclosures law fuel the Industria.docxrtodd665
 
Any help is appreciated- thank you- 2d- What is the difference between.docx
Any help is appreciated- thank you- 2d- What is the difference between.docxAny help is appreciated- thank you- 2d- What is the difference between.docx
Any help is appreciated- thank you- 2d- What is the difference between.docxrtodd665
 
Assume that you have an aqueous solution of an unknown salt- Treatment.docx
Assume that you have an aqueous solution of an unknown salt- Treatment.docxAssume that you have an aqueous solution of an unknown salt- Treatment.docx
Assume that you have an aqueous solution of an unknown salt- Treatment.docxrtodd665
 
Assume that you have the following incomplete definitions of Graph and.docx
Assume that you have the following incomplete definitions of Graph and.docxAssume that you have the following incomplete definitions of Graph and.docx
Assume that you have the following incomplete definitions of Graph and.docxrtodd665
 
Assume that the amounts of the company Oslo Company prepared the f.docx
Assume that the amounts of the company    Oslo Company  prepared the f.docxAssume that the amounts of the company    Oslo Company  prepared the f.docx
Assume that the amounts of the company Oslo Company prepared the f.docxrtodd665
 
Assume that bands is an ArrayList of String objects which contains a n.docx
Assume that bands is an ArrayList of String objects which contains a n.docxAssume that bands is an ArrayList of String objects which contains a n.docx
Assume that bands is an ArrayList of String objects which contains a n.docxrtodd665
 
Assume DRAM access time is 70 ns- and tha the memory accesses are 36-.docx
Assume DRAM access time is 70 ns- and tha the memory accesses are 36-.docxAssume DRAM access time is 70 ns- and tha the memory accesses are 36-.docx
Assume DRAM access time is 70 ns- and tha the memory accesses are 36-.docxrtodd665
 

Mehr von rtodd665 (10)

Answer the following questions or fill in the blanks using information.docx
Answer the following questions or fill in the blanks using information.docxAnswer the following questions or fill in the blanks using information.docx
Answer the following questions or fill in the blanks using information.docx
 
app-tophat-com 21 Solutions Now we can simulate doing a 5-fold dilutio.docx
app-tophat-com 21 Solutions Now we can simulate doing a 5-fold dilutio.docxapp-tophat-com 21 Solutions Now we can simulate doing a 5-fold dilutio.docx
app-tophat-com 21 Solutions Now we can simulate doing a 5-fold dilutio.docx
 
Answer- 4-975 light years 2- Round-Trip Visit to a Star Suppose the sp.docx
Answer- 4-975 light years 2- Round-Trip Visit to a Star Suppose the sp.docxAnswer- 4-975 light years 2- Round-Trip Visit to a Star Suppose the sp.docx
Answer- 4-975 light years 2- Round-Trip Visit to a Star Suppose the sp.docx
 
Anser in your own words- How did the enclosures law fuel the Industria.docx
Anser in your own words- How did the enclosures law fuel the Industria.docxAnser in your own words- How did the enclosures law fuel the Industria.docx
Anser in your own words- How did the enclosures law fuel the Industria.docx
 
Any help is appreciated- thank you- 2d- What is the difference between.docx
Any help is appreciated- thank you- 2d- What is the difference between.docxAny help is appreciated- thank you- 2d- What is the difference between.docx
Any help is appreciated- thank you- 2d- What is the difference between.docx
 
Assume that you have an aqueous solution of an unknown salt- Treatment.docx
Assume that you have an aqueous solution of an unknown salt- Treatment.docxAssume that you have an aqueous solution of an unknown salt- Treatment.docx
Assume that you have an aqueous solution of an unknown salt- Treatment.docx
 
Assume that you have the following incomplete definitions of Graph and.docx
Assume that you have the following incomplete definitions of Graph and.docxAssume that you have the following incomplete definitions of Graph and.docx
Assume that you have the following incomplete definitions of Graph and.docx
 
Assume that the amounts of the company Oslo Company prepared the f.docx
Assume that the amounts of the company    Oslo Company  prepared the f.docxAssume that the amounts of the company    Oslo Company  prepared the f.docx
Assume that the amounts of the company Oslo Company prepared the f.docx
 
Assume that bands is an ArrayList of String objects which contains a n.docx
Assume that bands is an ArrayList of String objects which contains a n.docxAssume that bands is an ArrayList of String objects which contains a n.docx
Assume that bands is an ArrayList of String objects which contains a n.docx
 
Assume DRAM access time is 70 ns- and tha the memory accesses are 36-.docx
Assume DRAM access time is 70 ns- and tha the memory accesses are 36-.docxAssume DRAM access time is 70 ns- and tha the memory accesses are 36-.docx
Assume DRAM access time is 70 ns- and tha the memory accesses are 36-.docx
 

Kürzlich hochgeladen

mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
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
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
“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
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 

Kürzlich hochgeladen (20)

mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
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...
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
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"
 
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
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . 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...
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

Any problem that can be solved with recursion could be re-implemented.docx

  • 1. Any problem that can be solved with recursion could be re-implemented with loops. True False Solution Yes True There are times where using recursion is better than using a loop, and times where using a loop is better than using recursion. Choosing the "right" one can save resources and/or result in fewer lines of code. Are there any cases where a task can only be done using recursion, rather than a loop Loops without recursion can definitely simulate recursion if given a stack, but what about recursion, can it solve whatever problems loops can solve Yes. Recursion to implement loops is a common idiom For example For example def foo() s=0; i=0; while i<10 s=s+i; i=i+1; return s;
  • 2. print foo(); the above code can be ritten as: def foo(s,i); if i<10; return foo(s+i,i+1); return s; print foo(0,0)