Skip to main content

Ready to use data structures

Project description

Data Structure in Python

This repo contains python implementation of data structures. The following data structures are available:

  1. Tree
  2. Heap

Installation

To install from pypi

pip install py-ds

To install from source

git clone https://github.com/nitinkatyal1314/data-structures.git
python setup.py install

Examples

The examples are available in the examples directory and can be used as a playground or a starting point.

Below are some snippets :

  1. Tree creation and traversal (BFS)
from pyds.tree import Tree


# attributes of the node in the tree
_children = "children"
_name = "name"
_data = "data"

# dictionary representation of tree
tree_data = {
  _name: "R_",
  _data: {},
  _children: [
    {
      _name: "L1",
      _data: {},
      _children: []
    },
    {
      _name: "R1",
      _data: {},
      _children: []
    }
  ]
}


# instantiate the tree
tree = Tree()

# parse the tree
root = tree.parse(tree_data)

# walk callback method, executed for every node that is traversed
def print_nodename(node):
    print(node.name)

# walk the tree (BFS)
# the print_nodename method is passed as a callback while walking
tree.walk(print_nodename, strategy="breadth-first")
  1. Heap (Insertion and Deletion)
from pyds.heap import HeapType, Heap

# max heap
heap = Heap(heap_type=HeapType.MAX)

heap.add_node(1)
heap.add_node(2)
heap.add_node(3)
heap.add_node(4)
heap.add_node(5)

# heap print node callback
def print_node(el):
  print("Node : ", el)


# walk the heap
heap.walk(print_node)

# delete the node from the heap
heap.delete_node()

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

py-ds-0.1.1.tar.gz (9.5 kB view details)

Uploaded Source

Built Distributions

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

py_ds-0.1.1-py3.9.egg (23.6 kB view details)

Uploaded Egg

py_ds-0.1.1-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file py-ds-0.1.1.tar.gz.

File metadata

  • Download URL: py-ds-0.1.1.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for py-ds-0.1.1.tar.gz
Algorithm Hash digest
SHA256 28094d81c525e2a8d7530ae98d0690ff3e84d180ca0a0eb6eb7598acd02243da
MD5 f560d55d8c636ed1871ccdb428e2abb8
BLAKE2b-256 3bfa2b9967f608edf0e34fd00a02c5801f3c1b5642da7ecb07834d4d772d1193

See more details on using hashes here.

File details

Details for the file py_ds-0.1.1-py3.9.egg.

File metadata

  • Download URL: py_ds-0.1.1-py3.9.egg
  • Upload date:
  • Size: 23.6 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for py_ds-0.1.1-py3.9.egg
Algorithm Hash digest
SHA256 d580e71d9d22a894a1201b04538f429e8670472fec4bebc74c2254c3bfca0f1f
MD5 130542d4dab09479faf0241820b2e538
BLAKE2b-256 64d1c9abbaec9955f32206cc64e2086ad2b5e8fa816fe32bbdd535fe2cd5440d

See more details on using hashes here.

File details

Details for the file py_ds-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: py_ds-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for py_ds-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 50188e2f8e40bade59deacca9704a249e95d2a294acaf84bf4ea532f2614536a
MD5 0a52733e702de3d24830100886b54e98
BLAKE2b-256 58956bfccfc34c50edc1c33f53ab46495a2e5d8a093b33302b9775c923080697

See more details on using hashes here.

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