BinTreeNode#

class tangles.util.tree.BinTreeNode(parent: Node | None = None, left_child: Node | None = None, right_child: Node | None = None)#

Node of a BinTree.

Note: when a node is created, the parent attribute of left_child and of right_child is set to this node.

Parameters#

parentBinTreeNode, optional

The parent of the node.

left_childBinTreeNode, optional

The left child of the node.

right_childBinTreeNode, optional

The right child of the node.

Attributes#

parentBinTreeNode or None

The parent of the node. If parent is None then the node has no parent.

left_childBinTreeNode or None

The left child of the node. If left_child is None then the node has no left child.

right_childBinTreeNode or None

The right child of the node. If right_child is None then the node has no right child.

Methods

children()

Return the list of children of this node

copy()

Create a new BinTreeNode (note: this is a kind of abstract base function)

copy_subtree()

Copy the subtree starting at this node

copy_subtree_into_children()

Replace each child by a copy of the subtree starting at this node

detach()

Detach the node by removing its pointer to its parent and the parents pointer to it

from_indicator_matrix()

Turn an indicator matrix back into a binary tree

is_leaf()

Whether this node is a leaf

leaves_in_subtree()

Find all leaves in the binary tree

level()

Returns the level of this node

level_in_subtree()

Return all the nodes at a certain depth below this node

path_from_root_indicator()

Returns the list of sides one has to take to go from the root to this node

set_left_child()

Set the left child of the node

set_right_child()

Set the right child of the node

to_indicator_matrix()

Turn a list of nodes into an indicator matrix