SlideShare uma empresa Scribd logo
1 de 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)

Mais conteúdo relacionado

Mais de rtodd665

Mais de 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
 

Último

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
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
heathfieldcps1
 
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
QucHHunhnh
 

Último (20)

Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
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
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
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
 
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
 
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
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 

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)