# What is Quick Sort Algorithm?

Article By Digamber Rawat Published on

A highly efficient and effective algorithm that deals with sorting and has been based on partitioning a more significant array of data into smaller arrays is known as Quick sort.

A big set of the array gets divided into two different arrays, and one of them holds the smaller values rather than the specified values like a pivot. On the other hand, the other array holds a value which is much higher than the value of the pivot.

Quick sort algorithm starts a partition and then identifies itself whether capable or not and resulting in the two subarrays from the original one.

This algorithm is quite efficient and productive because it sets and the average for more significant sized data and the complexity for the worst case scenario is where N is the number of items Ο(n2).

## Quick Sort Algorithm in JavaScript

The way we understand the partitioning process of the quick sort, here are the steps we can take to write an algorithm.

function quickSort(realArray) {
if (realArray.length <= 1) {
return realArray;
} else {
let newArray = [],
left = [],
right = [],
pivot = realArray.pop(),
length = realArray.length;
for (let i = 0; i < length; i++) {
if (realArray[i] <= pivot) {
left.push(realArray[i]);
} else {
right.push(realArray[i]);
}
}
return newArray.concat(quickSort(left), pivot, quickSort(right));
}
}
let arr = [5, 1, 3, 6, -1, 5, 0 ];
let modifiedArray = quickSort(arr);
// Result: [-1,0,1,3,5,5,6]

Digamber Rawat

I am a software engineer from India, love to learn and write about latest web and mobile technologies like: MongoDB, Angular 2+, Firebase, Express JS, Python, Node JS, JavaScript, RxJS etc.