Skip to main content

Max binary heap module, similar to heapq

Project description

maxheapq

This project implements heap data structure, specifically max binary heap described on wikipedia

The purpose is to implement my own version and compare with already existing heapq, by default heapq implements min heap but we implement max heap here, hence the name maxheapq

in max heap, the element with highest priority or value will be at the first index of the underhood array, which can be seen as a complete binary tree, where i is index of Parent, with indices 2 * i+ 1, 2 * i+ 2 as children of the parent

Documentation

https://test.pypi.org/project/maxheapq-snow

install and use package

install the package using below command to use locally on your machine

python3 -m pip install --index-url https://test.pypi.org/simple/ --no-deps maxheapq-snow

Usage

Some basic operations:

def max_heap.create_heap()
  - create an empty max heap 

def size(self) -> int:
  - returns size or number of keys in the max heap

def is_empty(self) -> bool:
  - returns True if no keys else False

def find_max(self) -> key:
  - returns key with maximum value

def insert(self, k: key):
 -  inserts new key k in the heap.

def delete_max(self):
    - deletes max key or key at index 0 in the max heap array.

def replace(self, k: key):
    - replace the first key or max key with the new key k .


def increase_key(self, old_key: key, new_key: key):
    - search for the old key indices and then update with new key value
      if new_key > old_key


def decrease_key(self, old_key: key, new_key: key):
   - search for the old key indices and then update with new key value
     if new_key < old_key


def delete(self, del_key: key):
   - deletes keys that matches del_key


def make_heap(array: list[int]) -> MaxHeap:
  - creates max heap from list of integers with time
    complexity O(n) according to Floyd's algorithm.

def merge(heap1: MaxHeap, heap2: MaxHeap) -> MaxHeap:
  - returns a new max heap created by merging heap1 and heap2

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

maxheapq_snow-0.0.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

maxheapq_snow-0.0.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file maxheapq_snow-0.0.1.tar.gz.

File metadata

  • Download URL: maxheapq_snow-0.0.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.12

File hashes

Hashes for maxheapq_snow-0.0.1.tar.gz
Algorithm Hash digest
SHA256 41bd15403c974bdffe8bcb0e7a7a025d805f20e99d06ae56c6f51818721e1bd9
MD5 a5156ddecf23ac245f14b2cebc12b758
BLAKE2b-256 bc1aa9f14d4d59d21dc9b0b920f9ecd6570f6a819ca0074e801569c2971ed4e7

See more details on using hashes here.

File details

Details for the file maxheapq_snow-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: maxheapq_snow-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.12

File hashes

Hashes for maxheapq_snow-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 917d46b9722a84b6ba22f86435d656957661e15ab19d09da5e56194038a98dd5
MD5 263f66ecea313ca8fa1454e80fdc39e5
BLAKE2b-256 bdae9476e2dac7eacb05a78602a62e9fb155c885919ccb744e056d3e19ec5029

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