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:
- time: perf_counter (timer decorator)
- random: randint (gen_ran_int)
- functools: wraps (timer decorator)
- itertools: permutations (bogo sort)
SORTING ALGORITHMS
timedsort allows you to time the following sorting algorithms
- bubble sort
- selection sort
- insertion sort
- merge sort
- heap sort
- quick sort
- 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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d101bb8ed7f0ed0e9be4d3e096296d4f38b71000cb58f2484ec1c54d6de6d1b
|
|
| MD5 |
aded8a57f46a9c72cd8b5dea1b48fd24
|
|
| BLAKE2b-256 |
56b8cd885882adee3f452a7d55551579cdef91b6169c317e9ef668f25e927739
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5dcf855e816816eb4089848148eb77cf3c71597eb52257477f226b4803d1de45
|
|
| MD5 |
610e2e672de37eca8efbb59a83c709a9
|
|
| BLAKE2b-256 |
eae8fd1c7c5bb81f98fd4a8d1f35d93063a83a70196760a638bb91ca474f03df
|