Generates visually appealing representations of data structures.
Project description
This Python library provides functions for visualizing various data structures, including linked lists, queue, stack, and more. It utilizes Matplotlib for creating interactive and informative visualizations.
This library was developed for the Data Structures and Algorithms course at King Mongkut's Institute of Technology Ladkrabang (KMITL) to enhance student understanding of these fundamental concepts.
Installation
Install using pip
pip install visualdsa
Usage
Stack
Context
- A stack is a linear data structure that follows the Last-In, First-Out (LIFO) principle.
- Imagine a stack of plates – you can only add or remove plates from the top of the stack.
Sample stack class
class ArrayStack:
def __init__(self):
self._data = []
def __len__(self):
return len(self._data)
# ... (class methods)
Visualization
import visualdsa as vd
# Sample stack data
my_stack = ArrayStack()
my_stack._data = [3, 2, 1]
# Visualize the stack
vd.showStack(my_stack)
Queue
Context
- A circular queue is a linear data structure that follows the First-In, First-Out (FIFO) principle, like a regular queue, but with a circular arrangement.
- The last element of the queue is logically connected to the first element, creating a circular structure. This efficient use of space by avoiding wasted memory at the beginning of the array.
- There are 2 pointers, front and rear, track the positions of the first and last elements in the queue, respectively.
Sample circular queue class
class ArrayQueue:
def __init__(self):
self._data = [None] * 5 # A list to store the queue elements with capacity of 5
self._front = 0 # The index of the front of the queue
self._rear = 0 # he index of the rear of the queue
def __len__(self):
return len(self._data)
# ... (class methods)
Visualization
import visualdsa as vd
# Sample queue data
my_queue = ArrayQueue()
my_queue._data = [3, 2, 1, None, None]
my_queue._front = 0
my_queue._rear = 2
# Visualize the queue
vd.showCircularQueue(my_queue)
Singly Linked List
Context
- A singly linked list is a linear data structure where each element (node) points to the next element in the sequence.
Sample singly linked list class
class SinglyLinkedListBase:
def __init__(self):
self._count = 0 # The number of nodes in the list
self._head = None # A reference to the first node of the list
class DataNode:
def __init__(self, name, next):
self._name = name # The value stored within the node
self._next = next # A reference to the next node in the list (None if it's the last node)
class SinglyLinkedList(SinglyLinkedListBase):
# self._count = 0 Inherited from SinglyLinkedListBase class
# self._head = None Inherited from SinglyLinkedListBase class
# ... (class methods)
pass # can delete after add class methods
Visualization
import visualdsa as vd
# Sample linked list data
my_list = SinglyLinkedList()
my_node1 = DataNode("John", None)
my_node2 = DataNode("Adam", my_node1)
my_list._head = my_node2
my_list._count += 2
# Visualize the linked list
vd.showSinglyLinkedList(my_list)
Change Log
0.0.1 (21/01/2025)
- First Release
0.0.2 (21/01/2025)
- Debug module
0.0.3 (21/01/2025)
- Clear tester
0.0.4 (22/01/2025)
- Corrected the date in previous changelog
- Updated README.txt with improved documentation, including installation and usage
- Refactored function names to accurately reflect the data structure
showQueue()toshowCircularQueue()showLinkedList()toshowSinglyLinkedList()
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
visualdsa-0.0.4.tar.gz
(4.9 kB
view details)
File details
Details for the file visualdsa-0.0.4.tar.gz.
File metadata
- Download URL: visualdsa-0.0.4.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
338e9c0899dc93481886b702cc0f6310b1f71b882387cef1eccd4b88d7707cde
|
|
| MD5 |
dfc76fc16a7e951c81b020979be6641d
|
|
| BLAKE2b-256 |
12c28ea9ef89ecb90470178af9adcc33ed558f779044a8378203998b7a581469
|