A calculator to predict big-O of sorting functions
Project description
Big-O Caculator
A big-O calculator to estimate time complexity of sorting functions.
inspired by : https://github.com/ismaelJimenez/cpp.leastsq
Installation
pip install big-O-calculator
Usage
You can call which array to test
(n : [10, 100, 1_000, 10_000, 100_000])
Big-O calculator
Args:
functionName ([Callable]): a function to call
array ([string]): "random", "sorted", "reversed", "partial", "Ksorted"
Warn:
To see the result of function, return the array.
K in Ksorted will use testSize//2
from bigO import bigO
def countSort(arr): # stable
# Time Complexity : O(n) | Space Complexity : O(n)
minValue = min(arr)
maxValue = max(arr) - minValue
buckets = [0 for x in range(maxValue + 1)]
for i in arr:
buckets[i - minValue] += 1
index = 0
for i in range(len(buckets)):
while buckets[i] > 0:
arr[index] = i + minValue
index += 1
buckets[i] -= 1
return arr
tester = bigO.bigO()
complexity, _, res = tester.test(countSort, "random")
complexity, _, res = tester.test(countSort, "sorted")
complexity, _, res = tester.test(countSort, "reversed")
complexity, _, res = tester.test(countSort, "partial")
complexity, _, res = tester.test(countSort, "Ksorted")
''' Result
Running countSort(random array)...
Completed countSort(random array): O(N)
Running countSort(sorted array)...
Completed countSort(sorted array): O(N)
Running countSort(reversed array)...
Completed countSort(reversed array): O(N)
Running countSort(partial array)...
Completed countSort(partial array): O(N)
Running countSort(Ksorted array)...
Completed countSort(Ksorted array): O(N)
'''
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
big-O calculator-0.0.4.tar.gz
(4.1 kB
view hashes)
Built Distributions
big_O_calculator-0.0.4-py3.7.egg
(16.8 kB
view hashes)
Close
Hashes for big_O_calculator-0.0.4-py3.7.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07771628a98176789d3f4d325f870e015a9005b936f50f3df6bd68c29e5ebb79 |
|
MD5 | a210f5a0033c31c9329bd58af5b92e3a |
|
BLAKE2b-256 | 00abaf7e78405393c0e92054240039c6556fa4233bb68a6eb767d32795d098db |
Close
Hashes for big_O_calculator-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4acc957fa45b61d7afe9277adc9c7acd6b611eaabeca326eb2ad048acb9c6957 |
|
MD5 | b23a92c8cd83bef51d0aa16d927a4b11 |
|
BLAKE2b-256 | 3aedae1f483899defc576adc68d3695c097cd0d305bbfd819bfd9f0557165d85 |