SELECT

Problem Desciption:

Select the k-th smallest element from an unordered list

Example


In [1]:
import random
import randomized_select

# The length of the test list
n = 10 ** 5

# The k-th smallest element
k = n // 2

# The test list of length n
data = [random.randint(0, 100) for _ in range(0, n)]

# Find the k-th smallest element
randomized_select.randomized_select_loop(data, k)


Out[1]:
50