### Thread: How To Analyze The Best Case, Worst Case And Average Case In Sorting

1. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2004
Posts
77
Rep Power
14

#### How To Analyze The Best Case, Worst Case And Average Case In Sorting

Hello every one im back again, asking for some help. im writing up a code doing binary and sequantial search then sorting an array.Got that done so far, but unfortuantally, I got stuck. I need analyze the best case, worst case and average case for each algorithm , and wirte an analysis report. any help or hint is appracited. Here is on older version of my code to show you what im doing:

Code:
```
#include "SeqSearch.h"

using namespace std;
int  sel, Num;
int main(void)
{
cout << "=========================\n";
cout << "*       MAIN MENU       *\n";
cout << "=========================\n\n";

cout << " 1) Create a List \n";
cout << " 2) Sequantial Search\n";
cout << " 3) Binary Search\n";
cout << " 4) Quit\n\n";
cout << "=========================\n";

cout <<" Enter Selection:  ";
cin >> sel;
cout <<"\n";

if ( sel == 1 )
{
int Num, Position;

IntArrayType IntArray;

GenerateArray(IntArray, MAXINDEX);
cout << "Here is the content of the array: " << endl;
PrintArray(IntArray, MAXINDEX);

}

else if ( sel == 2 )
{

IntArrayType IntArray;
int Num, Position;

GenerateArray(IntArray, MAXINDEX); // generate 100 random integers

cout << "Here is the content of the array: " << endl;
PrintArray(IntArray, MAXINDEX);

cout << "Enter the number to search for: ";
cin >> Num;

// Search the IntArray for Num and return its position
Position = SeqSearch(IntArray, MAXINDEX, Num);

cout << "Cannot find " << Num << "." << endl;
else
cout << "Found " << Num << " in position " << Position << ".\n";

}

if ( sel == 3 )

{

IntArrayType IntArray;
int Num, Pos;

GenerateArray(IntArray, MAXINDEX); // generate sorted integer array

cout << "The contents of the array are: " << endl;
PrintArray(IntArray, MAXINDEX);

cout << "Enter the integer to search for: " << endl;
cin >> Num;

// Pos = BinarySearch(IntArray, 0, MAXINDEX - 1, Num);

if(Pos == -1)

else
cout << "Number " << Num << " found in Position " << Pos << endl;

}

for( pass = 1; pass < SIZE; pass++ ){
for( i=0; i < SIZE - 1; i++ ){
if( a[i] > a[ i+1 ] ){
hold = a[i];
a[i] = a[ i + 1 ];
a[ i+1 ] = hold;
}
return 0;
}```
2. Missing your trailing code tag ;) . It isn't clear to me precisely what your question is and how it relates to the code posted.
3. No Profile Picture
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2004
Posts
77
Rep Power
14
well after sorting i need to analyze the best case, worst case and average case for each sort, and write an analysis report of the program.
4. Apart from mathematical analysis, you could characterize it by running a large number of differing sets of data by it and just collect the numbers you get. Then you pop 'em into a spreadsheet and devise some sort of presentation. You'd need to add a way to time its operation. You could probably automate the trials process.