List ADTs - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

List ADTs

Description:

Run time is function of input. We count basic steps. When we count steps we put in terms of n. We can eliminate lower order terms. Recall... – PowerPoint PPT presentation

Number of Views:21
Avg rating:3.0/5.0
Slides: 21
Provided by: bal1
Category:
Tags: adts | list | putin | quadratic

less

Transcript and Presenter's Notes

Title: List ADTs


1
Algorithm Analysis
Capt Balazs Michelson 366
2
Recall
  • We are typically concerned with worst case
    running time of algorithms as input grows
  • Run time is function of input
  • We count basic steps
  • When we count steps we put in terms of n
  • We can eliminate lower order terms

3
Recall
  • Looked growth rates for alg_1 and alg_2
  • We determined that alg_1 took k2 6k 19 steps
    and alg_2 took 5k 13 steps
  • We are able to ignore constants and lower order
    terms
  • alg_2 has a linear growth rate
  • alg_1 grows like k2 (quadratic growth)

4
Technically Speaking
  • Notation used to describe algorithms running
    time called Asymptotic Notation
  • It is mathematic notation for functions that
    disregards constant factors and lower order terms
  • Describes growth rate of a function in terms of
    input size

5
? - Notation
  • Function f(n) that has a quadratic growth rate is
    said to grow like ?(n2)
  • Written as f(n) ?(n2)
  • In other words
  • f(n) has the same shape as n2
  • f(n) grows at a rate proportional to n2

6
More Generally
  • f(n) ?(g(n))
  • g(n) is n2 in our previous (specific) example
  • alg_1 alg_2 example
  • alg_1 f(n) ?(g(n)) g(n) is n2
  • alg_2 f(n) ?(g(n)) g(n) is n

7
f(n) ?(g(n))
After some cutoff point, n0 -where n0 is an
integer constant - f(n) is bound between constant
multiples of g(n). Therefore, f(n) grows like
g(n).
8
Formal Definition
  • ?(g(n)) f(n) ? (c1, c2, n0 gt0)
  • where 0 ? c1g(n) ? f(n) ? c2g(n)
  • ? n ? n0
  • Less Formal
  • A function (f(n)) belongs to the set ?(g(n)) if
    there exists c1 c2 gt 0 such that f(n) can be
    bound between c1g(n) and c2g(n) for all values
    of n greater than a sufficiently large value (n ?
    n0)

9
Note!
  • f(n) ?(g(n)) and f(n) ? ?(g(n)) are equivalent
  • If f(n) ?(g(n)) then g(n) is an asymptotically
    tight bound for f(n)
  • Key points
  • ?(g(n)) is a tight bound
  • ?(g(n)) is a set of functions

10
Big-O Notation
  • O(g(n)) f(n) ? (c, n0 gt0)
  • where 0 ? f(n) ? c g(n)
  • ? n ? n0

11
Big-O
O(g(n)) describes a worst case upper bound. It
is an asymptotic upper bound for f(n). No
matter what, f(n) will be no worse than g(n).
12
Big-O Example
  • Use definition of big-O to show
  • 2n2 22n -18 O(n2)

2n2 22n -18 ? 2n2 22n for all n gt 0 Want
n2 on right 22n ? n2 22 ? n 2n2 22n -18 ?
2n2 n2 for all n ? 22 2n2 22n -18 ? 3n2 for
all n ? 22 Thus, with c 3 and n0 22 we have
shown that 2n2 22n -18 O(n2)
13
Example of Asymptotic Upper Bound
4g(n)4n2
  • 4 g(n) 4n2
  • 3n2 n2
  • ? 3n2 9 for all n ? 3
  • gt 3n2 5
  • f(n)
  • Thus, f(n)O(g(n))

f(n)3n25
g(n)n2
3
14
Use Definition of Big-O to show that 6n3 is not
O(n2)
15
? - Notation
  • ?(g(n)) f(n) ? (c, n0 gt0)
  • where 0 ? cg(n) ? f(n)
  • ? n ? n0

Best case running time or lower bound
16
Proving Tight Bound
  • Can be difficult
  • f(n) ?(g(n))
  • iff f(n) O(g(n)) f(n) ?(g(n))

17
f(n) ?(g(n)) iff f(n) O(g(n)) f(n) ?(g(n))
  • Implies
  • if f(n)O(g(n)) and g(n)O(f(n)) then f(n)?(g(n))

18
f(n) ?(g(n)) iff f(n) O(g(n)) f(n) ?(g(n))
  • Proof
  • g(n) O(f(n)) implies that g(n) ? cf(n)
  • 1/c g(n) ? f(n)
  • let c 1/c
  • cg(n) ? f(n)
  • f(n) ? cg(n)
  • ?f(n) ?(g(n))
  • Since f(n) ?(g(n)) and g(n) O(f(n)), it
    follows that f(n) ?(g(n))

19
Useful Properties of Asymptotic Notation
  • if a is a constant, O(af(n)) O(f(n))
  • Ex O(32n3) O(n3)
  • if f(n) grows as fast as or faster than g(n)
    (remember the growth rate hierarchy), then O(f(n)
    g(n)) O(f(n))
  • Ex O(5n4 3n2) ?(n4)
  • O(f(n)) O(g(n)) O(f(n) g(n))
  • Ex ?(n) ?(log n) ?(n log n)
  • O(f(n)) O(g(n)) O(f(n) g(n))

20
Show 8n3 - 5n2 10 O(n3)
Write a Comment
User Comments (0)
About PowerShow.com