Abasyn University Peshawar
Department of Computing
Course: CS617-Advanced Design & Analysis of Algorithm Teacher: Rashid Kamal
Assignment No. 1
Write algorithms for each of the exercises below.
1. Write an algorithm that finds the largest number in a list of n numbers.
2. Write an algorithm that finds the m smallest numbers in a list of n numbers.
3. Write an algorithm that prints out all the subsets of three elements of a set of n elements.
The elements of this set are stored in a list that is the input to the algorithm.
4. Write an algorithm that finds the greatest common divisor of two integers.
5. Write an algorithm that finds both the smallest and largest numbers in a list of n numbers.
6. Write an algorithm that takes an array of positive integers (it stops reading when it sees a
negative number), and the size of the array, and prints the average (type float) of the
values.
7. Given 2 arrays A and B, each of size n. Design an algorithm to test whether there is at
least one common element between the 2 arrays.
8. Read in any three characters (a-z) and print them in alphabetical order.
9. Write an algorithm that takes three integers and returns the smallest integer that is a
multiple of all three integers.
10. A perfect number is a positive integer greater than 1 that equals the sum of its divisors,
including 1 but not itself. For example, 6 is a perfect number because its divisors are 1, 2,
and 3 and 1 + 2 + 3 = 6. Write an algorithm that determines for a given integer whether it
is perfect or not.