Definition
Definition
1. What is an algorithm?
Algorithm is a design of computer program.
2. Algorithms and their complexity problem size(n).
The measure of the quantity of input data.
3. Time complexity and asymptotic time complexity
1. The time needed by an algorithm expressed as a function of the size of a problem is
called the time complexity of the algorithm.
2. The limiting behavior of the complexity as size increases is called the asymptotic time
complexity.
4. Space complexity and asymptotic space complexity
1. The space needed by an algorithm expressed as a function of the size of a problem is
called the space complexity of the algorithm.
2. The limiting behavior of the complexity as size increases is called the asymptotic time
complexity.
l(i) ={ [log(i)]+1,
i!=0
{1 i=0
-Uniform cost criteria each RAM instruction requires one unit of time
n-1 MUL T instructions and each register requires one unit of space.
-A second, sometimes more realistic definition takes into account
limited size of a real memory word and is called the logarithmic criteria.
O(n)
Proof: to simulate a RAM program P by a RASP program, the memory register of the rasp are
used as follow:
temporarily stores the contents of the accumulator in register 1
Theorem 1.2. If costs of instructions are either uniform or logarithmic. for every RASP
program of time complexity T(n) there is a constant k such that there is an equivalent RAM
program of time complexity at most kT(n). Proof: The RAM program we shall construct to
simulate the RASP will use indirect addressing to decode and simulate RASP instructions
stored in the memory of the RAM. Certain registers of the RAM will have special purposes:
register I - used for indirect addressing,
register 2-the RASP's location counter,
register 3 - storage for the RAS P's accumulator.
Register i of the RASP will be stored in register i + 3 of the RAM for i >=1 .
The RAM begins with the finite-length RASP-program loaded in its memory starting at register
4. The RAM program consists of a simulation loop which begins by reading an instruction of
the RASP (with a LOAD *2 RAM instruction). decoding it and branching to one of 18 sets of
instructions. The decoding and branching operations are straightforward: