Loading in 5 sec....

CS 312: Algorithm AnalysisPowerPoint Presentation

CS 312: Algorithm Analysis

- By
**eben** - Follow User

- 66 Views
- Uploaded on

Download Presentation
## PowerPoint Slideshow about ' CS 312: Algorithm Analysis' - eben

**An Image/Link below is provided (as is) to download presentation**

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

### CS 312: Algorithm Analysis

This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.

Lecture #2: Asymptotic Notation

Slides by: Eric Ringger, with contributions from Mike Jones, Eric Mercer, Sean Warnick

Quiz

- What is the reward for submitting project reports early?
- How many penalty-free late days are in your budget for the semester?
- How many penalty-free late days can you use on any one project?
- What is the penalty for late submission of project reports (after you’ve used your penalty-free late days)?
- T/F: You may submit late regular homework assignments.

Announcements

- Your initial experiences with Visual Studio?
- My office hours updated: Tu & Th 2-3 and by appointment
- TA office hours are on the course wiki
- Different kinds of TAs

- Project #1
- Instructions are linked from the online schedule
- Help session with TA
- Thursday at 4pm
- In the Windows help lab (1066 TMCB)
- Focus on intro. to C# and Visual Studio

- We’ll cover the mathematical ideas in class

- Purpose of help sessions

Objectives

- Revisit orders of growth
- Formally introduce asymptotic notation:O, W, Q
- Classify functions in asymptotic orders of growth

Orders of Growth

- Efficiency: how cost grows with the size/ difficulty n of a given problem instance.
- C(n): the cost (e.g., number of steps) required by an algorithm on an input of size / difficulty n.
- Order of growth: the functional form of C(n) up to a constant multipleas ngoes to infinity.

Orders of Growth

Efficient

- Best Case

- Need to decide which instance of a given size to use as the representative for that class:

Algorithm Domain

Instances

- Average Case (over all possible instances)

1 2 3 4 5

Instance size

Translation: An asymptotically non-negative function f(n) belongs to the set Q(g(n)) iff there exist positive constants c1 and c2such that f(n)can be “sandwiched” between c1g(n) and c2g(n), scaled versions of g(n), for sufficiently large n.

Convention:

Asymptotic NotationDefinition: given an asymptotically non-negative fn. g(n),

Asymptotic Notation

Definitions: given an asymptotically non-negative fn. g(n),

Distinguishing from

- Can you draw a function that is in but not ?

Distinguishing from

- Can you draw a function that is in but not ?

- Must find positive constants c1, c2, n0 such that

- Divide through by n2 to get

- Hint: consider one side of the inequality at a time:
- for n0=7 we have c1 1/14
- for n0=6 we have c2 >1/2; works for larger n0=7 as well

- This proof is constructive

Another Example

Show that

- Use proof by contradiction: assume that
- Suppose positive constants c2, n0 exist such that
- But this implies that
- i.e., is bounded by , a constant
- But is unbounded; hence we have a contradiction.
- Thus, our assumption was false; hence we have shown that

Other proof types?

- Induction
- Optional example on HW #1

- Deduction
- Others!

Useful Identity: L’Hopital’s Rule

Applicable when lim f(n) = lim g(n) = 0

and when lim f(n) = lim g(n) =

Assignment

- Read: Section 1.3
- HW #1: 0.1 (a-e, g, m) in the textbook
- Optional: 0.3 (a)
- Remember:
- Don’t spend more than 2 focused hours on the homework exercises.
- If you reach 2 hours of concentratedeffort, stop and make a note to that effect on your paper (unless you’re having fun and want to continue).
- The TAs will take that into consideration when grading.

Classic Multiplication

American Style

English Style

5001

x 502

10002

0

+ 25005

2510502

5001

x 502

25005

0

+ 10002

2510502

O(n2) for 2 n-digit numbers

Multiplication a la Francais / Russe

Multiplication a la Francais / Russe

Mulitplication a la Francais / Russe

function multiply(x,y)

Input: Two n-bit integers x and y, where y 0

Output: Their product

if y = 0: return 0

if y = 1: return x

z = multiply(x, floor(y/2))

if y is even:

return 2z

else:

return x+2z

Mulitplication a la Francais / Russe

function multiply(x,y)

Input: Two n-bit integers x and y, where y 0

Output: Their product

if y = 0: return 0

if y = 1: return x

z = multiply(x, floor(y/2))

if y is even:

return 2z

else:

return x+2z

Division

function divide(x,y)

Input: Two n-bit integers x and y, where y 1

Output: The quotient and remainder of x divided by y

if x=0: return (q, r) = (0,0)

(q, r) = divide(floor(x/2),y)

q=2*q, r=2*r

if x is odd: r=r+1

if r y: r=r-y, q=q+1

return (q, r)

Division

function divide(x,y)

Input: Two n-bit integers x and y, where y 1

Output: The quotient and remainder of x divided by y

if x=0: return (q, r) = (0,0)

(q, r) = divide(floor(x/2),y)

q=2*q, r=2*r

if x is odd: r=r+1

if r y: r=r-y, q=q+1

return (q, r)

Download Presentation

Connecting to Server..