Example

 

Quick Sort Example: Given Input 4 2 6 5 3 9

 

 

There are two basic operations in the algorithm, swapping items in place and partitioning a section of the array. The basic steps to partition an array are:

 

  1. Find a “pivot” item in the array. This item is the basis for comparison for a single round.

  2. Start a pointer (the left pointer) at the first item in the array.

  3. Start a pointer (the right pointer) at the last item in the array.

  4. While the value at the left pointer in the array is less than the pivot value, move the left pointer to the right (add 1). Continue until the value at the left pointer is greater than or equal to the pivot value.

  5. While the value at the right pointer in the array is greater than the pivot value, move the right pointer to the left (subtract 1). Continue until the value at the right pointer is less than or equal to the pivot value.

  6. If the left pointer is less than or equal to the right pointer, then swap the values at these locations in the array.

  7. Move the left pointer to the right by one and the right pointer to the left by one.

  8. If the left pointer and right pointer don’t meet, go to step 1.

Next

Sorting by MS.K.Abirami

  • BUBBLE SORT

    Bubble sort is a sorting algorithm that works by repeatedly stepping through lists that need to be sorted, comparing each pair of adjacent items and swapping them ...Read more »

  • INSERTION SORT

    A simple sorting technique that scans the sorted list, starting at the beginning, for the correct insertion point for each of the items from the unsorted list… Read more »

  • SELECTION SORT

    It starts by comparing the entire list for the lowest item and moves it to the #1 position. It then compares the rest of the list for the next-lowest item....Read more »

  • QUICK SORT

    A sorting technique that sequences a list by continuously dividing the list into two parts and moving the lower items to one side and the higher items to the other. … Read more »

  • BUBBLE SORT

    The number of comparison between elements and the number of exchange between elements determine the efficiency of Bubble Sort algorithm.Read more »

  • Insertion SORT

    Insertion sort is also a time taking technique as its complexity is O(n2)Read more »

  • selection SORT

    The number of comparison between elements and the number of exchange between elements determine the efficiency of Bubble Sort algorithm.Read more »

  • quick SORT

    The efficeieny of the quicksort depends on the pivot element. However the pivot element can also be choosen at random order or from the last element of the array

    Read more »