C Programming Starter Assignment
C Programming Starter Assignment
Assignment 1
(For all the questions, submit the program as *.c file and prepare a separate text file with
pseudocode and explanations)
Algorithm A:
The algorithm maintains a partially sorted array. More precisely, at the start of the ith
iteration, the algorithm has the elements a[1] to a[i] in sorted order. In the ith iteration,
a[i+1] is added to this partially sorted array at the correct position so that we now have a
partially sorted array of size i+1. Thus after n-1 iterations, we get a fully sorted array.
Example:
Original Array :
and so on.
Algorithm B :
Algorithm B modifies Algorithm A as follows:
For a given array and a fixed value of h, the algorithm uses Algorithm A to sort the
elements that are h indices apart i.e., a[i], a[i+h], a[i+2h], a[i+3h],. are in sorted order for
all values of i. This is repeated for different values of h= { n/2, n/4, n/8, n/16,..}. When
h=1, the array is fully sorted.
Example :
Original Array :
80
60
40
30
10
50
70
20
h=4 :
10
50
40
20
80
60
70
30
All subarrays of elements 4 indices apart ((10, 80), (50,60),) are in sorted order.
h=2:
10
20
40
30
70
50
80
60
All subarrays of elements 2 indices apart ((10, 40, 70, 80), (20, 30, 50, 60)) are in sorted
order.
h=1:
10
20
30
40
50
60
70
80