Recursion1.2 - Linear Recursion Design Pattern Test for...

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

View Full Document Right Arrow Icon
Last Updated 12-01-24 10:12 AM CSE 2011 Prof. J. Elder - 11 - Linear Recursion Design Pattern Test for base cases – Begin by testing for a set of base cases (there should be at least one). – Every possible chain of recursive calls must eventually reach a base case, and the handling of each base case should not use recursion. Recurse once – Perform a single recursive call. (This recursive step may involve a test that decides which of several possible recursive calls to make, but it should ultimately choose to make just one of these calls each time we perform this step.) – Define each possible recursive call so that it makes progress towards a base case.
Background image of page 1

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

View Full DocumentRight Arrow Icon
Last Updated 12-01-24 10:12 AM CSE 2011 Prof. J. Elder - 12 - Example 2: Computing Powers • The power function , p(x,n) = x n , can be defined recursively: • Assume multiplication takes constant time (independent of value of arguments). • This leads to a power function that runs in O
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

Recursion1.2 - Linear Recursion Design Pattern Test for...

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

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