Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
October 15th, 2004, 05:09 PM
 kwik222
Contributing User

Join Date: Jul 2004
Posts: 77
Time spent in forums: 2 h 22 m 39 sec
Reputation Power: 10
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
October 15th, 2004, 05:12 PM
 DaWei_M
Lord of Dorkness

Join Date: Jan 2004
Location: Central New York. Texan via Arizona, out of his element!
Posts: 8,521
Time spent in forums: 4 Weeks 20 h 13 m 16 sec
Warnings Level: 20
Number of bans: 3
Reputation Power: 3268
Missing your trailing code tag . It isn't clear to me precisely what your question is and how it relates to the code posted.
__________________
Functionality rules and clarity matters; if you can work a little elegance in there, you're stylin'.
If you can't spell "u", "ur", and "ne1", why would I hire you? 300 baud modem? Forget I mentioned it.
DaWei on Pointers Politically Incorrect.

#3
October 15th, 2004, 05:47 PM
 kwik222
Contributing User

Join Date: Jul 2004
Posts: 77
Time spent in forums: 2 h 22 m 39 sec
Reputation Power: 10
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
October 15th, 2004, 05:57 PM
 DaWei_M
Lord of Dorkness

Join Date: Jan 2004
Location: Central New York. Texan via Arizona, out of his element!
Posts: 8,521
Time spent in forums: 4 Weeks 20 h 13 m 16 sec
Warnings Level: 20
Number of bans: 3
Reputation Power: 3268
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.

 Viewing: Dev Shed Forums > Programming Languages > C Programming > How To Analyze The Best Case, Worst Case And Average Case In Sorting