You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Array.qsort has quadratic runtime on constant arrays #8087
def m (n : Nat) := Array.range n
def l (n : Nat) := Array.replicate n 0
#eval ((m 100000).qsort).size -- this is fast
#eval ((l 100000).qsort).size -- this is slow
The problem is that we split the list into "less than pivot" and "greater than or equal to pivot" in a naive way, leading to partition calls of size n, n - 1, n - 2 and so on. Solutions are discussed on Wikipedia; options include using a pivoting procedure like the Hoare rule where an all-equal array returns the center index as the pivoting index, or partitioning the array into three parts: less than pivot, equal to pivot or greater than pivot.
Expected behavior: Quicksort does not take quadratic time for reasonable inputs
Actual behavior: Quicksort takes quadratic time if all inputs are equal
Additional Information
This is apparently the bottleneck in the workspace symbol search LSP request!
Activity
feat: improve workspace symbol performance (#8091)