seealgo package

Subpackages

Submodules

seealgo.see_list_algo module

This module contains the functionality to visualize a list data structure as it changes throughout a function.

This involves the following classes:

  • TrackedArray(list): detects changes made to a given list data structure and triggers creation of a new visualization for each change.

  • List: uses graphviz to construct a node-edge visualization of a list.

class seealgo.see_list_algo.List

Bases: object

Create graphviz visualization for list data structure

create_viz(data, index)

Creates and renders a visualization of the list using graphviz

Args:

data (list): list that is being visualized index (int): index of the element that has been changed

filenum = 1
see(func, data)

Creates a visualization for the initial list and starts tracking a given list as it changes throughout a given function.

Args:

func (function): function that the list is being altered through data (list): list to track

class seealgo.see_list_algo.TrackedArray(*args, **kwargs)

Bases: list

Tracks changes to a list data structure and triggers creation of new visualization

Args:

list: the list data structure to track

append(value)

Appends an element to the end of the list and checks the length of the list

Args:

value (Any): element to be appended to the list

check_length(index, invoke)

Checks for change in the length of the list and triggers creation of a new visualization if the list length has changed.

Args:

index (int): index of the element that has changed invoke (boolean): indicates whether the visualization should be created

insert(index, value)

Inserts an element at a specified position and checks the length of the list

Args:

index (int >= 0): position at which the element is to be inserted value (Any): value of element to be inserted at the specified index

remove(value)

Removes the first occurrence of a value from the list and checks the length of the list

Args:

value (Any): value to be removed from the list

seealgo.see_tree_algo module

This module contains the functionality to visualize a binary search tree data structure as nodes are inserted and removed.

This involves the following classes:

  • TreeDS: defines a custom tree data structure

  • TrackedTree(TreeDS): detects changes made to a given TreeDS data structure and triggers creation of a new visualization for each change

  • Tree: uses graphviz to construct a node-edge visualization of the tree

class seealgo.see_tree_algo.TrackedTree(label, children=None)

Bases: TreeDS

Tracks changes to a TreeDS data structure and triggers creation of new visualization

Args:

TreeDS (seealgo.see_tree_algo.TreeDS): the tree data structure to track

add_child(val)

Adds a leaf node with the specified value to the current binary search tree object.

Args:

val (Any): the value to be added to the binary search tree

check_size()

Checks if there has been a change in the size of the tree and creates a new visualization if there has been a change.

get_size()

Calculates the size of the tree based on the number of nodes in the tree.

remove_node(to_remove)

Removes a node and its children (if applicable) from a binary search tree.

Args:

to_remove (Any): value of the node to remove from the tree

class seealgo.see_tree_algo.Tree

Bases: object

Create graphviz visualization for tree data structure.

static create_node(di_graph, tree, parent=None)

Creates a visualization of a single node in a tree using Graphviz, and adds it to the given directed graph.

Args:

di_graph (graphviz.dot.Digraph): a directed graph to add the node visualization to tree (seealgo.see_tree_algo.TrackedTree): tree to create visualization of parent (seealgo.see_tree_algo.TrackedTree, optional): the parent of the current node.

Defaults to None

static create_viz(tree)

Creates and renders a visualization of the tree using graphviz

Args:

tree (seealgo.see_tree_algo.TrackedTree): tree to create visualization of

filenum = 1
static see(func, tree)

Creates a visualization for the initial tree and starts tracking the tree as it changes throughout a given function.

Args:

func (function): function that the tree is being altered through tree (dict): tree to track in nested dictionary form

class seealgo.see_tree_algo.TreeDS(label, children=None)

Bases: object

Define a custom tree data structure.

insert(child)

Inserts a leaf node into a binary search tree.

Args:

child (Any): value of leaf node to be inserted

remove(val)

Removes a child node from the binary search tree.

Args:

val (Any): value of the node to be removed

seealgo.see_tree_algo.add_to_bst(bst, value)

Helper method that recursively adds a new leaf node with the given value to its correct place in a binary search tree represented as a nested dictionary.

Args:

bst (dict): the binary search tree in nested dictionary form value (Any): The value to be inserted as a new node.

Returns:

The updated binary search tree in nested dictionary form with the specified node added.

seealgo.see_tree_algo.nested_dict_to_tracked_tree(tree_dict)

Helper method that converts a nested dictionary (the user input form of the tree) to a nested TrackedTree object form.

Args:

tree_dict (dict): nested dictionary to be converted to TrackedTree object form

Returns:

The nested TrackedTree object form of the input dictionary.

seealgo.see_tree_algo.remove_node(root, val)

Helper method that recursively removes the first node with a given value from a tree in nested dictionary form.

Args:

root (dict): the root of the tree to remove a node from val (Any): the value of the node to be removed

Returns:

The updated binary search tree in nested dictionary form with the specified node removed. If the value is not found in the tree, this method will return the original tree.

seealgo.see_tree_algo.tracked_tree_to_dict(tree)

Helper method that converts a nested TrackedTree object to a nested dictionary.

Args:

tree (nested seealgo.see_tree_algo.TrackedTree): TrackedTree object form to be converted to nested dictionary form

Returns:

The nested dictionary form of the input nested TrackedTree object.

Module contents