# Lab4 - CS 284 Algorithms Summer semester 2010 Lab 4 Lab...

This preview shows pages 1–2. Sign up to view the full content.

CS 284 Algorithms Summer semester 2010 Lab 4 Lab objectives: - Understand the three different partition techniques used in quick sort used in chapter 7. - Compare the performance of these techniques. Related chapter(s): 7. Lab instructions (steps): 1. Write the following program and run it. 1. #include <time.h> 2. #include <iostream> 3. #include <stdio.h> 4. void MergeSort( int A[], int left, int right); 5. void Merge( int A[], int left, int mid, int right); 6. void printA( int A[], int n); 7. void QuickSort( int A[], int p, int r); 8. int Partition1( int A[], int p, int r); 9. int Partition2( int A[], int p, int r); 10. int Partition3( int A[], int p, int r); 11. void swap( int *, int *); 12. 13. int pm = 1; // Partition method: 1, 2 or 3 14. 15. using namespace std; 16. void main() 17. { 18. clock_t start1, finish1; 19. clock_t start2, finish2; 20. int maxK=1; 21. int MaxRep=1; 22. int initialN=10; 23. int n; // input size 24. 25. if (initialN>=20) cout << "Average Time Taken by Merge and Quick Sort : " <<endl; 26. if (initialN>=20) cout << "n\t \ ttime\t \ t time" <<endl; 27. if (initialN>=20) cout << "-----------------------------" <<endl; 28. for ( int k=1, n=initialN; k<=maxK; k++, n*=3){ 29. float TotalTime1=0; // merge sort time 30. float TotalTime2=0;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 04/15/2011 for the course CS 284 taught by Professor Jamess. during the Spring '10 term at Jordan University of Science & Tech.

### Page1 / 4

Lab4 - CS 284 Algorithms Summer semester 2010 Lab 4 Lab...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online