Lecture 3--Models for sequential computation (RAM, pseudocode, Turing machine). 10/3/97

================================================================================

We assume that we are executing programs on a sequential computer, i.e., one which can only execute one machine instruction per time unit. So we start by assuming we have a computer consisting of a control unit, an ALU, random access memory, and some sort of I/O device. We assume the computer can execute any operation from a finite set of operations in one time unit. Next quarter, when we study algorithms for low level calculations like addition and division we will allow only a primitive set of operations, but for now we will be less restrictive. So our operation set might incluce, for example,

---read one piece of data

---write one piece of data

---read the contents of one memory cell

---store a value into one memory cell

---do one arithmetic or logical operation (add, subtract, multiply, divide, and, or, not,xor)

---do one arithmetic or logical comparison

---jump (uncoditionally or conditionally)

---call a function or procedure

etc.

We assume that the memory consists of an (unlimited) number of identical cells, each of which can hold one data item and each of which has an address.

This ideal machine will then be used to measure the theoretical behavior of the algorithms we will be looking at. It will be represented by the statements we write in pseudocode. This model has been called the "RAM" model (for random access machine). In a rigorous formal study of computation we would use the formal definition of a Turing machine, but the machine we have described here is essentially the same as a Turing machine and is much easier to work with.

Typically we will measure the number of steps an algorithm takes to run on our machine and the number of memory cells required. We will be interested in answering three questions for an algorithm:

1. what is its worst behavior (in terms of time and space used relative to the size of the problem).

2. what is its average behavior?

(3. what is the "best" it can do?)

Exercise 3.1. For your algorithm to find the maximum value stored in an unsorted array in section 2, what will be the worst, average, and best running time for an array of size N?

If we are planning to run an algorithm on an actual machine, there are many machine characteristics we must take into account. For example, what is the size of the random access memory, what is the size of the hard drive, how fast is the processor, what language/compiler will we be using, how many users are on the system at one time, .... The model described above tries to abstract out the most important aspects of such an actual situation to enable us to give a general description of the behavior of a given algorithm. For example, if our model tells us that an algorithm will run in a number of steps proportional to N, the number of elements in the input, then in practice we might find we need 20N time units and 100N memory cells or 2000N time units and 50N memory cells, but it will never take 20N2 memory cells. (In practice we are only concerned about specific values of N, and the maximum value of N will be known, so the constants may be more important than the exponent on N, but as N gets larger and larger, the exponent would become more important).