✨ Construct¢

Construct Binary Tree from list.

Binary Tree Construct MethodsΒΆ

Construct Binary Tree from

Using heapq structure

Add node attributes

List

list_to_binarytree

No

Functions:

list_to_binarytree(heapq_list[,Β node_type])

Construct tree from a list of numbers (int or float) in heapq format.

bigtree.binarytree.construct.list_to_binarytree(heapq_list: ~typing.List[int], node_type: ~typing.Type[~bigtree.node.binarynode.BinaryNode] = <class 'bigtree.node.binarynode.BinaryNode'>) β†’ BinaryNodeΒΆ

Construct tree from a list of numbers (int or float) in heapq format.

>>> from bigtree import list_to_binarytree, tree_to_dot
>>> nums_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> root = list_to_binarytree(nums_list)
>>> root.show()
1
β”œβ”€β”€ 2
β”‚   β”œβ”€β”€ 4
β”‚   β”‚   β”œβ”€β”€ 8
β”‚   β”‚   └── 9
β”‚   └── 5
β”‚       └── 10
└── 3
    β”œβ”€β”€ 6
    └── 7
>>> graph = tree_to_dot(root, node_colour="gold")
>>> graph.write_png("assets/construct_binarytree.png")
https://github.com/kayjan/bigtree/raw/master/assets/construct_binarytree.png
Parameters:
  • heapq_list (List[int]) – list containing integer node names, ordered in heapq fashion

  • node_type (Type[BinaryNode]) – node type of tree to be created, defaults to BinaryNode

Returns:

(BinaryNode)