Quicksort

Mathematics Discrete Mathematics Source: Wikipedia Cite
Primary: C.A.R. Hoare; NIST DADS
Publication: Quicksort algorithm
Year: 1959
URL: NIST DADS

Description

Divide-and-conquer in-place sort. Pick pivot (e.g. last element). Partition: elements < pivot go left, > pivot go right. Recursively quicksort left and right partitions. Average O(n log n); worst O(n²) if pivot bad. Not stable.

Source: Wikipedia

Algorithm Flowchart

graph TD A1["Array A lo hi"] D1{"Base case?\nlo ge hi"} B1["Pick pivot p\nPartition A around p"] C1["Quicksort A lo p-1\nQuicksort A p+1 hi"] F1["Return in-place sorted"] A1 --> D1 D1 -->|Yes| F1 D1 -->|No| B1 B1 --> C1 C1 --> F1 classDef red fill:#ff6b6b,color:#fff,stroke:#c0392b classDef yellow fill:#ffd43b,color:#000,stroke:#f59f00 classDef green fill:#51cf66,color:#fff,stroke:#40c057 classDef lightblue fill:#74c0fc,color:#fff,stroke:#4dabf7 classDef violet fill:#b197fc,color:#fff,stroke:#9775fa classDef lavender fill:#e6e6fa,color:#333,stroke:#b19cd9 class A1 red class B1 yellow class C1 green class F1 violet class D1 lavender

Color Scheme (GLMP 6-Color)

Red
Triggers & Inputs
Yellow
Structures & Objects
Green
Processing & Operations
Light Blue
Intermediates & States
Violet
Products & Outputs
Lavender
Decision diamonds

Process Statistics

  • Nodes: 5
  • Edges: 5
  • OR gates: 1
  • Loops: 0
  • AND gates: 1
  • Complexity: O(n log n) avg, O(n²) worst

Keywords

  • quicksort
  • divide and conquer
  • sorting
  • partition