(the final arrangement is of course ``aegpru'')
1. Using each of the following methods, write down (step by step)
the position of each letter in the string ``prague'' when sorted
using
2. Write down the pseudocode for an algorithm which determines
if four given lengths can form
a rectangle.
3.
90 candidates take an exam. Each exam is marked between 0 and 100 (i.e. as
a percentage). Write
an algorithm to determine the number of marks obtained in the
ranges 0 to 40, 41 to 55, 56 to 70, 71 to 100.
4.
The Towers of Hanoï problem comes originally from a legend
associated with the Temple of Brahma, in which the problem had to
be solved with 64 gold discs on a diamond tower
(see
http://geminga.it.nuigalway.ie/~gettrick/courses/CT102/hanoi.html). Supposing
that these discs could be moved by the priests of the Temple at the
(reasonably fast) speed of 1 every second
5.
A perfect square is a number that is the square of another
Natural number, e.g. 1 (= 1x1), 4 (= 2x2), 9 (= 3x3), etc.
Write an algorithm that takes as input a positive number n
and calculates as output
the number of different perfect squares less than
or equal to n [e.g. if n were 18, the program should count
4 perfect squares: 1, 4, 9, 16].
6. A prime number is one which can only
be divided by itself
and 1. For example, 7 is prime but 9 is not (it can be divided by
3). Develop an algorithm to find (and output) all prime numbers up to a given
(input) number n . Write the algorithm in pseudocode, with
comments to explain its progress.
7. It turns out that n is
prime if it cannot be divided by any
of the numbers from 2 up to n/2. Based on this fact, write an
improved version of the algorithm in question 6.
8. The matrix (table) below
gives distances between five cities (numbered 1 to 5, corresponding to
the rows and columns of the matrix).
0
79
205
107
115
79
0
158
97
77
205
158
0
137
105
107
97
137
0
175
115
77
105
175
0
In each case state (by observation)
whether the solution is optimum.
9.
For each of the following graphs,
10. The Fibonacci sequence
is a sequence in which each number is the addition of the previous two
numbers and the first two numbers in the sequence are both 1:
(So for example the 7th Fibonacci number (13) is the sum of the 6th and
5th (8+5)). Write an algorithm to calculate the nth
fibonacci number using