Algorithms and Data Structures
Algorithms and Data Structures
Algorithms and Data Structures
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
N.Wirth. <strong>Algorithms</strong> <strong>and</strong> <strong>Data</strong> <strong>Structures</strong>. Oberon version 127<br />
3.3. Deduce the recursion scheme of Fig. 3.10 which is a superposition of the four curves W 1 , W 2 , W 3 ,<br />
W 4 . The structure is similar to that of the Sierpinski curves in Fig. 3.6. From the recursion pattern, derive a<br />
recursive program that draws these curves.<br />
Fig. 3.10. Curves W 1 – W 4 .<br />
3.4. Only 12 of the 92 solutions computed by the Eight Queens algorithm are essentially different. The<br />
other ones can be derived by reflections about axes or the center point. Devise a program that determines<br />
the 12 principal solutions. Note that, for example, the search in column 1 may be restricted to positions 1-<br />
4.<br />
3.5. Change the Stable Marriage program so that it determines the optimal solution (male or female). It<br />
therefore becomes a branch <strong>and</strong> bound program of the type represented by the program Selection.<br />
3.6. A certain railway company serves n stations S 0 , ... , S n-1 . It intends to improve its customer<br />
information service by computerized information terminals. A customer types in his departure station SA<br />
<strong>and</strong> his destination SD, <strong>and</strong> he is supposed to be (immediately) given the schedule of the train connections<br />
with minimum total time of the journey. Devise a program to compute the desired information. Assume that<br />
the timetable (which is your data bank) is provided in a suitable data structure containing departure (=<br />
arrival) times of all available trains. Naturally, not all stations are connected by direct lines (see also<br />
Exercise 1.6).<br />
3.7. The Ackermann Function A is defined for all non-negative integer arguments m<strong>and</strong> n as follows:<br />
A(0, n) = n + 1<br />
A(m, 0) = A(m-1, 1) (m > 0)<br />
A(m, n) = A(m-1, A(m, n-1)) (m, n > 0)<br />
Design a program that computes A(m,n) without the use of recursion. As a guideline, use the procedure<br />
NonRecursiveQuickSort from sec. 2.3.3. Devise a set of rules for the transformation of recursive into<br />
iterative programs in general.<br />
References<br />
[3.1] D.G. McVitie <strong>and</strong> L.B. Wilson. The Stable Marriage Problem. Comm. ACM, 14, No. 7 (1971),