# Quick Sort – Data Structure and Algorithm

Serving as a pivotal sorting algorithm, much similar to the way a seasoned card player organizes their deck, quick sort employs a strategy that efficiently divides an array into manageable segments. Unlike insertion sort or selection sort, quick sort doesn’t hinge on individual element placements. Instead, it tackle a divide-and-conquer approach that pivots around the selection of a “pivot” element to partition the array into sections.

## Quick sort Algorithm

In each iteration, quick sort selects a pivot element and rearranges the array such that all elements lesser than the pivot are placed on its left, and those greater are placed on the right. This “partitioning” process is the cornerstone of the algorithm’s efficiency. Subsequently, quick sort recurs on each of the partitioned segments, delving deeper into smaller chunks until the entire array is sorted.

## Working of Quick sort Algorithm

For a comprehensive grasp of the concept, consider an example array: arr[] = {10, 90, 30, 80, 40, 50, 70}

## Code in C++

This table explains each step of the Quick Sort algorithm implementation in C++ along with relevant code snippets.

## Complexity Analysis of Quick Sort

### Time Complexity:

• Worst-case time complexity: O(n^2)
• Average-case time complexity: O(n log n)
• Best-case time complexity: O(n log n)

### Space Complexity:

In conclusion, quick sort stands as an efficient algorithm for sorting arrays. By strategically partitioning and sorting segments, it effectively builds up a fully sorted array. Its average-case time complexity outperforms other quadratic time algorithms, rendering it suitable for larger datasets. However, its worst-case scenario can still pose challenges, making it crucial to consider data characteristics before implementation. Understanding quick sort unveils its potential and contributes to a comprehensive understanding of sorting algorithms.

Merge Sort also used the Divide and Conquer technique for sorting.