Binary trees Flashcards
Node
A node is a fundamental part of a tree. It can have a name, which we call the key. A node may also have additional information. We call this additional information the value or payload. While the payload information is not central to many tree algorithms, it is often critical in applications that make use of trees.
Edge
An edge is another fundamental part of a tree. An edge connects two nodes to show that there is a relationship between them. Every node (except the root) is connected by exactly one incoming edge from another node. Each node may have several outgoing edges.
Root
The root of the tree is the only node in the tree that has no incoming edges. In Figure 2, / is the root of the tree.
Path
A path is an ordered list of nodes that are connected by edges.
Children
The set of nodes that have incoming edges from the same node are said to be the children of that node.
Parent
A node is the parent of all the nodes it connects to with outgoing edges.
Sibling
Nodes in the tree that are children of the same parent are said to be siblings.
Si tree
A subtree is a set of nodes and edges comprised of a parent and all the descendants of that parent.
Leaf Node
A leaf node is a node that has no children.
Level
The level of a node n is the number of edges on the path from the root node to n.
Height
The height of a tree is equal to the maximum level of any node in the tree.
BinaryTree()
BinaryTree() creates a new instance of a binary tree.
get_root_val()
get_root_val() returns the object stored in the current node.
set_root_val(val)
set_root_val(val) stores the object in parameter val in the current node.
get_left_child()
get_left_child() returns the binary tree corresponding to the left child of the current node.