A collection of sorting algorithms in Python
Project description
Sortify: A Python Package for Sorting Algorithms
Sortify is a Python package that includes a variety of sorting algorithms, implemented for educational and practical use. The package makes it easy to experiment with different sorting algorithms and compare their performances.
Included Algorithms:
- Bubble Sort
- Insertion Sort
- Selection Sort
- Merge Sort
- Quick Sort
- Heap Sort
- Counting Sort
- Radix Sort
- Bucket Sort
- TimSort (Built-in in Python)
- Shell Sort
- Cocktail Shaker Sort
- Pigeonhole Sort
- Gnome Sort
- Bitonic Sort
- Pancake Sort
- Flashsort
Each algorithm is implemented as a separate function and can be used to sort a list of elements.
Installation
To install sortify, use the following pip command:
pip install sortify
Usage
Once the package is installed, you can use the sorting algorithms like this:
from sortify import bubble_sort, insertion_sort, selection_sort
Sample list to be sorted
arr = [64, 34, 25, 12, 22, 11, 90]
# Use any sorting algorithm
sorted_arr_bubble = bubble_sort(arr)
print("Bubble Sort:", sorted_arr_bubble)
sorted_arr_insertion = insertion_sort(arr)
print("Insertion Sort:", sorted_arr_insertion)
sorted_arr_selection = selection_sort(arr)
print("Selection Sort:", sorted_arr_selection)
You can replace bubble_sort, insertion_sort, and selection_sort with any of the other sorting algorithms available in sortify.
Available Sorting Algorithms
-
Bubble Sort: A simple comparison-based algorithm that repeatedly steps through the list, compares adjacent elements, and swaps them if needed. Insertion Sort: Sorts the list by building a sorted portion one item at a time.
-
Selection Sort: Repeatedly selects the smallest element from the unsorted part and swaps it to the sorted portion.
-
Merge Sort: A divide-and-conquer algorithm that splits the list and merges the sorted sublists.
-
Quick Sort: A divide-and-conquer algorithm that picks a pivot and sorts elements around it.
-
Heap Sort: Uses a binary heap data structure to sort the elements. Counting Sort: A non-comparison-based sorting algorithm that counts occurrences of each element.
-
Radix Sort: Sorts elements by processing their digits or bits. Bucket Sort: Distributes the elements into different buckets, sorts each bucket, and combines them.
-
TimSort: Python's built-in sorting algorithm (used internally by the sorted() function).
-
Shell Sort: An improvement of insertion sort, allowing the exchange of elements far apart.
-
Cocktail Shaker Sort: A bidirectional variation of bubble sort.
-
Pigeonhole Sort: A counting sort algorithm based on the pigeonhole principle.
-
Gnome Sort: A comparison-based algorithm similar to insertion sort.
-
Bitonic Sort: A parallel algorithm that sorts by dividing the list into bitonic sequences.
-
Pancake Sort: A sorting algorithm where the only operation allowed is flipping subarrays.
-
Flashsort: A distribution-based sorting algorithm that performs faster for uniformly distributed data.
from sortify import flash_sort
arr = [3, 1, 2, 5, 4]
sorted_arr_flash = flash_sort(arr)
print("Flash Sort:", sorted_arr_flash)
Time and Space Complexity
Each algorithm has its own time and space complexity. Some common examples include:
- Bubble Sort: Worst case time complexity is O(n²) and space complexity is O(1).
- Quick Sort: Average case time complexity is O(n log n) and worst-case is O(n²).
For each algorithm, you can refer to the individual functions for a detailed explanation of time and space complexities.
Contributers
- Lukas Van der Spiegel
License
This project is licensed under the MIT License - see the LICENSE file for details. Wich means everyone can use this for free, without any conditions.
I made it originaly from code I've been writing for my own educational purpose. I made it quickly an acceable package for everyone. Why wasting code that becoming dusty on my pc or github profile?😜
Yes, I used AI to write & code faster. Why not? 🙃
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 sortifly-0.1.tar.gz.
File metadata
- Download URL: sortifly-0.1.tar.gz
- Upload date:
- Size: 12.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d08232e770f9f7dc1853e174509e1ad597632bd8f8c7e3a01e5a7261fe0049b7
|
|
| MD5 |
5be3094a9d9c14a2171e26a49a7fbecc
|
|
| BLAKE2b-256 |
7ab85b5f72aaac47aeeacb34017bac79026432ec33f3a582fcd645f160690331
|
File details
Details for the file sortifly-0.1-py3-none-any.whl.
File metadata
- Download URL: sortifly-0.1-py3-none-any.whl
- Upload date:
- Size: 21.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a27d294fff38ad2cc094f37fcec341fcafb5e442dcceadccb62f93a068cdf11
|
|
| MD5 |
29a177f363bbbc57ed5aeba0f5acf0d6
|
|
| BLAKE2b-256 |
47827e5496df01bc34e758ec2686f7b51fae7e3f4e07ddb867dd1acebc5bf15e
|