### Install UCXDSA Package Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/index.md Use this command to install the UCXDSA package using pip. ```bash pip install ucxdsa ``` -------------------------------- ### Import HashSet Class Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.hashset.quick_start.md Import the HashSet class from the dsa.hashset module. Ensure you use the correct path for your installation. ```python from dsa.hashset import HashSet # or the appropriate HashSet class ``` -------------------------------- ### Build Word List from Node Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.trie.quick_start.md Helper method to construct a list of words starting from a specific node and prefix. Useful for custom traversals. ```python node = t.search_node("ap") words = t.build_word_list(node, "ap") ``` -------------------------------- ### Create Deque with Specific Capacity Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.deque.quick_start.md Create a Deque instance and specify its maximum capacity. This example sets the capacity to 100 elements. ```python d = Deque(100) ``` -------------------------------- ### Find Words with a Given Prefix Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.trie.quick_start.md Return all words in the Trie that start with the specified prefix. ```python t.insert("bat") t.insert("batch") t.prefix("ba") # ["bat", "batch"] ``` -------------------------------- ### Print Deque Contents Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.deque.quick_start.md Demonstrates how to print the contents of a deque, showing the elements in order and their current count and capacity. Note: The example uses push_front and push_back, which are common deque operations but not explicitly detailed in other snippets. ```python d = Deque() d.push_front(1) d.push_front(2) d.push_back(3) print(d) ``` ```python [2, 1, 3] Count: 3 Capacity: 10 ``` -------------------------------- ### Create an Empty Trie Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.trie.quick_start.md Instantiate an empty Trie object to start storing strings. ```python t = Trie() ``` -------------------------------- ### Heap Drawing Example Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.draw.md Instantiate HeapDraw with a heap object to visualize its structure. The draw() method displays the heap as a tree. Ensure the heap object is properly defined before instantiation. ```python h = MinHeap() # Define your heap, e.g., MinHeap or Heap hd = HeapDraw(h) hd.draw() ``` -------------------------------- ### Check UCXDSA Package Version (Terminal) Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/index.md Use the pip show command in the terminal to display information about the installed ucxdsa package, including its version. ```bash pip show ucxdsa ``` -------------------------------- ### Check DSA Package Version Source: https://github.com/ucxinstructor/dsa_package/blob/main/README.md You can check the installed version of the DSA package using the `version` attribute or the `__version__` special variable. ```python import dsa dsa.version ``` ```python import dsa dsa.__version__ ``` -------------------------------- ### Update UCXDSA Package Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/index.md Use this command to upgrade an existing installation of the UCXDSA package to the latest version. ```bash pip install --upgrade ucxdsa ``` -------------------------------- ### Draw Graph Structure Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.draw.quick_start.md Use the GraphDraw class to visualize a graph. This example demonstrates creating a directed and weighted graph and adding edges. ```python from dsa.draw import GraphDraw g = Graph.create_adjacency_matrix(directed=True, weighted=True) g.add_edge("A", "B", 1) g.add_edge("A", "C", 2) g.add_edge("B", "C", 3) # accepts any graph type gd = GraphDraw(g) gd.draw() ``` -------------------------------- ### Graph Drawing Example Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.draw.md Instantiate GraphDraw with a graph object to visualize it. The draw() method displays the graph. The graph type (directed, weighted) can be inferred or explicitly set. ```python gd = GraphDraw(g) # g is a Graph type (AdjacencyMatrixGraph, AdjacencyMatrixWeightedGraph, AdjacencyListWeightedGraph, AdjacencyListGraph) gd.draw() ``` -------------------------------- ### Create an Empty Heap Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.heap.quick_start.md Instantiate an empty max heap. Use MinHeap() for a min heap. ```python h = Heap() ``` -------------------------------- ### Initialize and Draw a Trie Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.draw.md Shows how to create a TrieDraw instance with a Trie object and then render the visualization. The Trie should be populated with data prior to drawing. ```python trie = Trie() # Initialize your Trie and populate it with words trd = TrieDraw(trie) trd.draw() ``` -------------------------------- ### Import Heap Class Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.heap.quick_start.md Import the Heap class from the dsa.heap module. This is the first step before creating any heap instances. ```python from dsa.heap import Heap # or the appropriate Heap class ``` -------------------------------- ### dsa.prim.prims_mst Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.prim.md Constructs the Minimum Spanning Tree (MST) of a graph starting from a specified vertex. ```APIDOC ## prims_mst(graph, start, mst_graph=None) ### Description Returns an MST given a graph and starting vertex. (Future: return a Tree type instead of a Graph type) ### Parameters #### Path Parameters - **graph** (graph) - The graph to search an MST from. (can be either an AdjacencyListWeightedGraph or AdjacencyMatrixWeightedGraph) - **start** (string) - The starting vertex label. - **mst_graph** (graph, optional) - An empty graph object to output the MST in to. ### Returns #### Success Response (200) - **mst** (AdjacencyListWeightedGraph) - The MST of the graph. ``` -------------------------------- ### Create Empty Tree Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.tree.quick_start.md Instantiate an empty binary search tree. This creates a tree with no nodes. ```python t = Tree() ``` -------------------------------- ### Get Value by Key from HashTable Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.hashtable.quick_start.md Retrieve the value associated with a given key from the HashTable. This operation is typically very fast. ```python value = ht.get('key') # Get value for key ``` -------------------------------- ### Delete Word using Preorder (Demonstration Only) Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.trie.quick_start.md This method demonstrates deleting a word using a preorder traversal. It is not recommended for general use. ```python # Not recommended, shown for completeness t.delete_preorder("app") ``` -------------------------------- ### dsa.graph_traversal.dfs Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.graph_traversal.md Performs a Depth-First Search (DFS) on a graph starting from a specified vertex. It returns a list of vertices in the order they were visited. ```APIDOC ## dsa.graph_traversal.dfs(graph, vertex: str, visited=None, path=None, debug=False, stack=None) -> list ### Description Depth-first traversal. ### Parameters #### Path Parameters - **graph** (object) - Graph object with an adjacents(v) method. - **vertex** (str) - Starting vertex. - **visited** (set) - Optional - Set of visited vertices. - **path** (list) - Optional - Traversal order result. - **debug** (bool) - Optional - If True, print internal state. - **stack** (list) - Optional - Internal recursion stack (debug only). ### Returns - **list** - The vertices in DFS order. ``` -------------------------------- ### dsa.graph_traversal.bfs Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.graph_traversal.md Performs a Breadth-First Search (BFS) on a graph starting from a specified vertex. It returns a list of vertices in the order they were visited. ```APIDOC ## dsa.graph_traversal.bfs(graph, start: str, debug=False) -> list ### Description Breadth-first traversal. ### Parameters #### Path Parameters - **graph** (object) - Graph object with an adjacents(v) method. - **start** (str) - Starting vertex. - **debug** (bool) - Optional - If True, print internal state. ### Returns - **list** - The vertices in BFS order. ``` -------------------------------- ### Build Tree Using TreeNodes Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.tree.quick_start.md Construct a binary search tree by manually creating TreeNode instances and linking them, then initializing the Tree with the root node. This allows for precise control over the initial tree structure. ```python # Create TreeNode instances root = TreeNode(10) root.left = TreeNode(5) root.right = TreeNode(15) root.left.left = TreeNode(3) root.right.right = TreeNode(20) # Initialize the Tree with the root t = Tree(root=root) ``` -------------------------------- ### AdjacencyListGraph Methods Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.md Methods for interacting with an Adjacency List representation of a graph, including getting order, size, dictionary representation, and vertices. ```APIDOC ## AdjacencyListGraph Methods ### Description Provides methods to query properties of a graph represented using an adjacency list. ### Methods - `order()`: Returns the number of vertices in the graph. - `size()`: Returns the number of edges in the graph. - `to_dict()`: Returns a dictionary representation of the graph. - `undirected_edges()`: Returns a list of all undirected edges in the graph. - `vertices()`: Returns a list of all vertices in the graph. ``` -------------------------------- ### Build Doubly Linked List from Nodes Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.linkedlist.quick_start.md Construct a doubly linked list by manually creating and linking nodes with both next and prev references, then initializing the list. ```python # Create nodes and link them with next/prev d1 = DNode(1) d2 = DNode(2) d3 = DNode(3) d1.next = d2 d2.prev = d1 d2.next = d3 d3.prev = d2 # Initialize the list with head/tail dll = DoublyLinkedList(head=d1, tail=d3, count=3) ``` -------------------------------- ### Initialize Data Structures and Draw Classes Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.draw.quick_start.md Create instances of data structures and their corresponding Draw classes. The Draw class is initialized with the data structure instance. ```python # create Tree t = Tree() td = TreeDraw(t) # create Heap h = Heap() hd = HeapDraw(h) # create Trie trie = Trie() trd = TreeDraw(trie) # create Graph g = Graph() gd = GraphDraw(g) ``` -------------------------------- ### Import Deque Class Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.deque.quick_start.md Import the Deque class from the dsa.deque module. This is the first step before creating any Deque instances. ```python from dsa.deque import Deque # or the appropriate Deque class ``` -------------------------------- ### Search for a Node (Prefix) in Trie Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.trie.quick_start.md Find the node corresponding to a given prefix. Useful for checking prefix existence or as a starting point for other operations. ```python node = t.search_node("app") node is not None # True if prefix exists ``` -------------------------------- ### Initialize and Draw a Tree Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.draw.md Demonstrates how to initialize a TreeDraw object with a Tree structure and then draw it. Ensure your Tree is properly defined before instantiation. ```python t = Tree(root_node) # Define your tree structure with a root node td = TreeDraw(t) td.draw() ``` -------------------------------- ### List Adjacent Vertices from a Given Vertex Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.graph.quick_start.md Get a list of all vertices directly connected from a specified vertex. This operation helps in understanding immediate neighbors. ```python g.adjacents("A") ``` -------------------------------- ### Create a Directed and Weighted Graph (Adjacency Matrix) Source: https://github.com/ucxinstructor/dsa_package/blob/main/noshare/graph.ipynb Initializes a new graph instance configured for directed edges and weighted connections using an adjacency matrix representation. ```python from dsa.graph import Graph g = Graph.create_adjacency_matrix(directed=True, weighted=True) ``` -------------------------------- ### Import HashTable Class Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.hashtable.quick_start.md Import the HashTable class from the dsa.hashtable module. This is the first step before using any HashTable functionality. ```python from dsa.hashtable import HashTable # or the appropriate HashTable class ``` -------------------------------- ### Create Stack with Default Capacity Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.stack.quick_start.md Instantiate a Stack object with its default capacity. ```python s = Stack() ``` -------------------------------- ### Create HashTable with Default Capacity Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.hashtable.quick_start.md Instantiate a HashTable object with the default capacity. This is useful for general-purpose use when the expected number of elements is not known in advance. ```python ht = HashTable() ``` -------------------------------- ### Create an Empty HashSet Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.hashset.quick_start.md Instantiate an empty HashSet object to begin storing unique elements. ```python hs = HashSet() ``` -------------------------------- ### Create Stack with Custom Capacity Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.stack.quick_start.md Instantiate a Stack object with a specified capacity. ```python s = Stack(100) ``` -------------------------------- ### Create Queue with Default Capacity Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.queue.quick_start.md Instantiate a Queue object with its default capacity. This is useful for general-purpose queue needs. ```python q = Queue() ``` -------------------------------- ### Create HashTable with Specific Capacity Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.hashtable.quick_start.md Instantiate a HashTable object with a specified capacity. This is useful for performance tuning when you have an estimate of the number of elements. ```python ht = HashTable(100) ``` -------------------------------- ### Create Empty Doubly Linked List Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.linkedlist.quick_start.md Instantiate an empty doubly linked list. ```python dll = DoublyLinkedList() ``` -------------------------------- ### Import Queue Class Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.queue.quick_start.md Import the Queue class from the dsa.queue module. Ensure you use the correct import path for your project. ```python from dsa.queue import Queue # or the appropriate Queue class ``` -------------------------------- ### Import Array Class Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.array.quick_start.md Import the Array class from the dsa.array module. This is the first step before creating any Array instances. ```python from dsa.array import Array # or the appropriate Array class ``` -------------------------------- ### Create Queue with Specific Capacity Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.queue.quick_start.md Instantiate a Queue object with a custom capacity. Use this when you need to pre-allocate space for a known number of elements. ```python q = Queue(capacity=100) ``` -------------------------------- ### Suggest Words with a Prefix Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.trie.quick_start.md Provide suggestions for words based on a given prefix. This method may fall back to broader prefixes if exact matches are limited. ```python t.suggest("batc") # Falls back to "bat" prefix → ["batch"] ``` -------------------------------- ### Import Stack Class Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.stack.quick_start.md Import the Stack class from the dsa.stack module. Ensure the correct path is used. ```python from dsa.stack import Stack # or the appropriate Stack class ``` -------------------------------- ### Create Array with Default Capacity Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.array.quick_start.md Create an array instance with the default capacity. This is useful for arrays where the initial size is not critical or will be determined by usage. ```python a = Array() ``` -------------------------------- ### Build Singly Linked List from Nodes Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.linkedlist.quick_start.md Construct a singly linked list by manually creating and linking nodes, then initializing the list with the head, tail, and count. ```python # Create nodes and link them n1 = SNode(1) n2 = SNode(2) n3 = SNode(3) n1.next = n2 # Initialize the list with head/tail ll = LinkedList(head=n1, tail=n3, count=3) ``` -------------------------------- ### Create Array with Specific Capacity Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.array.quick_start.md Create an array instance with a specified capacity. This allows pre-allocation of memory for a known or estimated number of elements. ```python a = Array(100) ``` -------------------------------- ### Print Stack Contents Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.stack.quick_start.md Display the elements of the stack, its top element, and its capacity. The output format shows elements as a list, followed by the top element and capacity. ```python s = Stack() s.push(1) s.push(2) s.push(3) print(s) ``` ```python [1, 2, 3] Top: 2 Capacity: 10 ``` -------------------------------- ### Import Linked List Classes Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.linkedlist.quick_start.md Import the necessary LinkedList and Node classes for singly and doubly linked lists. ```python from dsa.singlylinkedlist import LinkedList, Node as SNode from dsa.doublylinkedlist import DoublyLinkedList, Node as DNode ``` -------------------------------- ### Create Empty Singly Linked List Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.linkedlist.quick_start.md Instantiate an empty singly linked list. ```python ll = LinkedList() ``` -------------------------------- ### Print Heap Contents (Simple) Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.heap.quick_start.md Display the elements of the heap using the built-in print() method. This provides a level-by-level representation. ```python h = Heap() h.insert(1) h.insert(2) h.insert(3) h.insert(4) h.print() ``` -------------------------------- ### HashSet Methods Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.md Methods for managing a hash set, including adding, removing, checking for containment, and converting to/from lists. ```APIDOC ## HashSet Methods ### Description Provides methods for managing elements in a hash set. ### Methods - `add(item)`: Adds an item to the hash set. - `contains(item)`: Checks if an item is present in the hash set. - `from_list(items)`: Creates a hash set from a list of items. - `remove(item)`: Removes an item from the hash set. - `to_list()`: Returns a list of all items in the hash set. ``` -------------------------------- ### dsa.huffman.build_huffman_tree Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.huffman.md Accepts a priority queue of characters and their frequencies to construct a Huffman Tree. ```APIDOC ## dsa.huffman.build_huffman_tree(pq: PriorityQueue) -> Tree ### Description Accepts a priority queue and returns a Huffman Tree. ### Parameters #### Path Parameters - **pq** (PriorityQueue) - Required - A PriorityQueue containing TreeNodes of characters based on frequencies. ### Returns - **Tree** - A Huffman Tree. ``` -------------------------------- ### Import Draw Classes Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.draw.quick_start.md Import the Draw class specific to the data structure you want to visualize. ```python from dsa.draw import TreeDraw from dsa.draw import HeapDraw from dsa.draw import TrieDraw from dsa.draw import GraphDraw ``` -------------------------------- ### Print HashTable Contents Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.hashtable.quick_start.md Display the current contents of the HashTable. This is useful for debugging and verifying the state of the hash table. ```python ht = HashTable() ht.set(1, "a") ht.set(2, "b") ht.set(3, "c") ht.set(1, "d") print(ht) ``` ```python {1:d, 2:b, 3:c} ``` -------------------------------- ### Import Graph Class Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.graph.quick_start.md Import the Graph class from the graph module to begin using graph functionalities. ```python from dsa.graph import Graph ``` -------------------------------- ### Print Heap Contents (Formatted) Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.heap.quick_start.md Use the heap_print function from dsa.pretty_print for a more structured visual output of the heap's elements. ```python from dsa.pretty_print import heap_print heap_print(h) ``` -------------------------------- ### dsa.heap.MinHeap Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.heap.md Represents a min heap implementation, inheriting from the Heap class. Provides methods specific to min heap operations. ```APIDOC ## class dsa.heap.MinHeap ### Description A min heap implementation. ### Methods #### extract_min() Return the value of the root node (min value) and remove it from the heap. #### heapify_down(index: int) Perform heapify down starting at a given index. #### heapify_up(index: int) Perform heapify up starting at a given index. ``` -------------------------------- ### Create Adjacency Matrix Graph (Default) Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.graph.quick_start.md Create an adjacency matrix graph with undirected and unweighted edges, which are the default settings. ```python g = Graph.create_adjacency_matrix() ``` -------------------------------- ### Create Deque with Default Capacity Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.deque.quick_start.md Instantiate a Deque object with its default capacity, which is typically 10 elements. ```python d = Deque() ``` -------------------------------- ### Draw Heap Structure Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.draw.quick_start.md Use the HeapDraw class to visualize a heap. Ensure the Heap class is imported and populated before drawing. ```python from dsa.draw import HeapDraw h = Heap() h.insert(1) h.insert(2) h.insert(3) h.insert(4) hd = HeapDraw(h) hd.draw() ``` -------------------------------- ### Prepend to Linked Lists Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.linkedlist.quick_start.md Add a value to the beginning of both singly and doubly linked lists. ```python ll.prepend(0) dll.prepend(0) ``` -------------------------------- ### Check UCXDSA Package Version (Python) Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/index.md Import the dsa package in Python or Jupyter to print its version. ```python import dsa print(dsa.version) ``` -------------------------------- ### Print Queue Contents Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.queue.quick_start.md Display the current elements, count, and capacity of the queue. This is useful for debugging and monitoring the queue's state. ```python q = Queue() q.enqueue(1) q.enqueue(2) q.enqueue(3) print(q) ``` ```python [1, 2, 3] Count: 3 Capacity: 10 ``` -------------------------------- ### LinkedList.prepend Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.singlylinkedlist.md Prepends a value to the beginning of the linked list. ```APIDOC ## prepend(value) ### Description Place a value at the beginning of the linked list. ### Parameters * **value** (any) - A value to append. ### Returns None ``` -------------------------------- ### random_heap Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.generators.md Generates a random heap with a specified number of nodes. ```APIDOC ## dsa.generators.random_heap(n: int) -> [Heap](dsa.heap.md#dsa.heap.Heap) Generates a random heap. :param n – number of nodes in the heap: * **Returns:** Heap ``` -------------------------------- ### Create HashSet from Iterable Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.hashset.quick_start.md Initialize a HashSet with elements from an existing iterable, such as a list. ```python hs = HashSet([1, 2, 3]) ``` -------------------------------- ### dsa.graph.Graph.create Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.graph.md A static factory method to create a graph object based on specified parameters. It allows for the creation of different graph types, including directed and weighted options. ```APIDOC ## dsa.graph.Graph.create ### Description Return a graph object based on the specified parameters. ### Method static create ### Parameters #### Parameters - **graph_type** (str) - Required - The type of graph (‘adjacency_matrix’ or ‘adjacency_list’). - **directed** (bool) - Optional - Whether the graph is directed. - **weighted** (bool) - Optional - Whether the graph is weighted. - **vertices** (list[str], optional) - Optional - List of vertex labels for adjacency matrix graphs. Defaults to []. ### Response #### Success Response - An instance of the specified graph class. ``` -------------------------------- ### HashTable Methods Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.md Methods for interacting with a hash table, including accessing item count and enumerating key-value pairs. ```APIDOC ## HashTable Methods ### Description Provides methods for managing key-value pairs in a hash table. ### Methods - `count`: Property that returns the number of items in the hash table. - `enumerate()`: Returns an iterator over the key-value pairs in the hash table. ``` -------------------------------- ### grow() Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.array.md Internal helper method to increase the array's capacity by doubling it. ```APIDOC ## grow() Helper method to double the capacity of the current array. ``` -------------------------------- ### dsa.queue.Queue Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.queue.md A static queue implementation with fixed capacity. Supports enqueue, dequeue, peek, and conversion from a list. ```APIDOC ## class dsa.queue.Queue ### Description A static queue implementation. ### Methods #### capacity() Return the capacity of the queue. * **Returns:** The capacity of the queue. #### dequeue() Dequeue an element from the queue. Raise Exception when there are no elements to dequeue. * **Raises:** **Exception** – When there are no elements to dequeue. * **Returns:** The from element in the queue. #### enqueue(element) Enqueue an element into the queue. Raise Exception when trying to enqueue more elements than the capacity. * **Parameters:** **element** – The element to enqueue. * **Raises:** **Exception** – When trying to enqueue more elements than the capacity. * **Returns:** None #### from_list(alist) Set the contents of a queue into an array. Raise Exception when trying to enqueue more elements than the capacity. * **Parameters:** **alist** – The list with contents to enqueue. * **Returns:** The queue with the contents of the list. #### is_empty() Return a Boolean on whether the stack is empty or not. * **Returns:** True if the stack is empty, False otherwise. #### peek() Return the element in front of the queue. Raise Exception if queue is empty. * **Returns:** The element in front of the queue. * **Raises:** **Exception** – When the queue is empty. #### raw_view() Return the queue in its array representation. * **Returns:** The array representation of the queue. #### to_ordered_list() → list Return the contents of the queue as a Python list. * **Returns:** The contents of the queue as a Python list. ``` -------------------------------- ### Import Trie Class Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.trie.quick_start.md Import the Trie class from the dsa.trie module to begin using the data structure. ```python from dsa.trie import Trie ``` -------------------------------- ### Import Module and Class from UCXDSA Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/index.md This is a basic import statement to use a specific class from a module within the UCXDSA package. Replace 'modulename' and 'classname' with the actual names. ```python from dsa.modulename import classname ``` -------------------------------- ### Import Tree Class Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.tree.quick_start.md Import the necessary Tree and TreeNode classes from the dsa.tree module. This is the first step before creating or manipulating tree structures. ```python from dsa.tree import Tree, TreeNode # or the appropriate Tree class ``` -------------------------------- ### Print Tree Contents (Pretty Print) Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.tree.quick_start.md Print the tree contents using the `tree_print` function from the `dsa.pretty_print` module for an alternative, more compact visualization. ```python from dsa.pretty_print import tree_print tree_print(t) ``` -------------------------------- ### Add Item to HashSet Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.hashset.quick_start.md Use the add() method to insert an element into the HashSet. Duplicate elements are ignored. ```python hs.add(10) # Add 10 to the set ``` -------------------------------- ### dsa.huffman.build_frequency_table Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.huffman.md Accepts a string to encode and returns a heap of the characters based on their frequencies. ```APIDOC ## dsa.huffman.build_frequency_table(s: str) -> PriorityQueue ### Description Accepts a string to encode and returns a heap of the characters. ### Parameters #### Path Parameters - **s** (str) - Required - The string to encode. ### Returns - **PriorityQueue** - A priority queue of the characters based on frequencies. ``` -------------------------------- ### dsa.huffman.build_huffman_dictionary Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.huffman.md Given a Huffman tree node, builds a Huffman dictionary for encoding. ```APIDOC ## dsa.huffman.build_huffman_dictionary(node: TreeNode, bit_string: str = '') -> dict ### Description Given a TreeNode, build a Huffman Dictionary. ### Parameters #### Path Parameters - **node** (TreeNode) - Required - The Huffman Node. - **bit_string** (str) - Optional - The bit string. Defaults to '' ### Returns - **dict** - A Huffman Dictionary. ``` -------------------------------- ### HashTable Class Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.hashtable.md The HashTable class provides a basic implementation of a hash table, allowing for efficient key-value storage and retrieval. ```APIDOC ## class dsa.hashtable.HashTable(capacity=20) Bases: `object` A hashtable implementation. #### count the number of items in the hashtable #### enumerate() Return the enumeration of key-value pairs in the hashtable. * **Returns:** Enumeration of key-value pairs. #### get(key) Get corresponding value of a given key in the hash table. * **Parameters:** * **key** – The key to check for. * **value** – The value to set or create. * **Returns:** corresponding value of key. None if key is not found. #### hash_function(key) → int Return a hash value based on a given key. * **Parameters:** **key** – The key to convert to a hashvalue. * **Returns:** Hash value modded to the hashtable capacity. #### key_exists(key) → bool Returns a Boolean on whether a key exists in the hashtable or not . * **Parameters:** **key** – The key to check for in the hashtable. * **Returns:** Boolean of key existence. #### pop(key, default=None) Remove specified key and return the value. If key is not found, return default. #### remove(key) Remove key-value pair if specified key is found. Raise KeyError if not found. * **Parameters:** **key** – The key to check for. * **Raises:** **KeyError** – If the key is not found in the hashtable. #### set(key, value) Set a key-value pair in the hashtable. If key exists, replace the value otherwise, create a new key-pair. * **Parameters:** * **key** – The key to check for. * **value** – The value to set or create. #### show_buckets() Return a string displaying the contents of all buckets in the hashtable. ``` -------------------------------- ### dsa.heap.PriorityQueue Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.heap.md Represents a priority queue implementation, inheriting from MinHeap. Allows insertion and retrieval of items based on priority. ```APIDOC ## class dsa.heap.PriorityQueue ### Description A priority queue implementation in Python. ### Methods #### peek() → tuple Return the highest priority value in the heap. #### peek_pair() → tuple Return the highest priority value pair in the heap. #### pop() → tuple Return and remove the highest priority value in the heap. #### pop_pair() → tuple Return and remove the highest priority value pair in the heap. #### push(priority: int, item) Insert an item with a priority into the priority queue. #### to_string_with_priority() Return string representation of a heap in order of priority. ``` -------------------------------- ### Print Linked List Contents Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.linkedlist.quick_start.md Create a linked list from a Python list and print its contents and count. The output format is a list of elements followed by the total count. ```python ll = LinkedList.from_list([1, 2, 3, 4]) print(ll) ``` ```python [1, 2, 3, 4] Count: 4 ``` -------------------------------- ### dsa.queue.DynamicQueue Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.queue.md A dynamic queue implementation that grows its capacity when needed. Supports enqueue, dequeue, and peek operations. ```APIDOC ## class dsa.queue.DynamicQueue ### Description A dynamic queue implementation. Note that shrink is not implemented. ### Methods #### check_capacity() If count >= capacity, grow the array. * **Returns:** None #### enqueue(element) Enqueue an element into the queue. Increase capacity if count is greater than the capacity. * **Parameters:** **element** – the element to enqueue * **Returns:** None #### grow() Double the capacity of the current array. * **Returns:** None ``` -------------------------------- ### Push Element onto Stack Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.stack.quick_start.md Add an element to the top of the stack. This operation will raise an exception if the stack is full. ```python s.push(10) # Push 10 onto the stack ``` -------------------------------- ### DoublyLinkedList.from_list Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.doublylinkedlist.md Creates a doubly linked list from an existing Python list. ```APIDOC ## from_list(mylist: list) ### Description Create a doubly linked list from a list. ### Method from_list ### Parameters #### Path Parameters - **mylist** (list) - Required - A list or container to convert from. ### Returns - Doubly linked list with the contents of the list. ``` -------------------------------- ### random_queue Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.generators.md Generates a random queue of integers with specified size and value range. ```APIDOC ## dsa.generators.random_queue(size: int, min_val: int = 0, max_val=100) -> [Queue](dsa.queue.md#dsa.queue.Queue) Generates a random queue of integers. :param size – number of elements in the queue: :param min_val – minimum value of the elements: :param max_val – maximum value of the elements: * **Returns:** Queue ``` -------------------------------- ### dsa.draw.HeapDraw Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.draw.md A class for drawing a heap structure using the NetworkX library, visualizing heaps like binary heaps or min-heaps. ```APIDOC ## class dsa.draw.HeapDraw(heap: [Heap](dsa.heap.md#dsa.heap.Heap), **kwargs) Bases: [`Draw`](#dsa.draw.Draw) A class for drawing a heap structure using the NetworkX library. This class extends the Draw class to visualize heap structures, such as binary heaps or min-heaps. ### Attributes #### heap The heap structure to be drawn. * **Type:** [Heap](dsa.heap.md#dsa.heap.Heap) ### Usage Example : h = MinHeap() # Define your heap, e.g., MinHeap or Heap hd = HeapDraw(h) hd.draw() ### Methods #### array_to_node(index: int, array) Converts an array-based heap into a tree node structure. This helper function recursively constructs a tree from the array representation of the heap, reflecting the binary tree structure of the heap. * **Parameters:** * **index** (*int*) – The current index in the array representing the node. * **array** (*list*) – The array containing heap values, organized as a complete binary tree. * **Returns:** The root node of the constructed subtree. * **Return type:** [TreeNode](dsa.tree.md#dsa.tree.TreeNode) #### render(**kwargs) Renders the heap as a tree using Matplotlib. Not to be called directly. Call draw() instead. This method converts the heap into a tree structure and then uses the TreeDraw class to render it visually. Customization options can be provided via keyword arguments. * **Returns:** The Matplotlib plot object for further customization or display. * **Return type:** matplotlib.pyplot ``` -------------------------------- ### Peek at Left Element Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.deque.quick_start.md Retrieve the element at the beginning (left side) of the deque without removing it. Raises an exception if the deque is empty. ```python value = d.peek_left() # Peek at the left ``` -------------------------------- ### Peek at Front Element of Queue Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.queue.quick_start.md Return the element at the front of the queue without removing it. This operation will raise an exception if the queue is empty. ```python value = q.peek() # Peek at the front element ``` -------------------------------- ### Graph Factory Methods Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.md Factory methods for creating different types of graphs, including adjacency list and adjacency matrix representations. ```APIDOC ## Graph Factory Methods ### Description Provides static methods to create graph instances. ### Methods - `create()`: Creates a default graph instance. - `create_adjacency_list()`: Creates an instance of AdjacencyListGraph. - `create_adjacency_matrix()`: Creates an instance of AdjacencyMatrixGraph. - `from_dict(data)`: Creates a graph from a dictionary representation. ``` -------------------------------- ### Check Vertex and Edge Existence Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.graph.quick_start.md Verify the existence of vertices and edges within a directed and weighted adjacency matrix graph. This method is useful for validating graph state. ```python from dsa.graph import Graph g = Graph.create_adjacency_matrix(directed=True, weighted=True) g.add_vertex("A") g.add_vertex("B") g.add_vertex("C") g.add_edge("A", "B", 1) g.add_edge("A", "C", 2) g.add_edge("B", "C", 3) g.has_vertex("A") # True g.has_vertex("B") # True g.has_vertex("D") # False g.has_edge("A", "B") # True g.has_edge("A", "C") # True g.has_edge("C", "B") # False ``` -------------------------------- ### shrink() Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.array.md Internal helper method to decrease the array's capacity by halving it, with a minimum capacity of 10. ```APIDOC ## shrink() Helper method to halve the capacity of the current array. minimum capacity is 10. ``` -------------------------------- ### Print Array Contents Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.array.quick_start.md Display the elements of the array along with its current count and capacity. This is useful for debugging and understanding the array's state. ```python a = Array.from_list([1, 2, 3, 4]) print(a) ``` ```python [1, 2, 3, 4] Count: 4 Capacity: 4 ``` -------------------------------- ### random_stack Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.generators.md Generates a random stack of integers with specified size and value range. ```APIDOC ## dsa.generators.random_stack(size: int, min_val: int = 0, max_val=100) -> [Stack](dsa.stack.md#dsa.stack.Stack) Generates a random stack of integers. :param size – number of elements in the stack: :param min_val – minimum value of the elements: :param max_val – maximum value of the elements: * **Returns:** Stack ``` -------------------------------- ### Print HashSet Contents Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.hashset.quick_start.md The print() function displays the unique elements contained within the HashSet in a readable format. ```python hs = HashSet() hs.add(1) hs.add(2) hs.add(3) hs.add(1) print(hs) ``` ```python HashSet([1, 2, 3]) ``` -------------------------------- ### Enqueue Element into Queue Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.queue.quick_start.md Add an element to the rear of the queue. This operation will raise an exception if the queue is already at its maximum capacity. ```python q.enqueue(10) # Enqueue 10 into the queue ``` -------------------------------- ### Draw Trie Structure Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.draw.quick_start.md Use the TrieDraw class to visualize a trie. Ensure the Trie class is imported and populated before drawing. ```python from dsa.draw import TrieDraw t = Trie() t.insert("cab") t.insert("car") t.insert("cut") td = TrieDraw(t) td.draw() ``` -------------------------------- ### dsa.stack.DynamicStack Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.stack.md A dynamic stack implementation that automatically adjusts its capacity. It supports standard stack operations like push and pop, and includes methods for growing and shrinking the underlying array based on element count and capacity. ```APIDOC ## class dsa.stack.DynamicStack(capacity: int = 10) ### Description A dynamic stack implementation that automatically adjusts its capacity. It supports standard stack operations like push and pop, and includes methods for growing and shrinking the underlying array based on element count and capacity. ### Methods #### check_capacity() Check the capacity of the stack. If count >= capacity, grow the array. If count <= 1/4 of capacity, shrink the array. #### grow() Helper method to double the capacity of the current array. #### pop() Return an element from the stack. Automatically shrinks array if capacity is 4x the count. * **Returns:** The top element in the stack. * **Raises:** **Exception** – When the stack is empty. #### push(element) Push an element into the stack. Automatically grows array if capacity needs to increase. * **Parameters:** **element** – The element to push. * **Returns:** None #### shrink() Helper method to halve the capacity of the current array. ``` -------------------------------- ### dsa.stack.Stack Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.stack.md A static stack implementation with a fixed capacity. It provides methods for checking capacity, emptiness, peeking at the top element, pushing, popping, and converting the stack to a list. ```APIDOC ## class dsa.stack.Stack(capacity: int = 10) ### Description A static stack implementation with a fixed capacity. It provides methods for checking capacity, emptiness, peeking at the top element, pushing, popping, and converting the stack to a list. ### Methods #### capacity() Return the capacity of the stack. #### count number of elements in stack #### *classmethod* from_list(alist: list) Set the contents of a stack from a list. Raise Exception when trying to push more elements than the capacity. * **Parameters:** **alist** – The list with contents to set as an array. #### is_empty() Return a Boolean on whether the stack is empty or not. #### peek() Return the element from the top of the stack. Raise Exception if stack is empty. * **Returns:** The top element in the stack. * **Raises:** **Exception** – When the stack is empty. #### pop() Pop an element from the stack. Raise Exception when there are no elements to pop. * **Returns:** The top element in the stack. * **Raises:** **Exception** – When the stack is empty. #### push(element) Push an element into the stack. Raise Exception when trying to push more elements than the capacity. * **Parameters:** **element** – The element to push. * **Raises:** **Exception** – When the capacity is reached. #### to_list() Return the contents of the stack as an array. #### top() Return the top index of the stack. ``` -------------------------------- ### List All Words in Trie Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.trie.quick_start.md Retrieve a list of all words currently stored in the Trie. ```python words = t.list_words() # e.g., ["app"] after deletions above ``` -------------------------------- ### DoublyLinkedList.prepend Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.doublylinkedlist.md Prepends a value to the beginning of the doubly linked list. ```APIDOC ## prepend(value) ### Description Place a value at the beginning of the doubly linked list. ### Method prepend ### Parameters #### Path Parameters - **value** (any) - Required - The value to prepend to the doubly linked list. ``` -------------------------------- ### AdjacencyMatrixWeightedGraph Methods Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.graph.md Provides methods for managing a weighted adjacency matrix graph, including adding/deleting edges with weights, and retrieving weighted adjacency information. ```APIDOC ## AdjacencyMatrixWeightedGraph ### Description A weighted adjacency matrix graph implementation that allows for directed or undirected representation. ### Methods #### add_edge(start_label: str, end_label: str, weight, directed=None) Add an edge to the graph. * **Parameters:** * **start_label** (*str*) – The starting vertex label. * **end_label** (*str*) – The ending vertex label. * **weight** – The weight of the vertex. * **directed** – Whether the edge is directed. #### adjacent_items(vertex: str) → list Return a list of adjacents and weights of a given vertex (adjacent label, weight) pair. * **Parameters:** **vertex** – starting vertex label #### edges() → list Return a list of edges in the graph. Each edge is represented by a tuple (start, end, weight). #### from_dict(data: dict, directed: bool = False) Create a weighted graph from a dictionary representation. * **Parameters:** * **data** (*dict*) – The dictionary representation of the graph. * **directed** (*bool*) – Whether the graph is directed. * **Returns:** An instance of the weighted graph class. #### get_weight(start_label: str, end_label: str) Get the weight of an edge. * **Parameters:** * **start_label** – The starting vertex label. * **end_label** – The ending vertex label. * **Returns:** The weight of the edge from start to end. #### print_graph() Print the contents of the graph. #### undirected_edges() → list Return a list of undirected edges in the graph. Each edge is represented by a tuple (start, end, weight). ``` -------------------------------- ### AdjacencyMatrixGraph Methods Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.graph.md Provides methods for managing an unweighted adjacency matrix graph, including adding/deleting vertices and edges, and querying graph properties. ```APIDOC ## AdjacencyMatrixGraph ### Description An unweighted adjacency matrix graph implementation that allows for directed or undirected representations. ### Methods #### add_edge(start_label: str, end_label: str, directed=None) Add an edge in the graph. * **Parameters:** * **start_label** (*str*) – Starting vertex label. * **end_label** (*str*) – Ending vertex label. * **directed** (*bool*) – Whether the edge is directed. #### add_vertex(label: str) Add a vertex to the graph. * **Parameters:** **label** (*str*) – The vertex label to add. * **Raises:** **ValueError** – If the vertex label already exists. #### adjacents(vertex: str) → list Return a list of adjacents of a given vertex. * **Parameters:** **vertex** (*str*) – The label of the vertex. #### delete_edge(start_label: str, end_label: str, directed=None) Delete an edge in the graph. * **Parameters:** * **start_label** (*str*) – Starting vertex label. * **end_label** (*str*) – Ending vertex label. * **directed** (*bool*) – Whether the edge is directed. #### delete_vertex(label: str) Delete a vertex from the graph. * **Parameters:** **label** (*str*) – The vertex label to delete. #### edges() → list Return a list of edges in the graph. Each edge is represented by a tuple (start, end). #### from_dict(data: dict, directed: bool = False) Create a graph from a dictionary representation. * **Parameters:** * **data** (*dict*) – The dictionary representation of the graph. * **directed** (*bool*) – Whether the graph is directed. * **Returns:** An instance of the graph class. #### has_edge(start_label: str, end_label: str) → bool Return boolean if an edge exists. * **Parameters:** * **start_label** (*str*) – starting vertex label * **end_label** (*str*) – starting vertex label * **Returns:** A boolean of whether there is an edge from start to end. #### has_vertex(label: str) → bool Return boolean if a vertex exists. * **Parameters:** **label** (*str*) – The vertex label. * **Returns:** A boolean of whether the vertex exists in the graph. #### order() → int Return the number of nodes in the graph. :returns: The number of nodes in the graph. :rtype: int #### print_graph() Print the contents of the graph. #### size() → int Return the number of edges in the graph. :returns: The number of edges in the graph. :rtype: int #### to_dict() → dict Return the adjacency matrix as a dictionary. For unweighted graphs, returns a dictionary of lists. For weighted graphs, returns a dictionary of dictionaries. * **Returns:** A dictionary representing the adjacency matrix of the graph. - Unweighted: {vertex: [neighbor1, neighbor2, …]} - Weighted: {vertex: {neighbor1: weight1, neighbor2: weight2, …}} #### undirected_edges() → list Return a list of undirected edges in the graph. Each edge is represented by a tuple (start, end) #### vertices() → list Return a list of vertex labels of the graph ``` -------------------------------- ### List All Edges in a Graph Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.graph.quick_start.md Retrieve a list of all edges in the graph. For weighted graphs, each edge is represented as a tuple including its weight. ```python g.edges() ``` -------------------------------- ### Create Adjacency List Graph (Undirected, Unweighted) Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.graph.quick_start.md Create an adjacency list graph specifying undirected and unweighted edges. ```python g = Graph.create_adjacency_list(directed=False, weighted=False) ``` -------------------------------- ### LinkedList.traverse Source: https://github.com/ucxinstructor/dsa_package/blob/main/docs/source/dsa.singlylinkedlist.md Traverses the linked list and prints the value of each node to the console. ```APIDOC ## traverse() ### Description Print the contents of the linked list. ```