Write a program that will allow a user the opportunity to compare and analyze th
ID: 3687882 • Letter: W
Question
Write a program that will allow a user the opportunity to compare and analyze the efficiency of several sorting algorithms The program will sort integer arrays of size 10, 100 and 1,000 respectively using the bubble, selection and insertion sort algorithms The program should output in a tabular form the name of the algorithm, size of the array, number of comparisons and number of swaps You should incorporate passing an entire array through to a function at some point in your program. The outlining of the output may look something like this (Note the values are fake and do not represent a real scenario) Write a program that will allow a user the opportunity to compare and analyze the efficiency of linear and sequential search algorithms I he program will search integer arras's using both binary and linear search algorithms for a key value The arrays will be in sizes of 10. 100 and 1.000 The program should output in a tabular form the name of the algorithm, size of the array, and number of comparison In the case of the binary search algorithm, output the number of comparisons used by to sort the array Remember, you must first sort the array before employing the binary search algorithm Use functions when writing the program. You should incorporate passing an entire arras through to a function at some point in your program. The outlining of the output may look something like this (Note: the values are fake and do not represent a real scenario) Please use the notes section of your Blackboard submission to search your thoughts and observations about the various algorithms I suggest you use the built-in random number generator to populate the arrays.Explanation / Answer
code in c for all sort and search
Bubble sort:
#include <stdio.h>
int main()
{
int array[100], n, c, d, swap;
printf("Enter number of elements ");
scanf("%d", &n);
printf("Enter %d integers ", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
for (c = 0 ; c < ( n - 1 ); c++)
{
for (d = 0 ; d < n - c - 1; d++)
{
if (array[d] > array[d+1]) /* For decreasing order use < */
{
swap = array[d];
array[d] = array[d+1];
array[d+1] = swap;
}
}
}
printf("Sorted list in ascending order: ");
for ( c = 0 ; c < n ; c++ )
printf("%d ", array[c]);
return 0;
}
Insertion sort
Selection sort
Linear search
Binary search
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.