SUNY Geneseo Department of Computer Science
Asymptotic
Notation
{Date}
CSci 141, Spring 2005
Prof. Doug Baldwin
Return
to List of Lectures
Previous Lecture
Misc
Hand out Lab 7
First hour exam is this Friday (Mar. 4)
- Object oriented algorithms, recursion,
induction, recurrences, asymptotic
notation
- 3 - 5 short answer questions
- Will put practice test on Web
- Open book, notes, computer
- Closed person
- Whole class period
Questions?
Asymptotic Notation
Section 9.2
Some differences betweenn algorithms matter
more than others
Fastest-growing term is most important -- e.g.,
n2 vs n vs constant
Asymptotic notation indicates rough
proportionality
Initialization and ranking algorithms?
- Initialization: set all elements of arrray to
some fixed value
for each index into A
A[index] = value
- Ranking: identify each element in array by
order, 1st, 2nd, 3rd
for each index i in A
countOfSmallerElements = 0
for each index s in A
if A[s] <= A[i]
countOfSmallerElements = countOfSmallerElements + 1
What about looking for values and proving
asymptotic equivalence?
- Example: n2 + 3n = Θ(n2)
- Formally n2 + 3n = Θ(n2) iff
- c1 n2 <= n2 + 3n <= c2 n2
- (when n>=n1, n>=n2 respectively)
- Start with c1, c1 = 1
- n2 <= n2 + 3n, as long as n >= 0
- i.e., n1 = 0
- How about c2?
- c2 = 2?
- Is n2+3n <= 2 n2 for big enough n?
- Solve n2+3n <= 2 n2
- n + 3 <= 2 n (divide by n)
- 3 <= n
- i.e., n2 = 3
- But we could have picked c2 = 17
- n2 + 3n <= 17 n2
- n + 3 <= 17 n
- 3 <= 16 n
- 3 / 16 <= n
Next
Data structure and lists
Read Sections 11.1 and 11.2
Next Lecture