trees
trees
UNIT-4
Topic : Trees
TREES
Introduction to Trees
• The study of trees in mathematics can be traced to Gustav Kirchhoff in the
middle nineteenth century and several years later to Arthur Cayley, who
used trees to study the structure of algebraic formulas.
• Cayley’s work undoubtedly laid the framework for Grace Hopper’s use of
trees in 1951 to represent arithmetic expressions.
• Hopper’s work bears a strong resemblance to today’s binary tree formats.
• Trees are used extensively in computer science to represent algebraic
formulas;
• as an efficient method for searching large, dynamic lists; and for such
diverse applications as artificial intelligence systems and encoding
algorithms.
Basic Tree Concepts
• A leaf is any node with an outdegree of zero, that is, a node with no
successors.
• A node that is not a root or a leaf is known as an internal node
because it is found in the middle portion of a tree.
• A node is a parent if it has successor nodes—that is, if it has an
outdegree greater than zero.
• Conversely, a node with a predecessor is a child.
• A child node has an indegree of one.
• Two or more nodes with the same parent are siblings
• An ancestor is any node in the path from the root to the node.
• A descendent is any node in the path below the parent node; that is,
all nodes in the paths from a given node to a leaf are descendents of
that node
PATH
• Several terms drawn from mathematics or
created by computer scientists are used to
describe attributes of trees and their nodes
• A path is a sequence of nodes in which
each node is adjacent to the next one.
• Every node in the tree can be reached by
following a unique path starting from the
root.
• In Figure 6-2 the path from the root to the
leaf I is designated as AFI.
• It includes two distinct branches, AF and FI.
LEVEL
• A complete tree has the maximum number of entries for its height (see
formula
Nmax in “Height of Binary Trees”). The maximum number is reached when
the
last level is full (see Figure 6-7). A tree is considered nearly complete if it
has the
minimum height for its nodes (see formula Hmin) and all nodes in the last
level are found on the left. Complete and nearly complete trees are shown
in
Figure 6-7.
Binary Tree Traversals
• A binary tree traversal requires that each node of the tree be
processed once and only once in a predetermined sequence.
• The two general approaches to the traversal sequence are depth first
and breadth first.
• In a breadth-first traversal, the processing proceeds horizontally from
the root to all of its children, then to its children’s children, and so
forth until all nodes have been processed. In other words, in the
breadth-first traversal, each level is completely processed before the
next level is started.
Depth-first Traversals
• Given that a binary tree consists of a root, a left subtree, and a right
subtree,we can define six different depth-first traversal sequences.
Binary Search Trees-Basic Concepts