Module dsa.pretty_print
Module to access functions for a clearer visual representation of certain data structures.
Functions
def fill_complete_tree(tree)
-
(helper function) Force a binary tree to be a complete tree by filling any empty nodes.
Args
tree
- The tree to fill.
Returns
A new tree that is complete.
def get_tree_height(node) ‑> int
-
(helper function) Calculate the height of a tree.
Args
node
- The starting node.
Returns
The height of a tree.
def heap_print(heap)
-
Print a heap from root to leaves.
Args
heap
- The heap object to print.
def tree_print(tree)
-
Print a tree from root to leaves.
Args
tree
- The tree object to print.
Notes
Reuses heap_print() by converting tree into a complete tree array.
def tree_to_array(node, index: int = 0, tree_array=None)
-
(helper function) Create an array filled with index and value pairs from a node based tree.
Args
node
- The starting node.
index
:int
- The starting index.
tree_array
- The destination array.
Returns
Array filled with tree values.