Tut6_Sols - Programming & Data Structures Tutorial 6 –...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Programming & Data Structures Tutorial 6 – Sample Solutions Q1. Recursion differs to iteration in that Iteration terminates when the loop continuation condition fails. Recursion terminates when the base case is recognised. Each recursive call causes another copy of the function. Each iteration does not cause another copy of the function. An infinite loop in iteration can potentially loop forever. An infinite loop in recursion will continue to loop as long as there is enough memory to create another copy of that function. Due to the fact that recursion creates another copy of itself within itself we potentially have our previous step “memorized” in case we need to go back to that step. An example of where this might be useful is in problems such as the “knights” or “all queens” problem. We do not have this ability with iteration without creating a separate memory buffer variable of some sort, even then we may need some additional “not so obvious” logic. Q2.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/25/2010 for the course CPE CPE 360 taught by Professor Jenniferchen during the Spring '10 term at Stevens.

Page1 / 2

Tut6_Sols - Programming & Data Structures Tutorial 6 –...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online