As we saw in the quiz, there are three things that our basic machine model needs to have.
One is the memory, the second one is some sort of input/output capabilities,
and finally, we need to have certain programming capabilities.
There's a lot of different models that have these capabilities, but in this course,
we're going to use a model called the RAM, and RAM stands for Random Access Machine.
So, there are many different ways of defining a Random Access Machine, and we'll use a model
similar to the one defined by Steven Skiena and his book, The Algorithm Design Manual.
The first thing that the RAM has is the memory
and that memory can of course be used for input, for output, and for holding the program
that the RAM is running on, but as simplification,
we're going to split the memory into three parts.
We're just going to use this memory here for intermediate results and output,
and we're going to have a separate memory for the input and a separate memory to hold the program.
And, these two memories here on the left side are read only meaning that the RAM cannot modify
the input, it can only read the input, and the RAM can also not modify the program.
It could only read the program, and usually, when we will talk about the memory requirements
of an algorithm, what we will be talking about is how much of this memory here the RAM is using.
Generally, there is no limit of how much of this memory here we have
so we always have as much as we want, but the memory is divided into single cells,
and each of these cells has a limited capacity so each of these cells
cannot have arbitrarily large values, but there are as many cells as the algorithm needs.
Now, if we're running a program on the RAM, what we're mainly interested in is
the time that this program is going to run for a given input,
and there are basically three rules for how long the RAM requires to execute a program.
Simple operations such as adding two numbers, multiplying them, or executing an if or for.
Those all take one time step.
If you have a loop in your program such as a four-loop, this will count
not as a simple operation but count as often as it runs.
So, if you have a loop that executes a simple operation 100 times,
that will count as 100 time steps, and finally, you' ll also get something for free accessing memory.
So, reading a part of the input or writing something into a memory cell here, that is free.
That means that actually takes zero time steps.
And these three rules give us a simple way of determining the running time of an algorithm
or program or also of comparing the running time of two programs because all we need to do
is count the number of time steps that we expect the RAM to execute for a given input.
Let's practice this for a little bit.
