Algorithmic Complexity and Probability Flashcards
What is the trade off when deciding which option for a program is the most efficient?
Time and space efficiency:
How to evaluate efficiency of programs?
- measure with a timer
- count the operations
- abstract notion of order of growth (most appropriate way)
How can you time a program?
Use a time module:
import time t0 = time.clock (start)
call function
t1 = time.clock() - t0
What are the drawbacks of timimng programs?
Timing is inconsistent:
timer varies for different inputs but cannot really express a relationship between inputs and timer
What are the positive aspects and drawbacks of counting operations?
good:
count depends on algorithm
count is independent of the computer
bad:
count depends on the implementation
no clear definition of which operation to use
Overall: count varies for different inputs and can come up with a relationship between inputs and counts
What are the problems about timing and counting as evaluation implementations?
What oyu really want to do is evaluate the algorithm, scalability and the input isze
Does the input influence how the function runs?
Yes, i.e. a function that searches for an element in a list:
1. when e is the first element in the lest –> best case
when e is not in the list –> worst case
want to measure this in a general way
(look through half for the average case)
What measure do we use to measure the order of growthß
Big OH notation
What does the big o notation measure?
The upper bound of the asymptotic growth, often called order of growth
–> big o is used to descrive worst case as it is the bottleneck when a program runs
this evaluates the algorithm and not the machine or implementation
What does O(N) measure?
–> how the time needed grows with the input growth
What types of orders of growth do we know?
Constant linear quadratic logarithmic n log n exponential
What is the law of addition for o()?
O(f(n)) + O(g(n)) = O(f(n) + g(n))
What is the law of multiplication for O()?
O8f(n)) * O(g(n)) = O(f(n) * g(n))
What complexity classes do we know and what do they mean?
O(1) –> constant running time
O(log n) –> logarithmic running time
O(n) –> denotes linear running time
O(n log n) –> denotes log-linear running time
O(nC) –> polynominial runnung rime (c constant)
O(cN) –> exponential running time (c is a constant being raised to power based on soze if input)
What are examples of constant complexity?
- -> Complexity independent of input
examples: finding length of a list in python