menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

Sorting al...
source image

Prodevelopertutorial

3w

read

193

img
dot

Sorting algorithm 5: Quick Sort

  • Quick Sort is a divide and conquer technique.
  • Step 1: The first step is to get a pivot element.
  • Step 2: Once we get the pivot element, then we create 2 half such that, the elements left to the pivot element are lesser than pivot element.
  • In this example, we shall select the lowest element as pivot element.
  • By doing the above 2 operations, we make sure that all the elements to the left of pivot element are less and elements to right of pivot are greater.
  • Implementation of Quick Sort in C
  • In the worst case, the time taken will be O(n^2).
  • Steps to select pivot element.
  • we swap the elements in their respective positions.
  • Similarly, while comparing with the right pointer, we check if the element is greater than the pivot element. If the element is less than the pivot element, we swap the elements.

Read Full Article

like

11 Likes

For uninterrupted reading, download the app