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, 1000, 10000, 50000]
Big-O calculator
Args:
functionName ([string]): function name to call
array ([string]): "random", "sorted", "reversed", "partial"
from bigO import bigO
def countSort(arr): # stable
# Time Complexity : O(n) | Space Complexity : O(n)
sortedArr = arr[:]
minValue = min(arr)
maxValue = max(arr) - minValue
buckets = [0 for x in range(maxValue + 1)]
for i in sortedArr:
buckets[i - minValue] += 1
index = 0
for i in range(len(buckets)):
while buckets[i] > 0:
sortedArr[index] = i + minValue
index += 1
buckets[i] -= 1
return sortedArr
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")
''' 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)
'''
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.3.tar.gz
(3.4 kB
view hashes)
Built Distribution
Close
Hashes for big_O_calculator-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3f8a7a30af2ce8ed7708b904a11f192c41a6f92f1fc2d89d055fec614891f60 |
|
MD5 | fb8a9eac3c1cdb55d20d48c0532edd52 |
|
BLAKE2b-256 | a5c54fd1f83636021ebe6addad1380c960316219283e71c1d72d18187fa5e39c |