4.4. Classification of Algorithms - Advanced
4.4. Classification of Algorithms - Advanced
www.pmt.education
Specification:
www.pmt.education
4.4.4.3 Order of complexity
Be familiar with Big-O notation to express time complexity and be
able to apply it to cases where the running time requirements of the
algorithm grow in:
• constant time
• logarithmic time
• linear time
• polynomial time
• exponential time.
Be able to derive the time complexity of an algorithm
www.pmt.education
Comparing Algorithms
The complexity of each algorithm can be shown through a
function relative to the size of the task. An algorithm can be
complex in two ways - in terms of space and in terms of
time. An ideal algorithm will run quickly and take up little
space as possible. Often, a programmer will have to create
a compromise solution, relative to the situation.
www.pmt.education
As you can see from above, the different types of graphs have different rates of
increase. Apart from the constant function, they all grow as the input increases.These
functions can be used to represent the complexities of different algorithms. There are
two other functions you have to be aware of - y = xlog(x) and y = x!. ! stands for
factorial. The factorial of a number is all the positive integer values either smaller or
equal to that value multiplied, e.g. 4! = 1 x 2 x 3 x 4 = 24. Factorials are useful for
working out permutations, e.g. how many ways are there to order the alphabet - there
are 26 letters in the alphabet, so there are 26! different ways of ordering the alphabet
(or approx 400,000,000,000,000,000,000,000,000)
Big O Notation
The complexity of an algorithm can be described by big O notation. Big O always
assumes a worst case scenario. In big O is is customary to describe the input in terms
of n rather than x. If we wanted to specify the complexity of an algorithm with a linear
time complexity, we would say the time complexity is O(n). If an algorithm has a
complexity of n3 + 200n2 + 1000n + 25, its big O is simply O(n3) as n3 is the largest
polynomial - when n is very large, the other parts of the equation are dwarfed by n3.
www.pmt.education
Function Big O How to recognise Example
Limits of computation
There exists two types of algorithms - tractable and
intractable. A tractable problem can be solved within a
useful period of time. Tractable problems have a
polynomial or less time solution. Intractable problems are
theoretically solvable (i.e. there exists a corresponding
algorithm) but are classified as ‘insoluble’ due to limits of
computations - due to the speed of today’s technology, it
may take millions of years to solve. Intractable problems
do not have a polynomial (or less) time solution. They
www.pmt.education
cannot be solved within a useful period of time. For these types of problems, we may
use a heuristic method. These are approximate solutions to a problem; they are not
optimal, but are more useful than their intractable equivalent.
However, not every problem can be solved algorithmically, e.g. the Halting problem.
The halting problem: it is impossible to write an algorithm to determine if another
algorithm will finish with a given input. The halting problem demonstrates that there are
some problems which cannot be solved by computers.
www.pmt.education