Skip to main content

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

Project Structure - github.com/zhukovrost/datastructures/blob/master/datastructures.svg

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

slav_eeik_datastructures-1.1.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

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

slav_eeik_datastructures-1.1-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

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

Hashes for slav_eeik_datastructures-1.1.tar.gz
Algorithm Hash digest
SHA256 c49e3573962e0413ac6bea5688a7c9c8c27023cac3f9c86454019ee3dd78433c
MD5 4f8b27d5cfb88585ac79028eb711e166
BLAKE2b-256 b026abbcd520312a2d1dfdebf1ef6a12a0e61323ce796f818be74edda3dbfbfa

See more details on using hashes here.

Provenance

The following attestation bundles were made for slav_eeik_datastructures-1.1.tar.gz:

Publisher: publish.yml on zhukovrost/datastructures

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slav_eeik_datastructures-1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for slav_eeik_datastructures-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 20a9ec7307246b7ff93f0a07164fd898ea8196c6422f87ebaf9d58d9b689602a
MD5 584e35566a4b049ddac73cd4a04646c1
BLAKE2b-256 61ea9b037ebb1dd96518b6eb2159951f69311236c792e12284cb583cd862c101

See more details on using hashes here.

Provenance

The following attestation bundles were made for slav_eeik_datastructures-1.1-py3-none-any.whl:

Publisher: publish.yml on zhukovrost/datastructures

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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