Quick Sort (Divide & Conquer)

Visualize the partition-based divide and conquer approach of quick sort

Quick Sort (Divide & Conquer)

Quick Sort is a highly efficient divide-and-conquer algorithm that works by selecting a 'pivot' element and partitioning the array around it.

Theory & Concepts

Definition:

Quick Sort picks a pivot element and partitions the array so all elements smaller than pivot come before it and larger elements come after it. Then it recursively sorts the subarrays.

Key Points:

  • In-place sorting algorithm with O(log n) space complexity
  • Average case O(n log n), worst case O(n²) time complexity
  • Not stable - doesn't preserve relative order of equal elements
  • Pivot selection strategy affects performance significantly

Applications:

  • General purpose sorting in programming languages
  • Quick selection algorithm for finding kth element
  • Cache-friendly due to in-place nature
  • Basis for hybrid sorting algorithms

University Guidelines

Exam Weightage
6-8 marks Marks

Syllabus Coverage:

  • Quick sort algorithm implementation
  • Partitioning technique
  • Best, average and worst case analysis
  • Randomized quick sort
  • Comparison with merge sort

Common Questions:

  • Implement quick sort with different pivot strategies
  • Analyze time complexity in all cases
  • Trace quick sort execution
  • Compare quick sort vs merge sort performance

Exam Tips:

Show partitioning step clearly
Mention pivot selection strategies
Explain why worst case is O(n²)
Highlight in-place sorting advantage

Algorithm Details

Average: O(n log n), Worst: O(n²)
Time Complexity
O(log n) recursion stack
Space Complexity

Algorithm Steps:

  1. 1Choose a pivot element from array
  2. 2Partition array: elements < pivot on left, > pivot on right
  3. 3Recursively apply quick sort to left subarray
  4. 4Recursively apply quick sort to right subarray
  5. 5Base case: array size ≤ 1

Configure Quick Sort

💡 Enter numbers separated by commas. Example: 5, 2, 8, 1, 9
✓Current Array (7 elements):
64
34
25
12
22
11
90

Quick Sort Results

⚡

Click "Sort Array" to see the quick sort visualization

Complexity Analysis

Best Case

O(n log n)

When pivot always divides array into two equal halves

Average Case

O(n log n)

With random pivot selection or good pivot choices

Worst Case

O(n²)

When pivot is always the smallest or largest element