Geology Reference
In-Depth Information
Fig. A2.1
Control flow programming structures. From
left
to
right
: Conditional branch, pre-conditional loop,
post-conditional loop, and infinite iteration.
ExprL
is a
logical expression, which can assume the values
true
(
T
)
or
false
(
F
).
Block
is a sequence of instructions
at step #6 is a
conditional branch
. It is executed
comparing the value of
x
with 10. If
x
is less
than or equal to 10, then the next instruction that
will be executed is that at line #20, otherwise
it will be executed the instruction at line #7. In
absence of control flow instructions, the sequence
of instructions that are executed by the process-
ing unit is governed by the progression of line
numbers. However, jump instructions determine
a modification of the natural sequence of steps.
This feature can be considered as the most funda-
mental source of algorithms' power. For example,
backward jumps allow to execute more and more
times a block of instructions, providing the basis
for the construction of
cycles
(or
iterations
). Con-
sider the following code segment:
the execution is stopped and the algorithm returns
the actual value of
p
, else execution proceeds
with step #2. Steps #2 and #3 form the core
block of the algorithm instructions. They calcu-
late
x
n
D
xx
k
1
;
k
D
1, 2, :::,
n
. Finally, step #4 is a backward
jump that forces the program to restart at line
#1. We say that the sequence of steps 1-4 repre-
sents a cycle or iteration. There are three kinds
of cycles in computer programming, which are
illustrated in Fig.
A2.1
. They can be implemented
using backward or forward conditional branches
or unconditioned jump statements.
The third class of algorithm instructions is rep-
resented by
input/output
directives, which allow
to display results of computation, create graphics,
or enter input data and parameters. These instruc-
tions are specific of the programming language
used to implement the algorithms and ultimately
depend from the operating system.
by the recurrence formula:
x
k
Algorithm A2.1
pow
(
x
,
n
):
n
-th power of a real
number
x
.
Input
x
2<
;
n
2
N
; Output:
p
D
x
n
2<
f
0:
p
1;
k
0
1:
k
D
n
)
stop
2:
p
p
x
3:
k
k
C
1
4: jump #1
g
A2.2 Data Structures
Let
D
Df
x
1
,
x
2
, :::,
x
n
g
be a set of
n
data stored
in memory variables. It is assumed that the in-
dex
i
D
1,2, :::,
n
associated with the individual
data reflects the order of insertion into the main
memory, not a logical relation between them. The
set could be formed by homogeneous data, for
example a collection of integers, or by heteroge-
neous data, for example compound data records
At step #0, the algorithm initializes a
counter
k
and the return variable
p
. Line #1 contains a
conditional branch: if
k
has attained the value
n
,