This preview shows pages 1–3. Sign up to view the full content.
1
Binary Trees
•
A
tree
is a data structure that is made of nodes and
pointers, much like a linked list. The difference
between them lies in how they are organized:

In a linked list each node is connected to one
“successor” node (via next pointer), that is, it is
linear.

In a tree, the nodes can have several next
pointers and thus are not linear.
•
The top node in the tree is called the
root
and all
other nodes branch off from this one.
•
Every node in the tree can have some number of
children. Each child node can in turn be the parent
node to its children and so on.
•
A common example of a tree structure is the binary
tree.
Definition:
A
binary tree
is a tree that is limited
such that each node has only two children.
2
Examples
:
•
The following are NOT binary trees:
root
root
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document3
Definitions:
•
If n1 is the root of a binary tree and n2 is the root of its
left or right tree, then n1 is the
parent
of n2 and n2 is the
left
or
right child
of n1.
•
A node that has no children is called a
leaf
.
•
The nodes are
siblings
if they are left and right children
of the same parent.
•
The level of a node in a binary tree:

The root of the tree has level 0

The level of any other node in the tree is one more
than the level of its parent.
Exercise
: Construct all possible 5 binary trees with 3
nodes.
root
Level 0
Level 1
Level 2
Level 3
4
Implementation
•
A binary tree has a natural implementation in linked
storage. A separate pointer is used to point the tree (e.g.
root)
This is the end of the preview. Sign up
to
access the rest of the document.