Metadata-Version: 2.3
Name: visualize_heapq
Version: 0.0.2
Summary: A package that visualizes heapq heaps
Project-URL: Homepage, https://github.com/zlliu246/visualize_heapq
Project-URL: Issues, https://github.com/zlliu246/visualize_heapq/issues
Author-email: Liu Zuo Lin <zlliu246@gmail.com>
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.8
Requires-Dist: print-btree
Description-Content-Type: text/markdown

Python's ```heapq``` can be confusing to beginners.

This package helps beginners better visualize ```heapq``` heaps better

# Quickstart

# Context
What is a heap?
- a heap is a binary tree
- a binary tree where every parent <= its children
- more specifically, this is known as a min heap 
- max heaps are heaps where every parent >= its children, but max heaps are not relevant here

Where ```heapq``` comes in
- ```heapq``` is a built-in Python module
- it provides us with functionality to use heaps (min heaps)
- these heaps can act like priority queues

```python
import heapq 

priority_queue: list[int] = [] # heaps are stored as lists in heapq

heapq.heappush(priority_queue, 5)
heapq.heappush(priority_queue, 10)
heapq.heappush(priority_queue, 2)
heapq.heappush(priority_queue, 6)
heapq.heappush(priority_queue, 1)

print(priority_queue) # [1, 2, 5, 10, 6]

print(heapq.heappop(priority_queue)) # 1
print(heapq.heappop(priority_queue)) # 2
print(heapq.heappop(priority_queue)) # 5
print(heapq.heappop(priority_queue)) # 6
print(heapq.heappop(priority_queue)) # 10
```

The weird thing about heaps in ```heapq```
- there is no Heap object.
- heaps are stored as normal lists in ```heapq```
- which can be confusing for a beginner

As such, this package aims to make things more intuitive by allowing users to print and visualize a ```heapq``` heap (which is actually a list) directly.

Documentation Link: https://docs.python.org/3/library/heapq.html
