Skip to main content

my first package that focuses on sorting algorithms

Project description

timedsorts-python

About

timedsort is a python module that allows new coders to see the time differences in a variety of sorting algorithms. Although many people use languages such as C++ for algorithmic design, it is notorious for having a steep learning curve. Python on the otherhand is more beginner friendly. With that in mind, this module provides the ability for people to see the relative differences of sorting algorithm speeds through time.

You may call help_me() to see a more detailed description!

Builtin Libraries

timesort uses the following builtin libraries:

  1. time: perf_counter (timer decorator)
  2. random: randint (gen_ran_int)
  3. functools: wraps (timer decorator)
  4. itertools: permutations (bogo sort)

SORTING ALGORITHMS

timedsort allows you to time the following sorting algorithms

  1. bubble sort
  2. selection sort
  3. insertion sort
  4. merge sort
  5. heap sort
  6. quick sort
  7. call help_me() to see the meme sorts!

How to use

  • generate a list of integers we can use the gen_ran_int() function!
  • parameters format: (length, range1, range2)
  • if range1 and range2 are ommitted, the range would automatically from 0 to twice the length

e.g.

import timedsorts as ts

arr = ts.gen_ran_int(10)

#[7, 24, 35, 28, 36, 37, 2, 10, 20, 0, 18, 28, 0, 0, 34, 30, 8, 19, 6, 29]

arr2 = ts.gen_ran_int(5,-10,10)

#[-7, -1, -1, 5, 10]

You may then call a sorting function to be timed!

ts.bubble(arr)

outputs:

[7, 24, 35, 28, 36, 37, 2, 10, 20, 0, 18, 28, 0, 0, 34, 30, 8, 19, 6, 29]

[0, 0, 0, 2, 6, 7, 8, 10, 18, 19, 20, 24, 28, 28, 29, 30, 34, 35, 36, 37]

bubble sort time was: 0.00010280001151841134 seconds

or

ts.bubble(arr, out = False)

outputs:

bubble sort time was: 7.199999527074397e-05 seconds

As one can see, it is faster because the program doesn't print the list before and after sorting. When comparing algorithms, make sure that this kwarg is the same throughout the program.

More Examples:

ts.bubble(arr, out = False)

ts.quick(arr, out = False)

outputs:

bubble sort time was: 8.349999552592635e-05 seconds

quick sort time was: 4.939999780617654e-05 seconds

Notes

If you would like to mutate the actual list, add an underscore before the function you call! This calls the raw algorithm used to sort the list! Make sure that the argument placed for these functions is 1 list. It also does't display the time taken.

suppose we have the following code:

print(arr)

ts._selection(arr)

print(arr)

ts._heap(arr)

print(arr)

outputs:

[7, 24, 35, 28, 36, 37, 2, 10, 20, 0, 18, 28, 0, 0, 34, 30, 8, 19, 6, 29]

[0, 0, 0, 2, 6, 7, 8, 10, 18, 19, 20, 24, 28, 28, 29, 30, 34, 35, 36, 37]

[0, 0, 0, 2, 6, 7, 8, 10, 18, 19, 20, 24, 28, 28, 29, 30, 34, 35, 36, 37]

This actually changes the list.

Complexities

One may call on the BIGO function to see an algorithm's time complexity!

e.g.

ts.BIGO("bubble")

ts.BIGO("MeRge")

It is not case sensitive!

outputs:

bubble sort:

BEST: O(n)

AVE: O(n^2)

WORST: O(n)

merge sort:

BEST: O(n log(n))

AVE: O(n log(n))

WORST: O(n log(n))

Appendices:

  • Vince Tiu
  • Geek for Geeks
  • Stack Overflow
  • mycodeschool
  • Abdul Bari

Hope you enjoy!

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

timedsorts-0.0.2.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

timedsorts-0.0.2-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file timedsorts-0.0.2.tar.gz.

File metadata

  • Download URL: timedsorts-0.0.2.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.1

File hashes

Hashes for timedsorts-0.0.2.tar.gz
Algorithm Hash digest
SHA256 8d101bb8ed7f0ed0e9be4d3e096296d4f38b71000cb58f2484ec1c54d6de6d1b
MD5 aded8a57f46a9c72cd8b5dea1b48fd24
BLAKE2b-256 56b8cd885882adee3f452a7d55551579cdef91b6169c317e9ef668f25e927739

See more details on using hashes here.

File details

Details for the file timedsorts-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: timedsorts-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.1

File hashes

Hashes for timedsorts-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5dcf855e816816eb4089848148eb77cf3c71597eb52257477f226b4803d1de45
MD5 610e2e672de37eca8efbb59a83c709a9
BLAKE2b-256 eae8fd1c7c5bb81f98fd4a8d1f35d93063a83a70196760a638bb91ca474f03df

See more details on using hashes here.

Supported by

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