Algorithms
Algorithms
Big O Notation:
Big O is a characterization of algorithms accorfing to their worst-case
growth rates.
They are written "0(Formula)"
Formula above describes how an algorithm's run time or space requirements gor
as the input size grows:
0(1) - constant
0(n) - linear
0(n^2) - squared
0(2^n) - exponential
0(n!) - factorial
Sorting:
Quick sort is an efficient, widely used divide-and-conquer algorithm.
It divides by selecting a pivot (ideally one that will end up toward the
center of the sorted pack)
moves everything into either the less than or greater than side of
pivot
when the pivot is in its final position it recursively calls it self on
either side of the pivot.
While some quick sorts will perform at O(n*log(n)) speeds, if the list is
already sorted it will slow down to O(n^2).
This can be solved by randomizing the list before running the sort.
Another aproachg is to use the median of beginning, middle, and end of
each partition, as the pivot.
Quick sort is very fast and low in resource overhead, but is unstable,
recursive, and will perform poorly with a poorly selected pivot.
Algorithms can be sorted into two categories: Polynomial time and exponential time.
An algorithm grows in polynomial time if its runtime does not grow faster
than n^k where k is any constant.
ex) O(n^2), O(n^3), O(n*log(n))
Exponential time algorithms are generally too slow to be useful (except in
cryptography et c. )
P: This is the set of decision problems (problems with yes/no answers) that can
be solved quickly (in polynomial time) by a deterministic machine.
NP: This refers to decision problems where, given a "yes" answer, that solution
can be verified quickly (again, in polynomial time), even if finding the solution
isn't necessarily fast.
NP-hard: These problems are at least as hard as the hardest problems in NP.
Interestingly, solving an NP-hard problem quickly means you could quickly solve all
NP problems, but they aren't necessarily verifiable quickly.
NP-complete: These are the problems that are both in NP and as hard as any
problem in NP. An efficient solution for one NP-complete problem would solve all NP
problems efficiently.