Trees are a fundamental abstract data structure in computer science used to represent hierarchical relationships between elements. They consist of nodes connected by edges. This lesson will introduce the basics of trees, including their terminology and structure.
To effectively discuss trees, it's important to understand the specific terms used to describe their components and characteristics:
1
has no incoming edges, but two outgoing edges that point to nodes 2
and 5
. Node 5
has one incoming edge from node 1
, and no outgoing edges.
1
is the root.
2
is the parent of nodes 3
and 4
. A child node is one that is the continuation of a branch (an incoming edge) from a parent node, so nodes 3
and 4
are children of node 2
.
3
, 4
, and 5
are leaf nodes as they have no children.
0
. The height of the tree is the level of the deepest node or the longest path from the root to a leaf node. In this case, the height is 2
.
In the following assignment, we will delve into a specific type of tree called the Binary Tree.