Skip to main content

Almost all Searching and Sorting Algorithms for Python 3.x

Project description

searchsort

A Python Package that contains almost all the Searching and Sorting Algorithms

It is also available in GitHub

Installation

If there are 2 or more versions of Python installed in your system (which mostly occurs in UNIX/Linux systems) then please run any one of the commands in the BASH Shell :-

$ pip3 install searchsort
$ python3 -m pip install searchsort

If there is only Python 3.x installed in your system like in Windows systems then please run any one of commands in the Command Prompt :-

pip install searchsort
python -m pip install searchsort

Quick Guide

Please Read till the End

  • Import the Package using import searchsort as ss.
  • ss.AvailableSearchingAlgorithms() will show you the available Searching algorithms.
  • ss.AvailableSortingAlgorithms() will show you the available Sorting algorithms.
  • All the Functions have their Asymptotic Analysis in their docstrings. If you wish; you may take a note of it.

A Searching Implementation

from random import shuffle
import searchsort as ss

L1 = [i for i in range(1, 51)]
element = 20

# Shuffling the List
shuffle(L1)

index = ss.LinearSearch(L1, element)

if index:
  print(f"{element} found at :", index)
else:
  print(f"{element} not found")

Note :-

  • Some of the Algorithms require a sorted array. It is mentioned in the docstring of the functions so please read them carefully.
  • All the Algorithms return the index of the First Occurrence of the element.
  • If Element is Not Present, False is Returned.

A Sorting Implementation

from random import shuffle
import searchsort as ss

L1 = [i for i in range(1, 51)]

# Shuffling the List
shuffle(L1)
print("List Before Sorting :", L1)

Result = ss.BubbleSort(L1)
print("List After Sorting :", Result)

Note :-

  • Some of the Algorithms perform an in-place sorting, which means the structure of the Original List will be changed.
  • All the Algorithms return the sorted array, so assigning statements are preferred.

'IsSorted' Function Implementation

Besides Searching an Element in an Array and Sorting Arrays, the Package also contains an 'IsSorted' Function that Returns True if an Array is SORTED in either direction; False If NOT.

from random import shuffle
from searchsort import IsSorted

L1 = [i for i in range(1, 51)]
print("Is the List Sorted Now? ", IsSorted(L1))

# Shuffling the List
shuffle(L1)

print("Is the List Sorted Now? ", IsSorted(L1))

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

searchsort-0.1.6.tar.gz (8.9 kB view hashes)

Uploaded Source

Built Distribution

searchsort-0.1.6-py3-none-any.whl (8.7 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