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
- tree to fill
Returns
new tree that is complete
def get_tree_height(node) ‑> int
-
(helper function) Calculate the height of a tree.
Args
node
- starting node
Returns
the height of a tree
def heap_print(heap)
-
Print a heap from root to leaves.
Args
heap
- heap object to print
def tree_print(tree)
-
Print a tree from root to leaves.
Args
tree
- tree object to print
Notes
reuses heap_print() by converting tree into a complete tree array
def tree_to_array(node, index=0, tree_array=None)
-
(helper function) Create an array filled with index and value pairs from a node based tree.
Args
node
- starting node
index
- starting index
tree_array
- destination array
Returns
array filled with tree values