
Chapter 9
Complexity Issues
9.1 Algorithms and Complexity
By an algorithm, we usually mean a sequence of instructions carried out in
order to solve some computational problem. The steps of an algorithm need
to be clearly defined, so that they can be implemented and executed on a
computer.
Example 9.1 Given an integer number a and a positive integer n, a
n
can be
computed using the following simple algorithm.
Algorithm 9.1 A naive algorithm for computing the n
th
powerofaninteger.
1: Input: a, n
2: Output: a
n
3: answer = 1
4: for i =1,...,n do
5: answer=answer×a
6: end for
7: return answer
Algorithms are usually compared by their performance. The most popular
performance ...