ics141-lecture21-RecursionCounting

# ics141-lecture21-RecursionCounting - 21-1ICS 141: Discrete...

This preview shows pages 1–7. 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 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: 21-1ICS 141: Discrete Mathematics I (Spr 2008)University of HawaiiICS141: Discrete Mathematics for Computer Science IDepartment of Information and Computer SciencesUniversity of HawaiiStephen Y. Itoga21-2ICS 141: Discrete Mathematics I (Spr 2008)University of HawaiiLecture 21Chapter 4. Induction and Recursion4.4 Recursive AlgorithmsChapter 5. Counting5.1 The Basics of Counting 21-3ICS 141: Discrete Mathematics I (Spr 2008)University of HawaiiSome material in these slides were taken/adapted from the slides made by Prof. Michael P. Frank and Prof. Jonathan L. Gross which are provided through the publisher of “Discrete Mathematics and Its Applications” written by Kenneth H. Rosen.Some slides were done by Prof. Baek.21-4ICS 141: Discrete Mathematics I (Spr 2008)University of HawaiiRecursive AlgorithmsRecursive definitions can be used to describe algorithmsas well as functions and sets.A recursive procedureis a procedure that invokes itself.A recursive algorithmis an algorithm that contains a recursive procedure.An algorithm is called recursive if it solves a problem by reducing it to an instance of the same problem with smaller input.21-5ICS 141: Discrete Mathematics I (Spr 2008)University of HawaiiRecursive Euclid’s Algorithmgcd(a, b) = gcd((bmod a), a)proceduregcd(a, b∈N with a<b)ifa= 0 thenreturn belse returngcd(bmoda, a)Note recursive algorithms are often simpler to code than iterative ones… However, they can consume more stack space, if your compiler is not smart enough.21-6ICS 141: Discrete Mathematics I (Spr 2008)University of HawaiiRecursive Linear Searchproceduresearch(a: series; i, j: integer;x: item to be found){Find xin series aat a location ≥iand<j}if ai= xreturni {At the right item? Return it!}ifi= jreturn0 {No locations in range?...
View Full Document

## This note was uploaded on 09/12/2008 for the course ICS 141 taught by Professor Idk during the Fall '08 term at Hawaii.

### Page1 / 21

ics141-lecture21-RecursionCounting - 21-1ICS 141: Discrete...

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

View Full Document
Ask a homework question - tutors are online