Quick Sort

Its average-case running time is O(nlog n). Quicksort's performance degrades as the input list becomes more ordered. The worst-case input, a sorted list, causes it to run in O(n^{2})

Pseudocode

Quicksort(A as array, low as int, high as int){
    if (low < high){
        pivot_location = Partition(A,low,high)
        Quicksort(A,low, pivot_location - 1)
        Quicksort(A, pivot_location + 1, high)
    }
}
Partition(A as array, low as int, high as int){
     pivot = A[low]
     leftwall = low

     for i = low + 1 to high{
         if (A[i] < pivot) then{
             leftwall = leftwall + 1
             swap(A[i], A[leftwall])
         }
     }
     swap(A[low],A[leftwall])

    return (leftwall)}
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment