0% found this document useful (0 votes)
34 views1 page

Trees

Trees are a nonlinear data structure with nodes connected by edges in a hierarchical fashion. The root node sits at the top with child nodes below and leaf nodes at the bottom without children. Each node contains data and links to other nodes. Binary trees further restrict nodes to have no more than two children each. They are implemented in memory with each binary node reserving space for data and two pointers to children.

Uploaded by

rajk2kin
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views1 page

Trees

Trees are a nonlinear data structure with nodes connected by edges in a hierarchical fashion. The root node sits at the top with child nodes below and leaf nodes at the bottom without children. Each node contains data and links to other nodes. Binary trees further restrict nodes to have no more than two children each. They are implemented in memory with each binary node reserving space for data and two pointers to children.

Uploaded by

rajk2kin
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

Trees: The Abstract View

Another common nonlinear data structure is the tree.

In this diagram above, we can see that the starting point, or the root node, is circled in blue colour. A node is a simple
structure that holds data and links to other nodes. In this case, our root node contains the data string "John" and three
links to the other nodes. Notice that the group of nodes circled in red do not have any links(childs). These nodes are at
the end of the branches and they are appropriately called as leaves or leaf nodes. In our diagram, the nodes are
interconnected with solid black lines called arcs or edges. These edges show the relationships between the nodes in the
tree.

One important relationship in the binary tree is the parent-child relationship. Parent nodes have at least one edge to the
node lower in the tree. This lower node is called the child node. Nodes can have more than one child, but the children
can only have a single parent. Notice that the root node has no parent, and the leaf nodes has no children. Final feature
to note in our diagram is the subtree. At each level of the tree, we can see that the tree structure is repeated. For
example, the two nodes representing "Charles" and "Rick" compose a very simple tree with "Charles" as the root node
and and "Rick" as a single leaf node.

Trees are implemented in the computer's memory. We will begin by introducing the simple tree structure called the
binary tree. Binary trees have the restriction that nodes can't have more than two children. With this restriction, we can
easily determine how to represent a single binary node in the memory. Our node will need to reserve memory for the
data and two pointers(for pointing two childs of that node).
Structure of a binary node:
Using our binary nodes, we can construct a binary tree. In the data cell of each node, we will can store a letter. The
physical representation of our tree might look something like the figure below:

You might also like