615.04 - Recursion and Dynamic Programming Biostatistics...

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

View Full Document Right Arrow Icon
Recursion and Dynamic Programming Biostatistics 615/815 ecture 4 Lecture 4
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 Lecture z Principles for analysis of algorithms Empirical Analysis Theoretical Analysis z Common relationships between inputs and running time z Described two simple search algorithms
Background image of page 2
Recursive refers to … z A function that is part of its own definition e.g. > = 0 N if ) 1 ( ) ( N Factorial N N Factorial = 0 N if 1 z A program that calls itself
Background image of page 3

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

View Full DocumentRight Arrow Icon
Key Applications of Recursion z Dynamic Programming Related to Markov processes in Statistics ivide- nd- onquer Algorithms z Divide and Conquer Algorithms ree Processing z Tree Processing
Background image of page 4
Recursive Function in C int factorial (int N ) { if ( N == 0 ) eturn ; return 1; else return N * factorial ( N - 1 ); }
Background image of page 5

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

View Full DocumentRight Arrow Icon
Key Features of Recursions z Simple solution for a few cases z Recursive definition for other values omputation of large N depends on smaller N Computation of large N depends on smaller N an be naturally expressed in a function z Can be naturally expressed in a function that calls itself oops are sometimes an alternative Loops are sometimes an alternative
Background image of page 6
Typical Recursion: A Typical Recursion: Euclid’s Algorithm z Algorithm for finding greatest common divisor of two integers a and b If a divides b GCD(a,b) is a Otherwise, find the largest integer t such that t + r b at + r = b GCD(a,b) = GCD(r,a)
Background image of page 7

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

View Full DocumentRight Arrow Icon
Euclid’s Algorithm in C int gcd (int a , int b ) { if ( a == 0 ) eturn return b ; return gcd ( b % a , a ); }
Background image of page 8
Evaluating GCD(4458, 2099) gcd(2099, 4458) gcd(350, 2099) gcd(349, 350) cd(1 349) gcd(1, 349) gcd(0, 1)
Background image of page 9

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

View Full DocumentRight Arrow Icon
Divide-And-Conquer Algorithms z Common class of recursive functions z Common feature Process input Divide input in smaller portions Recursive call(s) process at least one portion z Recursion may sometimes occur before input is processed
Background image of page 10
Recursive Binary Search int search (int a [], int value, int start, int stop ) { // Search failed if ( start > stop ) return -1 ; // Find midpoint int mid = ( start + stop ) / 2; // Compare midpoint to value if ( value == a [ mid ]) return mid; // Reduce input in half!!!
Background image of page 11

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

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/26/2011 for the course BIO 615 taught by Professor Abecasis during the Fall '10 term at University of Michigan.

Page1 / 38

615.04 - Recursion and Dynamic Programming Biostatistics...

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

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