Urgent!!

I have an assignment about quick sort and insertion sort and i didnt understand it all :'( !!

sort an array of 10,000 elements using the quick sort algorithm as follows:
a- sort the array using pivot as the middle element of the array.
b- Sort the using pivot as the median of the fist,last and middle elements of the array .
c- sort the array using pivot as the middle element of the array.However ,what the size of any sub list reduces to less than 20 ,sort the sublist using an insertion sort .

d-Sort the using pivot as the median of the fist,last and middle elements of the array .When the size of any sublist reduces to less than 20 ,sort the sublist using an insertion sort.

e-Calculate the print the CPU time for each of the preceding four steps
It seems that you have just studied the sorting algorithms so their details should be fresh in your mind, but not in ours.

The assignment implies that the "quicksort" has concepts "pivot" and "sublist". I have no recollection what they mean, but your study material should have them.


The middle element of an array and the median of a three-element array are unrelated to sorting. Perhaps you have had average and mode too in the same class?


Timing a piece of code. There are functions that return current time. Have you used headers <chrono> or <ctime> ?
hi
read these:
https://en.wikipedia.org/wiki/Quicksort
https://en.wikipedia.org/wiki/Insertion_sort


and for computing relative cpu time:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <ctime>
using namespace std;

int main() {
	
	clock_t t1 = clock();
	// ... time consuming code
	clock_t t2 = clock();	
	double elapsed_time = double(t2 - t1) / CLOCKS_PER_SEC;
	
	cout << "elapsed time = " << elapsed_time << " sec\n";
  	
return 0;	
}

Topic archived. No new replies allowed.