11-recursive_programming

# 11-recursive_programming - CSE143 Lecture11...

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

CSE 143 Lecture 11 Recursive Programming slides created by Marty Stepp http://www.cs.washington.edu/143/

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

View Full Document
2 Decimal Numbers A visual review of decimal numbers: We get 348 by adding powers of 10 348 =  300 + 40 + 8 = 3 ×10 2  + 4 ×10 1  + 8×10 0   That’s why the decimal system is  base 10
3 Binary Numbers Binary is exactly the same, but  base 2 Decimal Binary Sum 0 0 0 × 2 0   1 1 1 × 2 0   2 10 1 × 2 1  + 0 × 2 0   3 11 1 × 2 1  + 1 × 2 0   4 100 1 × 2 2  + 0 × 2 1  + 0 × 2 0   5 101 1 × 2 2  + 0 × 2 1  + 1 × 2 0   6 110 1 × 2 2  + 1 × 2 1  + 0 × 2 0   7 111 1 × 2 2  + 1 × 2 1  + 1 × 2 0   8 1000 1 × 2 3  + 0 × 2 2  + 0 × 2 1  + 0 × 2 0

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

View Full Document
4 Exercise Write a recursive method  printBinary  that accepts an  integer and prints that number's representation in binary  (base 2) . Example:  printBinary(7)  prints 111 Example:  printBinary(12)  prints 1100 Example:  printBinary(42)  prints 101010 Write the method recursively and without using any loops. plac e 1 0 1 3 2 1 6 8 4 2 1 valu e 4 2 1 0 1 0 1 0
5 Case analysis Recursion is about solving a small piece of a large problem. What is 69743 in binary? Do we know  anything   about its representation in binary? Case analysis: What is/are easy numbers to print in binary? Can we express a larger number in terms of a smaller number(s)? Suppose we are examining some arbitrary integer

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.

{[ snackBarMessage ]}

### Page1 / 18

11-recursive_programming - CSE143 Lecture11...

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

View Full Document
Ask a homework question - tutors are online