Skip to main content

The powerful package designed for sorting.

Project description

sorting-algorithms🎢

Theory analysis and code implementation of common array sorting algorithms.

📍 start from galley

First, You need to click the fork button to create your own sub repository, or use the following command to synchronize the repository to the local folder:

git clone https://github.com/linjing-lab/sorting-algorithms

Second, I have put different implemented versions of various sorting algorithms in the galley folder, everyone can import it with the underlying command:

import galley as ge

For example, If I use the bubble sorting algorithm to sort a real data in reverse, use the following commands:

import random 
data = [random.randint(0, 100) for _ in range(10000)]
ge.bubble.flag(data, reverse=True)
print(data)

Lastly, many algorithms are in-place sorting, and a few are out-place, you should pay attention to it during the study, so that you can distinguish between print(data) and print(method). I mainly use if... else... to implement the reverse order of sorting algorithms in gallery and the partition of some algorithms.

📊 sorting complexity

Algorithm Time Complexity Space Complexity
--- Best Average Worst Worst
Quicksort $\Omega(n \log(n))$ $\Theta(n \log(n))$ $O(n^2)$ $O(\log(n))$
Mergesort $\Omega(n \log(n))$ $\Theta(n \log(n))$ $O(n \log(n))$ $O(n)$
Timsort $\Omega(n)$ $\Theta(n \log(n))$ $O(n \log(n))$ $O(n)$
Heapsort $\Omega(n \log(n))$ $\Theta(n \log(n))$ $O(n \log(n))$ $O(1)$
Bubble Sort $\Omega(n)$ $\Theta(n^2)$ $O(n^2)$ $O(1)$
Insertion Sort $\Omega(n)$ $\Theta(n^2)$ $O(n^2)$ $O(1)$
Selection Sort $\Omega(n^2)$ $\Theta(n^2)$ $O(n^2)$ $O(1)$
Tree Sort $\Omega(n \log(n))$ $\Theta(n \log(n))$ $O(n^2)$ $O(n)$
Shell Sort $\Omega(n \log (n))$ $\Theta(n(\log (n))^2)$ $O(n(\log (n))^2)$ $O(1)$
Bucket Sort $\Omega(n + k)$ $\Theta(n + k)$ $O(n^2)$ $O(n)$
Radix Sort $\Omega(nk)$ $\Theta(nk)$ $O(nk)$ $O(n+k)$
Counting Sort $\Omega(n + k)$ $\Theta(n + k)$ $O(n + k)$ $O(k)$
Cubesort $\Omega(n)$ $\Theta(n \log(n))$ $O(n \log(n))$ $O(n)$

🙋 test description

I test the performance of the sorting algorithm after adding the keyword sorting in the test_key file (The utils file stores the most core function for keyword sorting), test the time accumulation of the sorting algorithm with respect to the large data set in the test_time file, and test whether the reverse parameter of the sorting algorithms is designed correctly in the test_reverse file, including the robustness of these.

The design of reverse sorting of all methods is completely correct, and the design of keyword sorting is feasible, which is consistent with the usage of sorted parameter officially released by Python.

The example of keyword sorting are underlying:

data = [('Alex', 100, 90, 98, 95), ('Jack', 97, 88, 98, 92), ('Peter', 92, 95, 92, 96), ('Li', 97, 89, 98, 92)]
insertion_sort(data, key=lambda x: (x[1], x[2]), reverse=False)
# sorted(data, key=lambda x: (x[1], x[2]), reverse=False)
print(data)

'''
reverse=False: 
[('Peter', 92, 95, 92, 96), ('Jack', 97, 88, 98, 92), ('Li', 97, 89, 98, 92), ('Alex', 100, 90, 98, 95)]

reverse=True: 
[('Alex', 100, 90, 98, 95), ('Li', 97, 89, 98, 92), ('Jack', 97, 88, 98, 92), ('Peter', 92, 95, 92, 96)]
'''

you can see more 5 methods in keyword_sorting file.

🎒 pip install

As you can see, I create a core function to drive keyword sorting just by opening up an array with the size of k (k = nums of keyword), and the type of sorting implemented by Python officially released is Timsort, which is more complicated than the other algorithms in my released packages in the future.

!pip install sortingx # in jupyter
pip install sortingx # in cmd

sortingx can do whatever list.sort() do, and support more methods and more data types.

explain:

  • sortingx-1.1.0 is the first version aligned with the list.sort() usage method.
  • sortingx-1.1.1 is the first stable version accelerated with typing_extensions.
  • sortingx-1.1.2 is the first stable version that has a return value and extends the iterable data types.
  • sortingx-1.1.3 is the stable version that complete the typing of local variables and align with sorted() usage method.

LICENSE

Apache 2.0

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

sortingx-1.1.3.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

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

sortingx-1.1.3-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file sortingx-1.1.3.tar.gz.

File metadata

  • Download URL: sortingx-1.1.3.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for sortingx-1.1.3.tar.gz
Algorithm Hash digest
SHA256 b6b25a4cef72af4d213f61e99e797fcc9700168c188f1edc1ef6e5e5cbd57516
MD5 73a57c3084040f4ffbc7045d4bd1ca42
BLAKE2b-256 920bb024908545d58c6e79b788535f540a7ae5c40d24601518bb12d9255492d3

See more details on using hashes here.

File details

Details for the file sortingx-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: sortingx-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12

File hashes

Hashes for sortingx-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 78ab84abd35ccebcebed8dfaae0c78dcc50b4fcc228dee708f93d79c4e171608
MD5 07f7f94891d1ff827eaacb7ea53aafa3
BLAKE2b-256 9729eded53677b28854448121479553f2f0a764f8dce423f1f62a46b154e60fa

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