dsa.pretty_print module — ucxdsa documentation

# dsa.pretty_print module

Module to access functions for a clearer visual representation of certain data structures.

dsa.pretty_print.fill_complete_tree(tree)

  (helper function) Force a binary tree to be a complete tree by filling any empty nodes.

  Parameters:

    tree – The tree to fill.

  Returns:

    A new tree that is complete.

dsa.pretty_print.get_tree_height(node)

  (helper function) Calculate the height of a tree.

  Parameters:

    node – The starting node.

  Return type:

    `int`

  Returns:

    The height of a tree.

dsa.pretty_print.heap_print(heap)

  Print a heap from root to leaves.

  Parameters:

    heap – The heap object to print.

dsa.pretty_print.tree_print(tree)

  Print a tree from root to leaves.

  Parameters:

    tree – The tree object to print.

  Notes

  Reuses heap_print() by converting tree into a complete tree array.

dsa.pretty_print.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.

  Parameters:

    - node – The starting node.

    - index (int) – The starting index.

    - tree_array – The destination array.

  Returns:

    Array filled with tree values.