Simple datastructures library with documentation.
Project description
Python DataStructures by slav_EEik
About the project
This is a simple datastructures and algorithms library. It is also published on PyPi.
You can see the automatically-generated documentation on GitHub Pages.
Here are all implemented datastructures:
-
Lists
- Singly Linked List
- Doubly Linked List
- Static Array
-
Linear Structures
- Stack
- Queue
- Deque
-
Heaps
- Min Heap
- Priority Queue
-
Trees and Tree Nodes
- Binary Tree
- Huffman Tree
- Balancing Tree
- Binary Search Tree
- Red Black Tree
- 2-3 Tree
- Segment Tree
- AVL Tree
- Trie
-
Graphs
- Adjacency List
- Adjacency Matrix
Note: trees.nodes.BinaryNode and trees.nodes.BalancedNode don't have their trees, so you can use them. It is not recommended to use all other nodes without their trees.
Here are all implemented algorithms:
-
Sorting Algorithms:
- Heap Sort
- Bubble Sort
- Quick Sort
- Merge Sort
- Insertion Sort
- Selection sort
-
String search algorithms:
- Brute Force Search
- Rabin-Karp Algorithm
-
Tree Algorithms:
- Tree balancing
- Huffman Coding
-
Graphs Algorithms:
- Dijkstra algorithm
- Bellman-Ford's algorithm
- A* Algorithm
- Breadth First Search
- Depth First Search
Modules
Installation
pip install --upgrade pip
pip install slav-eeik-datastructures
Examples
Here are some examples of using the library:
from datastructures.linear import Stack, SinglyLinkedList
s = Stack()
s.push("First item")
s.push("Second item")
print(s.pop()) # Second item
print(s.peek()) # First item
print(s.peek()) # First item
l = SinglyLinkedList()
l.build([1, 2, 3, 4, 5, 6, 7, 8])
print(l[4]) # 5
l.delete_at(4)
print(l) # 1 -> 2 -> 3 -> 4 -> 6 -> 7 -> 8
from datastructures.sorts import merge_sort, quicksort, heap_sort
arr = [5, 4, 6, 1, 7, 10, -5, 9]
print(merge_sort(arr)) # [-5, 1, 4, 5, 6, 7, 9, 10]
print(quicksort(arr, reverse=True)) # [10, 9, 7, 6, 5, 4, 1, -5]
print(arr) # [5, 4, 6, 1, 7, 10, -5, 9]
heap_sort(arr, inplace=True)
print(arr) # [-5, 1, 4, 5, 6, 7, 9, 10]
from datastructures.graphs import ListAdjacency as Graph
g = Graph(6, False)
g.add_edge(0, 1, 1)
g.add_edge(0, 2, 5)
g.add_edge(1, 3, 2)
g.add_edge(2, 3, 3)
distance, path = g.dijkstra(0, 3)
print(distance) # 3
print(path) # [0, 1, 3]
print(list(g.breadth_first_traversal(0))) # [0, 2, 1, 3]
from datastructures.trees.trees import AVLTree
t = AVLTree()
t.build([9, 3, 5, 2, 9, 8, 2, 3, 4, 1])
print(t) # BinaryTree(['Node(1)', 'Node(2)', 'Node(3)', 'Node(4)', 'Node(5)', 'Node(8)', 'Node(9)'])
t.insert(6)
print(t) # BinaryTree(['Node(1)', 'Node(2)', 'Node(3)', 'Node(4)', 'Node(5)', 'Node(6)', 'Node(8)', 'Node(9)'])
print(t.find_min()) # 1
print(list(t.root.preorder_traversal())) # [Node(5), Node(3), Node(2), Node(1), Node(4), Node(8), Node(6), Node(9)]
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contacts
For any inquiries, please reach out to the project maintainer on GitHub or Telegram.
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 slav_eeik_datastructures-1.1.tar.gz.
File metadata
- Download URL: slav_eeik_datastructures-1.1.tar.gz
- Upload date:
- Size: 27.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c49e3573962e0413ac6bea5688a7c9c8c27023cac3f9c86454019ee3dd78433c
|
|
| MD5 |
4f8b27d5cfb88585ac79028eb711e166
|
|
| BLAKE2b-256 |
b026abbcd520312a2d1dfdebf1ef6a12a0e61323ce796f818be74edda3dbfbfa
|
Provenance
The following attestation bundles were made for slav_eeik_datastructures-1.1.tar.gz:
Publisher:
publish.yml on zhukovrost/datastructures
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
slav_eeik_datastructures-1.1.tar.gz -
Subject digest:
c49e3573962e0413ac6bea5688a7c9c8c27023cac3f9c86454019ee3dd78433c - Sigstore transparency entry: 156341404
- Sigstore integration time:
-
Permalink:
zhukovrost/datastructures@a0c8fb34cdd3c71442a89d73aae5a1f36718aa06 -
Branch / Tag:
refs/tags/v1.1 - Owner: https://github.com/zhukovrost
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a0c8fb34cdd3c71442a89d73aae5a1f36718aa06 -
Trigger Event:
release
-
Statement type:
File details
Details for the file slav_eeik_datastructures-1.1-py3-none-any.whl.
File metadata
- Download URL: slav_eeik_datastructures-1.1-py3-none-any.whl
- Upload date:
- Size: 30.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20a9ec7307246b7ff93f0a07164fd898ea8196c6422f87ebaf9d58d9b689602a
|
|
| MD5 |
584e35566a4b049ddac73cd4a04646c1
|
|
| BLAKE2b-256 |
61ea9b037ebb1dd96518b6eb2159951f69311236c792e12284cb583cd862c101
|
Provenance
The following attestation bundles were made for slav_eeik_datastructures-1.1-py3-none-any.whl:
Publisher:
publish.yml on zhukovrost/datastructures
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
slav_eeik_datastructures-1.1-py3-none-any.whl -
Subject digest:
20a9ec7307246b7ff93f0a07164fd898ea8196c6422f87ebaf9d58d9b689602a - Sigstore transparency entry: 156341406
- Sigstore integration time:
-
Permalink:
zhukovrost/datastructures@a0c8fb34cdd3c71442a89d73aae5a1f36718aa06 -
Branch / Tag:
refs/tags/v1.1 - Owner: https://github.com/zhukovrost
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@a0c8fb34cdd3c71442a89d73aae5a1f36718aa06 -
Trigger Event:
release
-
Statement type: