Nothing Special   »   [go: up one dir, main page]

namastey-min-heap

1.0.0 • Public • Published

namastey-min-heap

Brief Description

namastey-min-heap is a JavaScript package that implements the Min-Heap data structure. It provides essential methods for inserting, removing, and accessing elements while maintaining the heap property.

Features

  • insert(value): Inserts a new value into the heap while maintaining the heap property.
  • extractMin(): Removes and returns the minimum value (the root) from the heap.
  • heapifyUp(index): Ensures the heap property is maintained after an insertion.
  • heapifyDown(index): Ensures the heap property is maintained after extraction.
  • peek(): Returns the minimum value without removing it from the heap.
  • size(): Returns the number of elements in the heap.
  • isEmpty(): Returns true if the heap is empty, false otherwise.

Installation

To install the namastey-min-heap package globally, run the following command:

npm install -g namastey-min-heap

Examples

const MinHeap = require('namastey-min-heap');

const heap = new MinHeap();
heap.insert(10);
heap.insert(5);
heap.insert(30);
heap.insert(2);

console.log('Min element:', heap.peek()); // Output: Min element: 2
console.log('Extracted min:', heap.extractMin()); // Output: Extracted min: 2
console.log('Min element:', heap.peek()); // Output: Min element: 5
console.log('Heap size:', heap.size()); // Output: Heap size: 3

Package Sidebar

Install

npm i namastey-min-heap

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

4.74 kB

Total Files

3

Last publish

Collaborators

  • namasteyduniya