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 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: C M L Click to edit Master subtitle style 10/22/10 C M L CSE 310 Algorithms and Data Structures Aviral Shrivastava Assistant Professor Computer Science and Engineering Arizona State University C M L 10/22/10 C M L Announcements • Assignment 2 is online – Due by Monday, June 21, 2010 • Assignment 3 is online – Due Monday, June 28, 2010 • Teaching Assistant – Ke Bai, [email protected] – BYENG 407 AA – Office Hours: 12:00 pm – 1:00 pm • No class on June 21, and June 23 • Yes Class on June 28 • Midterm on June 30 – Open book, open notes – closed computers C M L 10/22/10 C M L CSE 310 Roadmap • Induction • Recursion • Complexity Analysis • Sorting • Selection C M L 10/22/10 C M L Algorithm • An ' algorithm' is a method for solving a problem expressed as a finite sequence of instructions. – Proof of correctness: always give the right answer and never give a wrong answer – Proof of termination: always be completed in a finite number of steps, rather than in an infinite number C M L 10/22/10 C M L Power Function • T(n) = Time required to solve a problem of size n • Recurrence relations are used to determine the running time of recursive programs – recurrence relations themselves are recursive • T(0) = time to solve problem of size 0 – Base Case • T(n) = time to solve problem of size n long power(long x, long n) if (n == 0) return 1; else return x * power(x, n1); T(0) = c1 for some constant c1 T(n) = c2 + T(n  1) for some constant c2 T(n) = Ѳ(n) C M L 10/22/10 C M L Improved Power Algorithm long power(long x, long n) if (n==0) return 1; if ((n % 2) == 0) return power(x,n/2) * power(x,n/ 2); else return power(x,n/2) * power(x,n/ 2) * x; T(0) = c1 for some constant c1 T(n) = T(n/2) +c2 for some constant c2 T(n) = Ѳ(lgn) C M L 10/22/10 C M L Recurrences • The expression: is a recurrence . – Recurrence: an equation that describes a function in terms of its + = = 1 2 2 1 ) ( n c n T n c n T C M L 10/22/10 C M L Recurrence Examples = + = ) 1 ( ) ( n n n s c n s  + = = ) 1 ( ) ( n n s n n n s + = = 1 2 2 1 ) ( n c n T n c n T + = = 1 1 ) ( n cn b n aT n c n T C M L 10/22/10 C M L Solving Recurrences • Substitution method • Iteration method • Master method C M L 10/22/10 C M L Solving Recurrences • The substitution method (CLR 4.1) – A.k.a. the “making a good guess method” – Guess the form of the answer, then use induction to find the constants and show that solution works – Examples: • T(n) = 2T(n/2) + & (n) & T(n) = &(n lg n) C...
View
Full Document
 Spring '08
 Davulcu,H
 Algorithms, Data Structures, Trigraph, LG, ml, CN, Recurrence relation, Aviral Shrivastava

Click to edit the document details