Information Technology Reference
In-Depth Information
ₐ
≤
≤
3. (Summation.)
sum
0. For each
j
, where 1
j
n
,
ₐ
(a)
c
1; the variable
c
is a temporary accumulator.
(b) For each
k
, where 1
≤
k
≤
m
,set
c
ₐ
c
×
A
jk
.
(c)
sum
ₐ
sum
+
c
.
This is cumbersome and no more informative than the equivalent mathematical
expression. It is safe to assume that most programmers know how to use loops
to implement sums and products.
ₐ
j
=
1
k
=
1
A
jk
.
Written this way, it is unclear that a separate variable
sum
is even required: the
mathematical expression may suffice in future references to the same value. Giving
this step explicitly, however, might help if, say, the matrix
A
was sparse and stored
as a list rather than as a two-dimensional array, thus requiring an explanation of how
to compute the summation efficiently.
In specifications of algorithms, use text rather than mathematics if the former is
sufficiently clear.
2. for 1
3. (Summation.) Set
sum
≤
i
≤|
s
|
(a) set
c
ₐ
s
[
i
]
(b) set
A
c
ₐ
A
c
+
1
2. For each character
c
in string
s
, increment
A
c
.
Figures
Figures are an effective way of conveying the intricacies of data structures; and
even quite simple structures can require complex descriptions. General guidelines
A single rotation can be used to bring a node one level closer to the root. In a
left-rotation, a parent node
x
and its right child
y
are exchanged as follows:
as
B
is the left child of
y
, assign
B
to be the new right child of
x
and assign
x
to be the new left child of
y
. The left child of
x
and the right child of
y
remain unchanged. The complementary operation is a right-rotation. Left- and
right-rotations are shown in the following diagram.
y
x
right rotate
x
y
A
C
left rotate
A
B
B
C