A Python library that helps developers implement data structures & algorithms easily.
Project description
📌 easydsi 2.0.1
🚀 easydsi is a Python library designed to simplify Data Structures and Algorithms (DSA), allowing users to focus on coding without worrying about implementation details.
📂 Features
- Heap
MinHeap()MaxHeap()
- Queue
- Stack
- Tree
BinaryTree()BinarySearchTree()
📦 Heap
🛠️ Initialization
MinHeap()orMinHeap([list])- Creates a MinHeap.MaxHeap()orMaxHeap([list])- Creates a MaxHeap.Heap(data=None, max_heap=False)- Creates a generic heap that can be a MinHeap or MaxHeap.
This module provides utility functions for performing various operations on a Heap object, including retrieving statistics, sorting, merging, and clearing the heap.
📌 Methods and Descriptions
-
heapify_list(data, max_heap=False)
Converts a list into a MinHeap or MaxHeap. -
merge_heaps(heap1, heap2, max_heap=False)
Merges two heaps into a new MinHeap or MaxHeap. -
is_heap_sorted(heap, max_heap=False)
Checks if a given heap is sorted. -
get_top_n(heap, n=1)
Retrieves the topnelements from a MinHeap or MaxHeap. -
heap_sort(data, descending=False)
Sorts a list using Heap Sort. -
contains(heap, element)
Checks if an element exists in the heap. -
clear_heap(heap)
Removes all elements from the heap. -
size(heap)
Returns the number of elements in the heap. -
sum_heap(heap)
Computes the sum of all elements in the heap. -
max_in_heap(heap)
Returns the maximum element in the heap. -
min_in_heap(heap)
Returns the minimum element in the heap.
📦 Stack
🛠️ Initialization
Stack()- Creates a stack.
📌 Methods and Descriptions
-
reverse_stack()
Reverses the order of elements in a stack. -
sort_stack()
Sorts a stack in ascending order. -
duplicate_stack()
Creates a duplicate of a stack without modifying the original. -
sum_stack()
Computes the sum of all elements in a stack. -
max_in_stack()
Finds the maximum value in a stack. -
min_in_stack()
Finds the minimum value in a stack. -
merge_stacks()
Merges two stacks into one, maintaining order. -
is_balanced()
Checks if a given expression has balanced parentheses. -
remove_duplicates()
Removes duplicate elements from a stack while maintaining order.
📦 Queue
🛠️ Initialization
Queue()orQueue([list])- Creates a queue.
This module provides utility functions for performing various operations on a Queue object, including retrieving statistics, sorting, reversing, and clearing the queue.
📌 Methods and Descriptions
-
get_max(queue, visualize=False)
Returns the maximum numerical value in the queue. -
get_min(queue, visualize=False)
Returns the minimum numerical value in the queue. -
get_sum(queue, visualize=False)
Computes the sum of all numerical values in the queue. -
get_avg(queue, visualize=False)
Computes the average of all numerical elements in the queue. -
reverse_queue(queue, inplace=False, visualize=False)
Reverses the order of elements in the queue. -
sort_queue(queue, descending=False, inplace=False, visualize=False)
Sorts the queue in ascending order by default. Usedescending=Truefor descending order. -
clear_queue(queue, visualize=False)
Removes all elements from the queue. -
contains(queue, item, visualize=False)
Checks if a specific item exists in the queue.
🌳 Tree
🛠️ Initialization
BinaryTree()orBinaryTree(root_value)- Creates a Binary Tree with an optional root value.BinarySearchTree()orBinarySearchTree(root_value)- Creates a Binary Search Tree with an optional root value.
This module provides utility functions for performing various operations on a Tree object, including retrieving statistics, searching, traversing, and modifying the tree.
📌 Methods and Descriptions
-
contains(tree, value)
Checks if a tree contains a specific value. -
sum_tree(tree)
Returns the sum of all elements in the tree. -
max_in_tree(tree)
Returns the maximum value in the tree. -
min_in_tree(tree)
Returns the minimum value in the tree. -
count_nodes(tree)
Returns the total number of nodes in the tree. -
count_leaves(tree)
Returns the number of leaf nodes in the tree. -
get_height(tree)
Returns the height of the tree. -
inorder(tree)
Returns the in-order traversal of the tree (Left, Root, Right). -
preorder(tree)
Returns the pre-order traversal of the tree (Root, Left, Right). -
postorder(tree)
Returns the post-order traversal of the tree (Left, Right, Root). -
levelorder(tree)
Returns the level-order traversal of the tree (Breadth-First Traversal).
📥 Installation
Run the following command to install:
pip install easydsi
🚀 Quick Start
Import the library into your project:
from easydsi.tree.binary_tree import BinaryTree, BinarySearchTree
from easydsi.tree.tree_utils import max_in_tree, sum_tree
🎯 Working with Tree
🔹 Initialize a tree
bt = BinaryTree([3, 5, 1, 7, 2])
print(bt)
Output:
__3
/ \
5 1
/ \
7 2
🔹 Get maximum value in Binary Search Tree
bst = BinarySearchTree([10, 5, 15, 2, 7])
print(max_in_tree(bst))
Output:
15
🔹 Get all elements after adding 6
bt.add(6)
print(bt.get_elements())
Output:
[3, 5, 1, 7, 2, 6]
📊 Statistics
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file easydsi-2.0.1.tar.gz.
File metadata
- Download URL: easydsi-2.0.1.tar.gz
- Upload date:
- Size: 17.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bb9b1eaa22d1a874bac879dbe16195a0aff42b8e0e098449230519714f384a0
|
|
| MD5 |
ee6f6ea964d27140f8b0ad1075703d1b
|
|
| BLAKE2b-256 |
2adc21e61206a46b3ca1aee0b300f65adde610cc08442e0a1f3daa206ebe5932
|
File details
Details for the file easydsi-2.0.1-py3-none-any.whl.
File metadata
- Download URL: easydsi-2.0.1-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b244e36f6d44f88c2c5205b7875f260383a7b517e5c05228725c6cd513c9b218
|
|
| MD5 |
b7bdb94b0f2620fd6f17bf9ce266b6a4
|
|
| BLAKE2b-256 |
d2b5001b09f303927be0c6bb09e71a388675774775d99e5db9975d8c14b14931
|