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.
end<br />
NOTES ON DATA STRUCTURING 129<br />
n.w: = n.w + next.w;<br />
if n. b >i wordlength then begin n. w: -- n. w + 1 ;<br />
end<br />
n. b: = n. b - wordlength<br />
Since this appears acceptably efficient we will code the other operati<strong>on</strong>s of<br />
the outer loop, starting with the most dimcult"<br />
next" = rain (sieve);<br />
Here we do not wish to start our search for the minimum at the beginning<br />
of the sieve set each time, since towards the end of the process this would<br />
involve scanning many empty words. We therefore take advantage of the<br />
fact that the new value of next must be larger than the old value.<br />
The search c<strong>on</strong>sists of two parts, first finding a n<strong>on</strong>empty word, and then<br />
its first bit. But if the search for a word reaches the end of the array, the<br />
whole program is completed<br />
while sieve [next. w] = { } do {next. w: = next. w + 1 ;<br />
if next. w > W then exit primefinder };<br />
next. b: = min (sieve [next. w]);<br />
The remaining operati<strong>on</strong>s are trivial Since the outer loop is terminated<br />
by an exit, there is no need to test a separate while c<strong>on</strong>diti<strong>on</strong>; and the<br />
statement<br />
primes" v {next };<br />
can be coded as<br />
primes [next. w]: v {next. b }.<br />
The whole program including initialisati<strong>on</strong> is as follows"<br />
primes, sieve:array 0.. W of powerset 0.. wordlength - 1 ;<br />
begin primefinder;<br />
n, next:(w, b:integer);<br />
for t:O.. W do begin primes [t]: = ( };<br />
end;<br />
sieve [0]: - (0, 1 };<br />
next. w: = O;<br />
while true do<br />
sieve [t]: = range (0.. wordlength - 1<br />
begin while sieve [next. w] = ( ) do