Recursion1.2

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

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

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.

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

View Full Document
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
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 02/14/2012 for the course CSE 2011Z taught by Professor Elder during the Fall '11 term at York University.

### 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
Ask a homework question - tutors are online