Data Structure: Implementing Quick Sort using C/C++

Algorithm

1. Declare and initialize necessary variables
2. Pick a pivot element.
3. FInd the proper position of the pivot element
4. Divide the total array into two sub arrays so that all elements
of the left sub array are less than pivot and that of right are greater than pivot.
5. Do the quick sort on the each subarrays

Source Code:

Output:

 

QuickSort

 

Efficiency of Quick Sort

 

Assume that file size n is a power of 2 i.e. n = 2^m or m = logn. Also assume proper position of pivot is always at middle. In first pass, there are n comparisons and file splits into subfiles of size n/2 and so on . So total number of comparisons is O(n*m) or O(nlogn).

SHARE Data Structure: Implementing Quick Sort using C/C++

You may also like...

2 Responses

  1. Anonymous says:

    Your codes are actually a lifesaver man….
    thanks a lot..

    Would you please give me the most optimized code for Heap Sort through C++
    give me the Link…. I didn't find it on your website..

Leave a Reply

Your email address will not be published. Required fields are marked *

Share