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

    Join Date
    Jul 2004
    Posts
    77
    Rep Power
    11

    Question 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);
    
       if (Position == -1)  // not found
          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)
    	cout << "Not found" << endl;
    
       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. #2
  3. Lord of Dorkness
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2004
    Location
    Central New York. Texan via Arizona, out of his element!
    Posts
    8,524
    Rep Power
    3314
    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.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    77
    Rep Power
    11
    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.
  6. #4
  7. Lord of Dorkness
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2004
    Location
    Central New York. Texan via Arizona, out of his element!
    Posts
    8,524
    Rep Power
    3314
    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.
    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.

IMN logo majestic logo threadwatch logo seochat tools logo