Skip to main content

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.

Metadata

Release files for algods 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for algods 0.2.0
File Size Uploaded Provenance
algods-0.2.0.tar.gz 4.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for algods 0.2.0
File Interpreter ABI Platform
algods-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.2 kB

Release files / algods-0.2.0.tar.gz

Download URL algods-0.2.0.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e9a38a920729bec820c2688355f0eb4781d90c6884a8c9d0b8d18569d0702645
BLAKE2b-256 checksum
How to use checksums
5fbd49af46a528959e17e6da4378ef1e7052dc72bf4a430d512216f5f13c5db7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Release files / algods-0.2.0-py3-none-any.whl

Download URL algods-0.2.0-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b931776f67a78aff0c569385755e96532ac204a1e47aa14226657c6e610a33f9
BLAKE2b-256 checksum
How to use checksums
d7f2f4090b59b8f12617494a577aea9ecc142f9ddd300d155fdc648e7c15d62c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Security for algods 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page