{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Lab3 - CS 284 Algorithms Summer semester 2010 Lab 3 Lab...

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

CS 284 Algorithms Summer semester 2010 Lab 3 Lab objectives: - Understand the heap properties. - Implements Heap sort using different techniques. Related chapter(s): 6. Lab instructions (steps): 1. Write the following program and run it. #include <time.h> #include <iostream> #include <stdio.h> void printA( int A[], int n); void checkHeap( int A[], int n); void Heapify( int A[], int n, int i); void BuildHeap( int A[], int n); void BuildHeapNEW( int A[], int n); void BuildHeapNEW2( int A[], int n); void HeapSort( int A[], int n); void HeapSortNEW( int A[], int n); void HeapSortNEW2( int A[], int n); int HeapSize=0; using namespace std; int main() { clock_t start1, finish1; int maxK=1; int initialN=10; int MaxRep=1; int n; // input size if (initialN>=20) cout << "Average Time Taken by Heap Sort : " <<endl; if (initialN>=20) cout << "n\ttime" <<endl; if (initialN>=20) cout << "-------------" <<endl; for ( int k=1, n=initialN; k<=maxK; k++, n*=2){ float TotalTime1=0; // Heap sort time for ( int Rep=1; Rep<=MaxRep; Rep++){ //create and intialize A with size n int *A; srand ( time(NULL) ); A= new int [n]; for ( int i=0; i<n; i++) {A[i]=(rand() % 1000);} if (initialN<20) printA(A,n); if (initialN<20)

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.

{[ snackBarMessage ]}

### Page1 / 2

Lab3 - CS 284 Algorithms Summer semester 2010 Lab 3 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