MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / _partition

Function _partition

searches/quick_select.py:7–23  ·  view source on GitHub ↗

Three way partition the data into smaller, equal and greater lists, in relationship to the pivot :param data: The data to be sorted (a list) :param pivot: The value to partition the data on :return: Three list: smaller, equal and greater

(data, pivot)

Source from the content-addressed store, hash-verified

5https://en.wikipedia.org/wiki/Quickselect
6"""
7def _partition(data, pivot):
8 """
9 Three way partition the data into smaller, equal and greater lists,
10 in relationship to the pivot
11 :param data: The data to be sorted (a list)
12 :param pivot: The value to partition the data on
13 :return: Three list: smaller, equal and greater
14 """
15 less, equal, greater = [], [], []
16 for element in data:
17 if element.address < pivot.address:
18 less.append(element)
19 elif element.address > pivot.address:
20 greater.append(element)
21 else:
22 equal.append(element)
23 return less, equal, greater
24
25def quickSelect(list, k):
26 #k = len(list) // 2 when trying to find the median (index that value would be when list is sorted)

Callers 1

quickSelectFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected