1 quick sort

Upload: reddy1984

Post on 09-Mar-2016

213 views

Category:

Documents


0 download

DESCRIPTION

qs

TRANSCRIPT

Merge SortPage 3 of 3

PROGRAM 2:- Using OpenMP, implement a parallelized Merge Sort algorithm to sort a given set of elements and determine the time required to sort the elements. Repeat the experiment for different values of n, the number of elements in the list to be sorted and plot a graph of the time taken versus n. The elements can be read from a file or can be generated using the random number generator.

Algorithm MergeSort (A, low, high)// Input: An n-element Array A[0..n 1]// Output: Sorted array A

if low < high // at least two elementsmid (low + high) / 2 // divide the list into two halvesMergeSort(A, low, mid)MergeSort(A, mid + 1, high)Merge(a,low, mid, high)end MergeSort.

Algorithm Merge(A[0..n 1], low, mid, high)// Input: Semi sorted Array A// Output: Merged sorted array A from low to high

i k low // i is for the first sublistj mid + 1 // j is for the second sublist

while (i