The Big-O notation

THE BIG-O NOTATION
BIG O NOTATION IS USED IN COMPUTER SCIENCE TO
DESCRIBE THE PERFORMANCE OR COMPLEXITY OF AN
ALGORITHM. BIG O SPECIFICALLY DESCRIBES THE
WORST-CASE SCENARIO, AND CAN BE USED TO
DESCRIBE THE EXECUTION TIME REQUIRED OR THE SPACE
USED (E.G. IN MEMORY OR ON DISK) BY AN
ALGORITHM.
IS WRITTEN O(X) WHERE X IS THE WORST CASE
COMPLEXITY OF THE ALGORITHM.
7n3+n2+4n+1
We keep only the term that has the most effect
Constant
Linear
Polynomial
Exponential
logarithmic
THERE ARE FIVE DIFFERENT TYPES OF
COMPLEXITY
Algorithms
that show a constant complexity
take the same time to run regardless of the
size of a data set. Example pushing or
popping an item off stack. No matter how big
the stack the time to push or pop remains
constant.
CONSTANT COMPLEXITY O(1)
Algorithms
with linear complexity increase at
the same rate as the input size increases. If the
input size doubles, the time taken for the
algorithm to complete doubles. An example of
this is the average time to find an element
using linear search.
LINEAR COMPLEXITY O(N)
Is
that where the time taken as the size increases can
be expressed as n power of k is a constant value. As n
power of 0 = 1 and n power of 1 = n. Constant and
linear complexities
are
also
polynomial
complexities.
2
3
Quadratic O(n ) and cubic O(n ).
k
POLYNOMIAL COMPLEXITY O(N )
WHERE K >=0
Algorithms
with exponential complexity do not
scale well at all. Exponential complexity means
that as the input n gets larger the time taken
increases at rate of k power of n where k is a
constant value.
Same
as polynomial but faster
n
EXPONENTIAL COMPLEXITY O(K )
WHERE K>1
The
rate at which their execution time
increases, decreases as the data set increase.
Meaning the execution time between n=100
and n=150 will be less than the difference in
execution time between n=50 and n=100.
Example binary search because the check
increase by one when data set as double
LOGARITHMIC COMPLEXITY O(LOG N)
N
N power 2 (polynomial)
2 power of n (exponential)
1
1
2
10
100
1024
20
400
1048756
30
900
1073741824
Consider
n=100 an algorithm with quadratic
growth (n power of 2) would take 10 000 steps.
An algorithm with exponential growth of 2
power of n would take around 1.3 X 10 power
30 steps. A computer perfuming a 10billion
steps per second since the beginning of time
would still be less than one per cent of the
way through solving the problem.
INTRACTABLE: WHEN A PROBLEM BECOME
QUICKLY UNSOLVABLE AS AMOUNT OF TIME
NP
(stands for Non-Determinsitic Polynomial
time) means if your given a solution to that
problem you can check the solution is
correct in P polynomial. The debate that all
NP problems are actually P problems. If you
prove otherwise you could win the prize
$1000 000 PRIZE AVAILABLE IF YOU
Logarithmic
Dijkstra's algorithm is an algorithm for finding
the shortest paths between nodes in a graph, which
may represent, for example, road networks.
 Mark
the start node as a distance of 0 from itself and all other
nodes as an infinite distance from the start node.
 While
the destination node is unvested go to the closest
unvisited node to A (Call it A)
 FOR
every unvisited node connected to the current node:
calculate the distance to the current plus the distance of the
edge to unvisited
If this distance is less than the currently recorded shortest
distance, make it the new shortest distance
Next connected node
Mark the current node as visited
Node
Shortest distance from A
Previous node
A(V)
0
B(V)
~50
A
C(V)
~25
A
D(V)
~75
B
E(V)
~70
C
F(V)
~75
C
G(V)
~100
E
H(V)
~105 100
EF
I(V)
~130
B
J(C)
~ 180 160
GI
Alternative
algorithms to find the shortest path. It
preforms better than Dijkstra’s algorithm because
of its use of heuristics (heuristic, is any approach
to problem solving, learning, or discovery that
employs a practical method not guaranteed to
be optimal or perfect, but sufficient for the
immediate goals).
A * SEARCH
 Begin
at the start node and make this the current node. WHILE the
destination node is unvisited FOR each open node directly
connected to the current node
Add o the list of open nodes
Ass the distance from the start (g) to the heuristic estimate of
distance left (h)
Assign this value (f) to the node
NEXT connected node
Make the unvisited node with the lowest value the current node
ENDWHILE
ALGORITHMS
THE FIFTEEN PUZZLE
79