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

You are to write a C++ program to compare two sorting algorithms and compare two

ID: 644917 • Letter: Y

Question

You are to write a C++ program to compare two sorting algorithms and compare two searching algorithms by running the algorithms and collecting data on each. Your data for sorting and searching will be strings of 25 characters in length. You are to have your program run, compute and print all the results in one run, not multiple runs. (You are not to run your program once for each data set.)

First Part: 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 six sets of data, 1000 strings, then 3000 strings, 5000, 7000, 9000 and 11000 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 format showing results will do. Use the

Explanation / Answer

Hope it may helps you i compared by taking two sample examples..

Bubble sort:
Bubble Sort is probably one of the oldest, most easiest, straight-forward, inefficient sorting algorithms. It is the algorithm introduced as a sorting routine in most introductory courses on Algorithms. Bubble Sort
works by comparing each element of the list with the element next to it and swapping them if required
void BubbleSort(int a[], int array_size)
{
     int i, j, temp;
     for (i = 0; i < (array_size - 1); ++i)
     {
          for (j = 0; j < array_size - 1 - i; ++j )
          {
               if (a[j] > a[j+1])
               {
                    temp = a[j+1];
                    a[j+1] = a[j];
                    a[j] = temp;
               }
          }
     }
}

Bubble sort algorithm...
Example :


    8 6 10 3 1 2 5 4 } pass 0
    6 8 3 1 2 5 4 10 } pass 1
    6 3 1 2 5 4 8 10 } pass 2
    3 1 2 5 4 6 8 10 } pass 3
    1 2 3 4 5 6 8 10 } pass 4
    1 2 3 4 5 6 8 10 } pass 5
    1 2 3 4 5 6 8 10 } pass 6
    1 2 3 4 5 6 8 10 } pass 7

  
selection sort:

void SelectionSort(int a[], int array_size)
{
     int i;
     for (i = 0; i < array_size - 1; ++i)
     {
          int j, min, temp;
          min = i;
          for (j = i+1; j < array_size; ++j)
          {
               if (a[j] < a[min])
                    min = j;
          }

          temp = a[i];
          a[i] = a[min];
          a[min] = temp;
     }
}

8 6 10 3 1 2 5 4 } pass 0
1 6 10 3 8 2 5 4 } pass 1
1 2 10 3 8 6 5 4 } pass 2
1 2 3 10 8 6 5 4 } pass 3
1 2 3 4 8 6 5 10 } pass 4
1 2 3 4 5 6 8 10 } pass 5
1 2 3 4 5 6 8 10 } pass 6
1 2 3 4 5 6 8 10 } pass 7   

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