Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ucxinstructor/dsa_package/llms.txt
Use this file to discover all available pages before exploring further.
TreeNode
A binary tree node implementation.Constructor
The value of the node.
Reference to the left child node.
Reference to the right child node.
Methods
copy()
Return a deep copy of the node and its subtree.A new TreeNode with the same structure and values as the original.
print(level=0)
Print the contents of the node and its subtree in a visual tree format.Starting indentation level of the node (used internally for recursion).
Special Methods
__lt__(other)
Compare the value of two nodes using the less-than operator.The other node to compare against.
True if this node’s value is less than the other node’s value.
__repr__()
Return the string representation of a node.String representation of the node’s value, or “none” if value is None.
Tree
A binary search tree (BST) implementation. Can be treated as a plain binary tree if BST operations (insert, search, delete) are not used and nodes are set manually.Constructor
Root node of the tree.
Methods
search(value)
Search for a value in the binary search tree.Value to search for.
The node with the matching value.
ValueError: If value is not found in the tree
insert(value)
Insert a value in the binary search tree.The value to insert.
The root of the tree after insertion.
ValueError: If value already exists in the tree
insert_iterative(value)
Insert a value in the binary search tree using an iterative implementation.The value to insert.
ValueError: If value already exists in the tree
delete(value)
Delete a value from the binary search tree.The value to delete.
The root of the tree after deletion.
ValueError: If value is not found in the tree
successor_node(node=None)
Return the successor node (the minimum value in a binary search tree’s right subtree).The starting node. If None, uses the tree’s root.
Node with the lowest value in the subtree, or None if not found.
predecessor_node(node=None)
Return the predecessor node (the maximum value in a binary search tree’s left subtree).The starting node. If None, uses the tree’s root.
Node with the highest value in the subtree, or None if not found.
print()
Print the values in the BST in a visual tree format.Special Methods
__len__()
Return the number of nodes in the BST.The number of nodes in the BST.
__eq__(other)
Compare two Tree objects for value-based equality (structure and values).The other tree to compare against.
True if both are Tree instances and their structures and values are equal.