Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This program uses Bubble sort and Selection sort as well as Linear and Binary se

ID: 3551444 • Letter: T

Question

This program uses Bubble sort and Selection sort as well as Linear and Binary search.


You are to compare two sorting algorithms and to compare two searching algorithms by running and collecting data on each. Your data for sorting and searching will be strings of 25 characters in length. The two sorts to compare are the Bubble Sort and the Selection Sort. You are to test your sorts against different set of strings. Each sort will sort 500 strings, then 1000 strings, 2000, 3000, 4000 and 5000 strings. You will compare how well each sort did with the different data sizes and show results. I would like to see a plot of the results. A table print out will do. Use the 'time' function and the diff time function to gather sort times. The two searches to use for comparisons are the Linear Search and the Binary Search. You will search for 1000 strings in the array of 5000 strings and compute the average number of probes needed to find a match. The target string will be a randomly selected string from the 5000 string's data set. You will select randomly 1000 strings for testing each search algorithm. You are to generate 25 random characters for each string for your string data sets.

Explanation / Answer

 

Bubble sort and Selection sort Linear and Binary search
#include
<stdio.h> #define size 25 void selection(); int findmin(int []); int i,j,Arr[size],min,counter; int main() { printf(" Enter your elements now "); for(i=0;i<size;i++) scanf("%d",&Arr[i]); printf("You have provided this data "); for(i=0;i<size;i++) printf(" %d",Arr[i]); printf(" Press any key to perform selection sort "); selection(); printf("Result after selection sort "); for(i=0;i<size;i++) printf(" %d",Arr[i]); printf("Selection sort on this array took %d swap operation",counter); } void selection() { for(i=0;i<(size-1);i++) { j = findmin(Arr); if(Arr[i]>Arr[j]) { Arr[i] = Arr[i] + Arr[j]; Arr[j] = Arr[i] - Arr[j]; Arr[i] = Arr[i] - Arr[j]; counter++; } } } int findmin(int a[]) { min = i; for(j=i+1;j<size;j++) { if(a[j]<a[min]) min = j; } return(min); }




Linear and Binary search

#include <stdio.h>
int main() { int c, first, last, middle, n, search, array[5000]; printf("Enter number of elements "); scanf("%d",&n); printf("Enter %d integers ", n); for ( c = 0 ; c < n ; c++ ) scanf("%d",&array[c]); printf("Enter value to find "); scanf("%d",&search); first = 0; last = n - 1; middle = (first+last)/2; while( first <= last ) { if ( array[middle] < search ) first = middle + 1; else if ( array[middle] == search ) { printf("%d found at location %d. ", search, middle+1); break; } else last = middle - 1; middle = (first + last)/2; } if ( first > last ) printf("Not found! %d is not present in the list. ", search); return 0; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote