Skip to main content

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

Usage

You can call which array to test

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, _ = tester.test(countSort, "random")
complexity, _ = tester.test(countSort, "sorted")
complexity, _ = 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(partial array)...
Completed countSort(partial array): O(N)
'''

Project details


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.2.tar.gz (3.5 kB view hashes)

Uploaded Source

Built Distribution

big_O_calculator-0.0.2-py3-none-any.whl (5.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page