Data Structures using C - Solved Data Structure Examples
Section I - Data structures using C
Assignment 1: Sorting Techniques (Non recursive)
Set A
- Sort a random array of n integers (accept the value of n from user) in ascending order by using bubble sort algorithm.
- Sort a random array of n integers (accept the value of n from user) in ascending order by using insertion sort algorithm.
Set B
- Read the data from the file “employee.txt” and sort on age using insertion sort / bubble sort.
- Read the data from the file “employee.txt” and sort on names in alphabetical order (use strcmp) using bubble sort / insertion sort.
Set C
- What modification is required to insertion sort to sort the integers in descending order ?
- What modifications are required to bubble sort to sort the integers in descending order ?
- What modifications are required to bubble sort to count the number of swaps?
- What modifications are required to insertion sort to count the number of key comparisons ?
- What modifications are required to improve bubble sort to stop further passes if the file is already sorted that is when there are no more swaps ?
- Compare the system time taken by insertion sort and bubble sort by using 'time'
command on a random file of size 10000 or more.
$ time ./a.out - What modifications are required to output the array contents after every pass of the sorting algorithm ?
Comments