Lab 00
Lab 00
Algorithm SelectionSort(A[0..n-1])
//The algorithm sorts a given array by selection sort
//Input: An array A[0..n-1] of orderable elements
//Output: Array A[0..n-1] sorted in ascending order
for i 0 to n – 2 do
min i
for j i + 1 to n – 1 do
if A[j] < A[min]
min j
swap A[i] and A[min]
return A
Example:
IV. Exercises
For each problem, do the following:
a) Use Python to present the algorithm.
b) Determine the time efficiency of the algorithm [in the worst case] (as a function of input size).
1. Design and analyze a non-recursive algorithm to find the sum of the following series.
2. Design and analyze a non-recursive algorithm to find the sum of the following series.
( )
3. Design and analyze a non-recursive algorithm to find the sum of the following series.
4. Design and analyze a non-recursive algorithm to find the factorial of a positive integer n,
denoted by n!
5. Design and analyze a non-recursive algorithm to check whether all elements in an array are
distinct.
6. Design and analyze a non-recursive algorithm to find the maximum element in an array,
supposing that all elements in the array are unique.
7. Design and analyze an algorithm for multiplying ( ) two matrices
8. Design and analyze an algorithm for multiplying ( ) a matrix with a number
9. Design and analyze an algorithm for subtracting ( ) two matrices
10. Design and analyze an algorithm for adding ( ) two matrices