Skip to main content

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.

Table of Contents

Data Visualization

Sorting Visualization

Installation

Install using pip

pip install visualdsa

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.showQueue(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 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():
  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 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)

Bubble Sort

Context

  • Compares adjacent elements and swaps them if they are in the wrong order.
  • Repeatedly passes through the list until no swaps1 occur in a pass.

Visualization

import visualdsa as vd

arr = [12, 90, 53, 63]
vd.bubbleSort(arr)

Selection Sort

Context

  • Finds the minimum element in the unsorted portion of the list and places it at the beginning.
  • Repeats this process until the entire list is sorted.

Visualization

import visualdsa as vd

arr = [12, 90, 53, 63]
vd.selectionSort(arr)

Insertion Sort

Context

  • Builds the sorted array one element at a time.
  • Inserts each element into its correct position within the already sorted portion of the array.

Visualization

import visualdsa as vd

arr = [12, 90, 53, 63]
vd.insertionSort(arr)

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() to showCircularQueue()
    • showLinkedList() to showSinglyLinkedList()

0.0.5 (07/02/2025)

  • Refactored the SinglyLinkedList sample class for better code organization and readability.
  • Added checks for node count mismatches in the linked list visualization and displays a more informative warning message.
  • Implemented visualizations for Bubble Sort, Selection Sort, and Insertion Sort, including visual representations of the sorting process.
  • Updated the README.md documentation for the new visualization features.

0.0.6 (07/02/2025)

  • Updated the README.md table of contents
  • Fixed an issue where the example output images in the README.md were outdated or missing.

0.0.7 (11/02/2025)

  • Removed test case

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.7.tar.gz (7.2 kB view details)

Uploaded Source

File details

Details for the file visualdsa-0.0.7.tar.gz.

File metadata

  • Download URL: visualdsa-0.0.7.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for visualdsa-0.0.7.tar.gz
Algorithm Hash digest
SHA256 9a67b9068e018a85df46df13f31177933c06abe1674e599b2fd433b169176d1e
MD5 35c2b9d759d68a100396a870e586b26b
BLAKE2b-256 ea328f43a3c02684990fbf6076e730ae5f6b149eff5ce8ce615fcd9548794280

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