Professional Documents
Culture Documents
Plexity Algorithms
Plexity Algorithms
Plexity Algorithms
Algorithms
CS/MA 109
Wayne Snyder
Fall, 2017
Today:
Computer Science
Review: Functions and Graphs
Computer Science
f(x) = x2
f(x) = x3 f(x) = x2
y = f(x) = a*x + b
The simplest such function is just
f(x) = x
Complexity of Algorithms
Computer Science
y = f(x) = a*x + b
Note: this is the equation of a line, well simplify
a bit and assume that a = 1 and b = 0:
f(x) = x
y = f(x) = a*x + b
Note: this is the equation of a line, well simplify Brief Digression: To be a computer
a bit and assume that a = 1 and b = 0:
scientist, you have to be a real pessimist!
f(x) = x You always want to know what is the
absolutely worst thing that can happen?
The worst thing in looking for your paper is
Example of Linear Time Algorithm: that it is in the last place you look. No
matter how to look at the pile, it MAY be
Finding your homework paper in an the last one you look at.
unordered pile of homeworks.
x = how many papers in pile
f(x) = how many papers you have
to look at in worst case.
Complexity of Algorithms
Computer Science
Logarithmic Algorithms
Another class of algorithms have a
complexity function which is a f(x) = x
logarithm of x
f(x) = log2(x)
This is the complexity of Algorithm 2:
Binary Search, e.g., searching for a
word in a dictionary, or for a number
in an ordered list:
f(x) = log2(x)
Complexity of Algorithms
Computer Science
Logarithmic Algorithms
Another class of algorithms have a Zoom Out:
complexity function which is a
f(x) = x
logarithm of x
f(x) = log2(x)
This is the complexity of Algorithm 2:
Binary Search, e.g., searching for a
word in a dictionary, or for a number
in an ordered list:
f(x) = log2(x)
Complexity of Algorithms
Computer Science
Logarithmic Algorithms
Another class of algorithms have a
Zoom Out:
complexity function which is a
f(x) = x
logarithm of x
f(x) = log2(x)
This is the complexity of Algorithm 2:
Binary Search, e.g., searching for a
word in a dictionary, or for a number
in an ordered list:
f(x) = log2(x)
Complexity of Algorithms
Computer Science
f(x) = 2x
Exponential Algorithms
f(x) = * x2 - *x f(x) = x
These have a complexity function
which is NOT a polynomial, because
it has X in the exponent.
Example:
f(x) = 2x f(x) = Xx
f(x) = log2(x)
Complexity of Algorithms
Computer Science
f(x) = 2x
f(x) = x2 f(x) = x2
f(x) = log2(x)
Exponential Problem: Partition Problem
Computer Science
Complexity: f(x) = 2x
Exponential Problem: Guessing Passwords
Computer Science
How many passwords would you have to try in the worst case?
..
Complexity: f(x) = 2x
Exponential Problem: Traveling Salesman
Computer Science
Total Length = 97
Complexity of Algorithms
Computer Science
f(x) = xx
which grows very fast!!
Example: Exponential Growth of Algorithms
Computer Science
f(x) = x
Example: Exponential Growth of Algorithms
Computer Science
f(x) = x2
Example: Exponential Growth of Algorithms
Computer Science
f(x) = xx
Example: Exponential Growth of Algorithms
Computer Science