Intro. To Sorting Algorithms

advertisement
Intro. To Sorting Algorithms
Understanding Algorithmic complexity
What is algorithmic complexity? In computer science, we express how
fast a program runs in a quantitative manner. Essentially, we are
interested in how efficient a program is.
We express this complexity in terms of O(n)  (Big O of N).
In mathematics, O(big O), Ω(Omega), Θ(Theta) are asymptotic bounds.
They describe how a graph/function will behave over time.
When we write an algorithm, we are interested in how fast that
algorithm will run on an average case (Theta), best case (Omega) or
worst case(big O) scenario.
For example, when we run linear search, Ω(n) = 1 because it could be
that we find our first element in the first try.
The Θ(n) is n/2 in linear search because we would expect that to be the
average.
The O(n) is n in linear search because at the worst case, we would have
to search through the entire list before we found our results.
Usually in computer science, we are strictly concerned with the worst
case scenario, or Big O notation.
Big O notation is independent of machine and programming language
used. You don’t gain anything in algorithmic complexity for using
another language or superior hardware.
Big O is a quantitative way of expressing runtime efficiency in terms of
n, where n is the size of the set that we are acting on.
Complexity Order:
Constant
O(1)
Logarithmic
O(log(n))
Polynomial time
Linear
O(n)
Quadratic
O(𝑛2 ) or n raised to any constant
_________________________________________________________________________________
Factorial
O(n!)
Bad Algorithms (takes too long)
Exponential
O(2ᴺ) or O(nᴺ)
Complexity order
If the best algorithm we have for a problem runs in factorial or
exponential time, we say we don’t have a good solution for this
problem.
A good algorithm runs in polynomial time.
Example: RSA keys
Cracking RSA keys? RSA is the world’s premiere public key crypto. All
internet certificates use RSA for authentication. VPN’s and other encrypted
network use RSA keys to send messages back and forth.
RSA uses 1024 bit keys for encryption.
How big is 2^1024? To try to break this number with a brute force tactic, a
cluster of supercomputers would take about 30 years. That’s how big that
number is.
The algorithm needed to break an RSA key runs in exponential time. It’s a
bad algorithm. There is no known good algorithm to crack RSA keys.
Download