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 [str]: "random", "sorted", "reversed", "partial", "Ksorted"
Returns:
complexity (str) : ex) O(n) |
time (float) : Time took to sort all 5 different arrays in second (max=100,000)
Info:
To see the result of function, return the array.
K in Ksorted will use testSize//2
from bigO import bigO
tester = bigO.bigO()
tester.test(bubbleSort, "sorted")
Example
from bigO import bigO
from random import randint
def quickSort(array): # in-place | not-stable
"""
Best : O(nlogn) Time | O(logn) Space
Average : O(nlogn) Time | O(logn) Space
Worst : O(n^2) Time | O(logn) Space
"""
if len(array) <= 1:
return array
smaller, equal, larger = [], [], []
pivot = array[randint(0, len(array) - 1)]
for x in array:
if x < pivot:
smaller.append(x)
elif x == pivot:
equal.append(x)
else:
larger.append(x)
return quickSort(smaller) + equal + quickSort(larger)
tester = bigO.bigO()
complexity, time = tester.test(quickSort, "random")
complexity, time = tester.test(quickSort, "sorted")
complexity, time = tester.test(quickSort, "reversed")
complexity, time = tester.test(quickSort, "partial")
complexity, time = tester.test(quickSort, "Ksorted")
''' Result
Running quickSort(random array)...
Completed quickSort(random array): O(nlog(n))
Time took: 0.35816s
Running quickSort(sorted array)...
Completed quickSort(sorted array): O(nlog(n))
Time took: 0.37821s
Running quickSort(reversed array)...
Completed quickSort(reversed array): O(nlog(n))
Time took: 0.38500s
Running quickSort(partial array)...
Completed quickSort(partial array): O(nlog(n))
Time took: 0.35820s
Running quickSort(Ksorted array)...
Completed quickSort(ksorted array): O(nlog(n))
Time took: 0.38140s
'''
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.6.tar.gz
(4.4 kB
view hashes)
Built Distributions
big_O_calculator-0.0.6-py3.7.egg
(17.3 kB
view hashes)
Close
Hashes for big_O_calculator-0.0.6-py3.7.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ef8ab65e401302cdf27df8c0ae1578aafb690572384e79b4bdd3d381df54b59 |
|
MD5 | 4aa27721a901d0cedcbf2f07f5086cac |
|
BLAKE2b-256 | 4d677a5ca122c63a6e30b6c2e6a2baa6e4a318fdeee65fa621a0daedf466971b |
Close
Hashes for big_O_calculator-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51ee424f81284159241009b3473088c24dc7100ba82f8e431e121389e25931d4 |
|
MD5 | e14e5c3cb15c82a701ca25f2c45e1262 |
|
BLAKE2b-256 | 6ac716214db40eab0fc10dd1381a72463f348366a9a0e0a93befdb239fee595b |