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 DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 211ICS 141: Discrete Mathematics I (Spr 2008)University of HawaiiICS141: Discrete Mathematics for Computer Science IDepartment of Information and Computer SciencesUniversity of HawaiiStephen Y. Itoga212ICS 141: Discrete Mathematics I (Spr 2008)University of HawaiiLecture 21Chapter 4. Induction and Recursion4.4 Recursive AlgorithmsChapter 5. Counting5.1 The Basics of Counting 213ICS 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.214ICS 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.215ICS 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.216ICS 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.
 Fall '08
 IDK

Click to edit the document details