Skip to main content

A Python package for data structures and algorithms

Project description

Algods

Algods is a Python package designed to help programmers save time by providing efficient implementations of common algorithms and data structures.

This module includes well-known search algorithms and is ideal for those looking to quickly implement these algorithms in their projects.

Contents

  • Algorithms

    • Linear Search
    • Binary Search
    • Jump Search
    • Interpolation Search

Installation

Installing Algods is straightforward. Simply open a terminal and run:

pip install algods

Compatibility

Algods is compatible with Python 3.8 and above.

Documentation:

Enough talk. Let's come to the main part. Documentation. Here is a detailed breakdown of all the functions.

linear_search(arr: List[int], target: int) -> Union[int, None]

This function takes a list of integers (arr), which can be either unsorted or sorted, and a target integer (target) as inputs. It iterates through each element in the list, comparing it to the target. If a match is found, the function returns the index of the matching element. If the target is not found in the list, the function returns None.

binary_search(arr: List[int], target: int) -> Union[int, None]

This function takes a sorted list of integers (arr) and a target integer (target) as inputs. It repeatedly divides the list in half and compares the middle element to the target until a match is found or the list cannot be divided further. If a match is found, the function returns the index of the matching element. If the target is not found, the function returns None.

jump_search(arr: List[int], target: int) -> Union[int, None]

This function performs a jump search on a sorted list of integers (arr) to find a target integer (target). The jump search algorithm divides the list into blocks of fixed size and performs a linear search within the identified block where the target might be located. The steps are as follows:

  • Determine Block Size: Calculate the block size as the square root of the length of the list.
  • Jump Through Blocks: Start from the beginning of the list and jump ahead by the block size until you reach a block where the target could be located.
  • Linear Search in Block: Once the correct block is identified, perform a linear search within that block to find the exact position of the target.

If the target is found, the function returns the index of the target. If the target is not present in the list, the function returns None.

interpolation_search(arr: List[int], target: int) -> Union[int, None]

This function performs an interpolation search on a sorted list of integers (arr) to find a target integer (target). The interpolation search algorithm estimates the position of the target based on the values in the list, assuming a uniform distribution. The steps are as follows:

  • Estimate Position: The algorithm calculates a probable position for the target using the formula:
                (target - arr[low])×(high - low)
    pos = low+ _________________________________
                      arr[high] - arr[low]

where low and high are the indices representing the current search range in the list.

  • Check Estimated Position: The algorithm compares the value at the estimated position with the target:
    • If it matches, the function returns the index of the target.
    • If the target is less than the value at the estimated position, the search continues in the lower subarray.
    • If the target is greater, the search continues in the upper subarray.
  • Repeat or Return: The process is repeated, adjusting the search range based on the estimated position, until the target is found or the search range is exhausted.

If the target is found, the function returns its index. If the target is not present in the list, the function returns None.

Usage

Here, I will show you how to import the algorithms and use them.

from algods.search import binary_search

array = [1, 3, 5, 6]
target = 6

result = binary_search(array, target)
print(result)

Contributing

We welcome contributions to Algods! If you'd like to contribute, please refer to our CONTRIBUTING.md for guidelines on how to get started.

Your contributions help us improve and expand the functionality of Algods.

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

algods-0.2.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

algods-0.2.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file algods-0.2.0.tar.gz.

File metadata

  • Download URL: algods-0.2.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for algods-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e9a38a920729bec820c2688355f0eb4781d90c6884a8c9d0b8d18569d0702645
MD5 77b7b3aea4c70c9441781f84375d730d
BLAKE2b-256 5fbd49af46a528959e17e6da4378ef1e7052dc72bf4a430d512216f5f13c5db7

See more details on using hashes here.

File details

Details for the file algods-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: algods-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for algods-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b931776f67a78aff0c569385755e96532ac204a1e47aa14226657c6e610a33f9
MD5 40eae5cb0c70affe3e473bb0b045019f
BLAKE2b-256 d7f2f4090b59b8f12617494a577aea9ecc142f9ddd300d155fdc648e7c15d62c

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