Quick Sort in C [Program & Algorithm]

In this tutorial you will learn about algorithm and program for quick sort in C.


Quick sort is the fastest internal sorting algorithm with the time complexity O (n log n). The basic algorithm to sort an array a[ ] of n elements can be described recursively as follows:


Quick Sort Algorithm

1. If n < = 1, then return.


2. Pick any element V in a[]. This is called the pivot.
3. Rearrange elements of the array by moving all elements xi > V right of V and all elements x­i < = V left of V. If the place of the V after re-arrangement is j, all elements with value less than V, appear in a[0], a[1] . . . . a[j – 1] and all those with value greater than V appear in a[j + 1] . . . . a[n – 1].
4. Apply quick sort recursively to a[0] . . . . a[j – 1] and to a[j + 1] . . . . a[n – 1].

Quick Sort Animation

Quick Sort Animation, Quick Sort in C
Quick Sort Animation, Quick Sort in C
Visualization of the quicksort algorithm. The horizontal lines are pivot values.


Quick Sort Program in C


What is Quick Sort? Algorithm and C Program to Implement Quick Sort
If you found anything incorrect or have any doubts regarding above quick sort in C tutorial then comment below.

10 thoughts on “Quick Sort in C [Program & Algorithm]

  1. sadia julekha

    can anyone make me understand the implementation of quicksort?

  2. SambasivaRao

    simple programming,easy to understand.
    thank you bro.

  3. sivabala

    hi boss can you explain in detail manner how the quick sort is working ?

  4. Devendra Prajapati

    If i want to Enter 100 or MORE Number then……

    User Want Enter Any Number so..

    What he/she will do??

  5. Sirisha

    you have to return the array in order to print it the array after sorting.And we should sort the key as well i.e,pivot element
    So the j in the calling of quicksort equals to j in any of the call

  6. SHreya

    I seriously love the animation part, which makes it more interesting to see the content.
    And Sir, you program’s are so, accurate and efficient.
    Thank you for providing us this website and helping new coder like me, to get to know, what exactly is a GOOD CODE to approach.

    You are seriously doing a good job.
    Thank you.

  7. Hania

    void quick_sort(int a[],int l,int u)
    int j;

    can anyone explain this??

  8. JanieBiggie

    Hi admin, i’ve been reading your page for some time and I really like coming back
    here. I can see that you probably don’t make money
    on your page. I know one interesting method of earning
    money, I think you will like it. Search google for:
    dracko’s tricks


Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.