Photo AI
Last Updated Sep 27, 2025
Revision notes with simplified explanations to understand Quick Sort quickly and effectively.
451+ students studying
Quick Sort is a highly efficient, comparison-based sorting algorithm that uses the divide-and-conquer strategy. It partitions the array into two sub-arrays around a chosen pivot element such that elements smaller than the pivot go to the left, and elements larger go to the right. This process is recursively applied to each sub-array until the entire list is sorted.
Step 1: Choose a Pivot
Typically, the first, last, or middle element is chosen, but any element can be the pivot.
Step 2: Partition
Rearrange the array such that:
Apply the same process to the left and right sub-arrays.
Given an unsorted list:
9, 7, 5, 11, 12, 2, 14, 3, 10, 6
Step 1: Choose a pivot (e.g., last element, 6).
Step 2: Partition the array around the pivot.
5, 2, 3, 6, 12, 11, 14, 9, 10, 7
Step 3: Recursively apply Quick Sort to sub-arrays.
2, 3, 5, 6, 7, 9, 10, 11, 12, 14
METHOD QuickSort(array, low, high)
IF low < high
pivotIndex ← Partition(array, low, high)
CALL QuickSort(array, low, pivotIndex - 1)
CALL QuickSort(array, pivotIndex + 1, high)
METHOD Partition(array, low, high)
pivot ← array[high]
i ← low - 1
FOR j FROM low TO high - 1
IF array[j] <= pivot
i ← i + 1
SWAP array[i] AND array[j]
SWAP array[i + 1] AND array[high]
RETURN i + 1
def quick_sort(array, low, high):
if low < high:
pivot_index = partition(array, low, high)
quick_sort(array, low, pivot_index - 1)
quick_sort(array, pivot_index + 1, high)
def partition(array, low, high):
pivot = array[high]
i = low - 1
for j in range(low, high):
if array[j] <= pivot:
i += 1
array[i], array[j] = array[j], array[i]
array[i + 1], array[high] = array[high], array[i + 1]
return i + 1
# Example usage:
data = [9, 7, 5, 11, 12, 2, 14, 3, 10, 6]
quick_sort(data, 0, len(data) - 1)
print(data) # Output: [2, 3, 5, 6, 7, 9, 10, 11, 12, 14]
Example: Given the array 8, 3, 7, 4, 6, 2, 5, 1
1, 2, 3, 4, 5, 6, 7, 8
i
and j
) can result in incorrect placement of elements.low >= high
leads to infinite recursion.Enhance your understanding with flashcards, quizzes, and exams—designed to help you grasp key concepts, reinforce learning, and master any topic with confidence!
120 flashcards
Flashcards on Quick Sort
Revise key concepts with interactive flashcards.
Try Computer Science Flashcards12 quizzes
Quizzes on Quick Sort
Test your knowledge with fun and engaging quizzes.
Try Computer Science Quizzes29 questions
Exam questions on Quick Sort
Boost your confidence with real exam questions.
Try Computer Science Questions27 exams created
Exam Builder on Quick Sort
Create custom exams across topics for better practice!
Try Computer Science exam builder12 papers
Past Papers on Quick Sort
Practice past papers to reinforce exam experience.
Try Computer Science Past PapersDiscover More Revision Notes Related to Quick Sort to Deepen Your Understanding and Improve Your Mastery
Join 500,000+ A-Level students using SimpleStudy...
Join Thousands of A-Level Students Using SimpleStudy to Learn Smarter, Stay Organized, and Boost Their Grades with Confidence!
Report Improved Results
Recommend to friends
Students Supported
Questions answered