II. Notes on Data Structuring * - Cornell University
II. Notes on Data Structuring * - Cornell University
II. Notes on Data Structuring * - Cornell University
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
130 c.A.R. HOARE<br />
end<br />
end primefinder<br />
begin next. w" -- next. w + 1 ;<br />
if next. w > W then exit primefinder<br />
end;<br />
next. b: = min (sieve [next. w]);<br />
primes [next. w]: v {next. b );<br />
,<br />
n" = next,<br />
while n. w ~< W do<br />
begin sieve [n. w]: - {n. b );<br />
end<br />
n.b: = n.b + next.b;<br />
n.w: = n.w + next.w;<br />
if n.b >~ wordlength then<br />
beginn.w'= n.w +l;<br />
n. b: = n. b - wordlength<br />
end<br />
One feature of this program is that it uses an envir<strong>on</strong>ment enquiry word-<br />
length to achieve the full efficiency of which a machine is capable, and yet<br />
does so in a completely machine-independent fashi<strong>on</strong>. The program will not<br />
<strong>on</strong>ly work, but work with high efficiency, <strong>on</strong> machines with widely varying<br />
word lengths.<br />
But the most interesting feature about the program is the way in which<br />
it is related to the previous versi<strong>on</strong>. From an abstract point of view it<br />
expresses an identical algorithm; all that has changed is the manner in which<br />
the data has been represented <strong>on</strong> the computer. The original design acted as<br />
a framework or pattern, <strong>on</strong> which the more intricate coding of the sec<strong>on</strong>d<br />
versi<strong>on</strong> was structured. By carrying out the design in two stages, we simplify<br />
the task of ensuring that each part of the finalprogram works successfully<br />
in c<strong>on</strong>juncti<strong>on</strong> with the other parts.<br />
Exercise<br />
Rewrite the program using sets representing <strong>on</strong>ly the odd numbers. (Hint:<br />
rewrite the more abstract program first.)<br />
8. THE SEQUENCE<br />
The previous chapters have dealt with the topic of elementary data structures,<br />
which are of great importance in practical programming, and present very