Sie sind auf Seite 1von 24

1

2
3
4
Definition and Applications of
Binary Trees
• A binary tree is a non-linear linked list where each node
may point to two other nodes.

5
Definition and Applications of
Binary Trees
• It is anchored at the top by a tree pointer,
which is like the head pointer in a linked
list.
• The first node in the list is called the root
node.
• The root node has pointers to two other
nodes, which are called children, or child
nodes.

6
Definition and Applications of
Binary Trees
• A node that has no children is called a leaf
node.
• All pointers that do not point to a node are
set to NULL.

7
Definition and Applications of
Binary Trees
• Binary trees can be divided into subtrees. A
subtree is an entire branch of the tree, from
one particular node down.

8
Definition and Applications of
Binary Trees
• Binary trees are excellent data structures for
searching large amounts of information.
They are commonly used in database
applications to organize key values that
index database records.
• When used to facilitate searches, a binary
tree is called a binary search tree.

9
Definition and Applications of
Binary Trees
• Information is stored in binary search trees in a
way that makes a binary search simple. For
example, look at Figure.

Values are stored in a binary tree so


that a node's left child holds data
whose value is less than the node's
data, and the node's right child holds
data whose value is greater tan the
node's data.

10
Definition and Applications of
Binary Trees
• It is also true that all the nodes to the left of a node
hold values less than the node's value. Likewise,
all the nodes to the right of a node hold values that
are greater than the node's data.
• When an application is searching a binary tree, it
starts at the root node. If the root node does not
hold the search value, the application branches
either to the left or right child, depending on
whether the search value is less than or grater than
the value at the root node.
11
Traversing the Tree
• There are three common methods for
traversing a binary tree and processing the
value of each node:
– inorder
– preorder
– postorder
• Each of these methods is best implemented
as a recursive function.

12
Inorder Traversal

13
Preorder Traversal

14
Postorder Traversal

15
16
17
18
19
20
21
22
23
24

Das könnte Ihnen auch gefallen