Skip to main content

A comprehensive Python library for data structures and algorithms

Project description

Using the Python DSA Package

Installation

Install the package via pip:

pip install gsl_331

This package exposes a few classes to manage common data structures. The available classes are:

  • Queue
  • Stack
  • Graph
  • Node
  • LLNode
  • LinkedList
  • Priority_queue

Below are usage examples for each.

Queue

Use the Queue class to enqueue and dequeue items.

from gsl_331 import Queue

q = Queue()
q.enqueue("first")
q.enqueue("second")
print("Queue front:", q.top())  # prints "first"
print("Dequeued:", q.dequeue())
print("Queue is empty:", q.is_empty())

Stack

The Stack class provides LIFO operations.

from gsl_331 import Stack

s = Stack()
s.push("item1")
s.push("item2")
print("Stack top:", s.top())  # prints "item2"
print("Popped item:", s.pop())
print("Is stack empty:", s.is_empty())

Graph and Node

Create a graph, add vertices via random generation, and run BFS/DFS. Both the BFS and DFS operations return custom response objects. The BFS operation returns a BFS_response containing visited nodes, visit order, and parent relationships. Similarly, the DFS provides a DFS_response with entry and exit times, pending nodes, and a stack with the order of the processed nodes.

from gsl_331 import Graph, Node

# Create a directed graph with labels generated for n_node vertices.
g = Graph(n=5, directed=True)
g.generate_random_graph(n_node=5)

# Choose a starting node label (e.g., "a")
bfs_response = g.BFS("a")
print(bfs_response)  # prints visited nodes, order, and parent relationships given as a whole object of type bfs response

dfs_response = g.DFS("a")
print(dfs_response)  # prints visited nodes, entry/exit times, pending nodes, and processing stack given as a whole object of type bfs response

LLNode and LinkedList

Manage a linked list with LLNode and LinkedList classes.

from gsl_331 import LLNode, LinkedList

# Create the head LLNode and initialize the linked list.
head = LLNode(val=10, name="10")
ll = LinkedList(head)

# Insert values
ll.insertAtHead(5)
ll.insertAtTail(15)
print("Linked List:", ll)
print("Search for 15:", ll.search(15))
ll.delete(10)
print("After deleting 10:", ll)

Priority_queue

The Priority_queue supports heap operations with fast lookup by node name. Its responses include returning the top element and providing means to extract a specific node.

from gsl_331 import Priority_queue

# Initialize priority queue with a list of elements.
data = [4, 2, 6, 3]
pq = Priority_queue(data)

print("Priority Queue top:", pq.top())
pq.push(1, name="unique1")
print("Priority Queue after push:", pq)
extracted = pq.exctract_node("unique1")
print("Extracted node value:", extracted.val)

NOTE

that the priority queue contains a dictionary in pq.location_tracker that gives you the real time postions of objects from your pq and makes the extraction of any node O(logn) same as all other operations

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

gsl_331-1.0.1.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

gsl_331-1.0.1-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file gsl_331-1.0.1.tar.gz.

File metadata

  • Download URL: gsl_331-1.0.1.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for gsl_331-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a93f28ef5a60b8873fca439c7987dc2fe7b8ab6a2f436a94c38a3c78f017817a
MD5 aa3f96c5abf3ab551d5bc395b2621589
BLAKE2b-256 3c129efe09bb7546bd90492a580f0ce276dbd61cac036da209215d815d87ea87

See more details on using hashes here.

File details

Details for the file gsl_331-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: gsl_331-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for gsl_331-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b5e9b65820d0a2b990fbfd654ba9410382ea388363c0b4156f114750109c326d
MD5 154a1d6aabeddc8146127267d9d7f0ed
BLAKE2b-256 25ffe05bb2bb8433d3642061030f2e5124266233e1b9dba160651796ad44d34b

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