Chapter 3
Computing with Large Integers
3.1
Complexity Theory
When presenting an algorithm, we shall always use a high-level, and somewhat informal, notation.
However, all of our high-level descriptions can be routinely translated into the machine-language of
an actual computer. So that our theorems on the running-times of algorithms have a precise math-
ematical meaning, we formally define an “idealized” computer: the
Random Access Machine
or
RAM
.
A RAM consists of an unbounded sequence of
memory cells
m
[0]
, m
[1]
, m
[2]
, . . .
each of which can store an arbitrary integer, together with a
program
. A program consists of a
finite sequence of instructions
I
0
, I
1
, . . .
, where each instruction is of one of the following types:
arithmetic
This type of instruction is of the form
x
←
y
◦
z
, where
◦
represents one of the
operations addition, subtraction, multiplication, or integer division. The values
y
and
z
are
of the form
c
,
m
[
a
], or
m
[
m
[
a
]], and
x
is of the form
m
[
a
] or
m
[
m
[
a
]], where
c
is an integer
constant and
a
is a nonnegative integer constant. Execution of this type of instruction causes
the value
y
◦
z
to be evaluated and then stored in
x
.
branching
This type of instruction is of the form IF
y
∼
z
GOTO
i
, where
i
is the index of
an instruction, and where
∼
is one of the comparison operators =
,
6
=
, <, >,
≤
,
≥
, and
y
and
z
are as above.
Execution of this type of instruction causes the “flow of control” to pass
conditionally to instruction
I
i
.
halt
The HALT instruction halts the execution of the program.
A RAM executes by executing instruction
I
0
, and continues to execute instructions, following
branching instructions as appropriate, until a HALT instruction is executed.
We do not specify input or output instructions, and instead assume that the input and output
are to be found in memory at some prescribed location, in some prescribed format.
To determine the running-time of a program on a given input, we charge 1 unit of time to each
instruction executed.
This model of computation closely resembles a typical modern-day computer, except that we
have abstracted away many annoying details. However, there are two details of real machines that
10