Assn1 29 9 17
Assn1 29 9 17
Assn1 29 9 17
Assignment No. 1
Due Date: Thursday 5th October 2017
1. Given below is the source code of radix sort. Dry run the following source code as
discussed in the lecture:
//Radix Sort:
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
int main(void)
{
int len = 16, x[16], i;
// size_t len = 16, i;
each(i, len) x[i] = rand() % 512 - 256;
radix_sort(x, len);
return 0;
}
2. Given an array storing integers ordered by value, modify the binary search algorithm to return
the position of the integer with the greatest value less than K(K is the key to be searched) when
K itself does not appear in the array. Return ERROR if the least value in the array is greater than
K.
3. The following run times were obtained when using two different algorithms on a data set of size
n. Based on this timing data, guess the complexity of each algorithm as a function of n. Use big-
O notation in its simplest form and briefly explain how you reached your conclusion.
1000 0.743
2000 3.021
4000 12.184
8000 50.320
1000 0.01
1000000 20
1000000000 30000
4. Implement sequential search and binary search algorithms on your computer. Run timings for
each algorithm on arrays of size n = 10 i for i ranging from 1 to as large a value as your
computer’s memory/compiler will allow. For both algorithms, store the values 0 through n - 1 in
order in the array, and use a variety of random search values in the range 0 to n - 1 on each size
n. Graph the resulting times. When is sequential search faster than binary search for a sorted
array?
5. Implement bubble sort in C/C++. Graph the resulting running times for small, medium and
then the largest value of n.
*****