Commit 31e2a367 authored by AVANZINI Martin's avatar AVANZINI Martin
Browse files

qselect example added

parent b1dbe066
# Quick-select, abstracted
# Upper Bound: O(n)
def qselect():
var lo, hi, p, pos, N
lo = 0
p = 0
hi = N - 1
while [lo >= 0 ] lo < hi:
tick(hi - lo)
p = rand(N)
if p = pos:
hi = lo
else:
if p < pos:
lo = p + 1
else:
hi = p - 1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment