Alice chap 7

# Alice chap 7 - After finishing this chapter you should be...

This preview shows pages 1–4. Sign up to view the full content.

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

View Full Document

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: After finishing this chapter, you should be able to: o Provide brief definitions of the following terms: base case, base condition, conditional recursion, exponential recursion, infinite recursion, iteration, iterative process, linear recursion, overhead, recursion, and recursive method o Describe the usage of a recursive algorithm o Describe how recursion differs from iteration, including the cost of recursion, and roughly how to tell when one might be more appropriate to use than the other o Describe the difference between infinite recursion and conditional recursion o Create a recursive method in Alice o Convert an iterative Alice method into a linear recursive method o Convert a linear recursive Alice method into an iterative method RECURSIVE ALGORITHMS 187 7 7 Chapter C5777 36525 1/9/06 11:11 AM Page 187 188 Chapter 7 • Recursive Algorithms WHAT IS RECUSION? This chapter is about recursion. Generally, something is said to be recursive if each of the parts that make up the thing have a structure—in other words, a design or pattern—that repeats the structure of the whole thing itself. Consider the fern in Figure 7-1. Each leaf of the fern has a pattern that is virtually identical to the overall fern itself. In fact, if you look closely at the leaf, you can see that the parts that make up the leaf have patterns that match the leaf itself. If you were to go deeper and deeper into the structure of the fern, you would see that the same pattern is repeated again and again, each time on a smaller scale, each time in more detail. The fern has a recursive structure—parts of the fern have structures that mirror the overall structure of the fern itself. There are many such examples of recur- sion in the natural world. Recursion is not a simple concept, so often it takes a while for someone who has never seen it before to really understand what it’s all about. This chapter is not intended to make you an expert on recursion but only to expose you to the topic. By the time you are done, you should have a basic understanding of what a recursive algorithm is. Before going on, let’s take a look at another example. Can you see how the following very short story is recursive? FIGURE 7-1: A fern with a recursive structure 7 Chapter C5777 36525 1/9/06 11:11 AM Page 188 189 Recursive Algorithms Once upon a time a young princess was sitting with her father, the king. She said to her father, “My Royal Father, can you read me a story?” “Yes my Royal Daughter,” said the king, as he opened the Royal Storybook. He began to read, “Once upon a time a young princess was sitting with her father, the king. She said to her father, ‘My Royal Father, can you read me a story?’” “Yes my Royal Daughter,” said the king, as he opened the Royal Storybook. He began to read, “Once upon a time a young princess was sitting with her father, the king. She said to her father, ‘My Royal Father, can you read me a story?’” RECURSIVE ALGORITHMS In computer programming, an algorithm that calls itself is said to be recursive. ThroughoutIn computer programming, an algorithm that calls itself is said to be recursive....
View Full Document

{[ snackBarMessage ]}

### Page1 / 24

Alice chap 7 - After finishing this chapter you should be...

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

View Full Document
Ask a homework question - tutors are online