170 likes | 279 Views
Trees are powerful non-linear data structures comprising nodes and directed branches that connect them. The fundamental components of a tree include the root, subtrees, leaves, and internal nodes, with essential concepts like node degree and paths. Binary trees, a specific type, have a maximum of two subtrees per node. This overview covers basic terminology, properties, and various traversals associated with tree data structures, offering insights into their applications in file storage, compiler design, text processing, and searching algorithms.
E N D
Tree Concepts • A tree are very flexible, versatile and powerful non-liner data structure that consists of finite set of elements, called nodes, and a finite set of directed lines called branches, that connect the nodes. • A tree is a data structure. It is used for • storing files • compiler design • text processing • searching algorithms 1
A starting node called root. • The rest of nodes can be split into T1, T2, -, Tn, which are subtrees of the root.
Basic Terminology • Degree Of Node :- Number of sub trees for that node • 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. • A node is a parent if it has successors nodes; that is, if it has outdegree greater than zero. • A node with a predecessor is called a child. • A pathis a sequence of nodes in which each node is adjacent to the next node.
A node 1 degree 3 children E C B siblings B, D D 2 E F H I J 3 G parent B ancestors A, D, H M 4 L K leaf height or depth tree = maximum level of any node in the tree = 4 degree of a tree = maximum of the degree of the nodes = 3
When the branch is directed toward the node, it is indegreebranch. • When the branch is directed away from the node, it is an outdegreebranch. • If the tree is not empty, the first node is called the root. • Node degree=number of output paths for it. 6
Binary Trees • A binary tree is a finite set of nodes that is either empty or consists of a root and two disjoint binary trees called the left subtree and the right subtree. • A binary tree can have no more than two descendents. In this section we discuss the properties of binary trees, four different binary tree traversals • Properties • Binary Tree Traversals • Expression Trees 9
Binary Trees • A binary tree is a tree in which no node can have more than two subtrees; the maximum outdegree for a node is two. • In other words, a node can have zero, one, or two subtrees. • These subtrees are designated as the left subtree and the right subtree. 10