CSE 310-Lecture4

CSE 310-Lecture4 - C M L Click to edit Master subtitle...

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the 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, n-1); 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

{[ snackBarMessage ]}

Page1 / 44

CSE 310-Lecture4 - C M L Click to edit Master subtitle...

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

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