0% found this document useful (0 votes)
9 views2 pages

Quick Sort

Quick Sort is a fast sorting algorithm that uses the divide and conquer principle. It involves selecting a pivot, partitioning the list into elements less than and greater than the pivot, and recursively sorting the resulting sublists. The algorithm is efficient and requires minimal additional memory.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Quick Sort

Quick Sort is a fast sorting algorithm that uses the divide and conquer principle. It involves selecting a pivot, partitioning the list into elements less than and greater than the pivot, and recursively sorting the resulting sublists. The algorithm is efficient and requires minimal additional memory.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Quick Sort: Intuitive Explanation

What is Quick Sort?


Quick Sort is a fast and efficient sorting algorithm based on the divide and
conquer principle.

How does it work?


1. Pick a pivot: Choose an element from the list (first, last, or random).
2. Partition: Rearrange elements so that:

• Elements smaller than the pivot go to the left.


• Elements greater than the pivot go to the right.
3. Recursive step: Recursively apply Quick Sort to the left and right sub-
lists (excluding the pivot).

4. Base case: When sublists are of length 0 or 1, they are already sorted.

Example
Sort the list [7, 2, 1, 8, 6]:

• Pick pivot = 7
• Partition:
– Left: [2, 1, 6]
– Pivot: [7]
– Right: [8]
• Recursively sort [2, 1, 6] and [8]
• Final result: [1, 2, 6, 7, 8]

1
Advantages
• Very fast in practice.
• Requires little extra memory.

You might also like