What are trees in Data Structure?
What are
Trees in Data Structure?
Trees are a type of data structure that
represents hierarchical data. Trees are
the type of non-linear data structure that consists of nodes. All the nodes of
the trees are connected by an edge. In the linear data structure, the
complexity of an operation increases with the increasing size of data. However,
in tree data structure you can get quick access to the data which is
non-linear. Trees include various types
of data structures and algorithms, which makes the task performance easy and
efficient.
Terminologies
associated with trees in the data structure are:
· Node: A node in Data structure contains a value or a key and pointers to its child nodes.
· Child node: A child node is connected to its parent node. The left child node has a value smaller than the parent node and the right child node has a value larger than the parent node.
· Leaf nodes: Leaf nodes are also called extreme nodes. Leaf nodes do not have any child nodes. They are the bottom-most nodes in a tree.
· Root: It is the topmost node of a tree.
· Internal node: The internal node has at least one child node.
· Edge: An edge is an entity that refers to the connection between any two nodes in a tree.
· Height of a node: The height of a node refers to the height of the edges from the node to the deepest leaf.
· Depth of a node: Depth refers to the depth of edges from the root to the node.
· Height of a tree: Height of the root node.
· Degree of a node: Total number of branches to that node.
· Forest: A collection of disjoint trees.
What are
types of trees in data structure
1. Binary
tree
A binary tree is a type of tree in a data
structure in which each parent node has at least two child nodes. Each node in
a binary tree can have 0, 1, or 2 nodes. Leaf nodes have null pointers on both
right and left parts.
Properties
of a binary tree
· The maximum number of nodes at each level of I is 2 i.
· At height h, the maximum number of possible nodes at height h is 2h+1 -1.
· The minimum number of nodes possible at height h is equal to h+1.
· A minimum number of nodes will represent a tree with maximum height and vice versa.
Binary
trees are divided into two parts.
Full
Binary tree: It is a type of binary tree in which
every parent node or an internal node has either two child or no child nodes.
Perfect
binary tree: In this type of tree data structure,
every internal node has exactly two child nodes and all the leaf nodes are at
the same level. Each internal node has exactly two child nodes and all the leaf
nodes have the same level.
Complete
binary tree: Complete binary has features of a full
binary tree with a few differences.
· Every level of a node is completely filled.
· The leaf nodes lean towards the left of the tree.
· It is not necessary for the last leaf node to have the right sibling. It means that a complete binary tree doesn’t have to be a full binary tree.
Degenerate
or Pathological Tree: These trees have a single
child. The child node can be either to the left or right of the parent node.
Skewed
binary tree: Skewed binary tree is a degenerate or
pathological tree where the tree is dominated by either the left nodes or the
right nodes. That is why there are two types of skewed binary trees which are
the left-skewed binary tree and the right-skewed binary tree.
Balanced
binary tree: In a balanced binary tree the
difference between the height of the left and right subtree for each node is
either 0 or 1.
Binary
search tree:
Binary search trees are non-linear and one
node is connected to a number of nodes. The node can be connected to a maximum
of two child nodes. They are called binary search trees because:
· Each node has a maximum of two child nodes.
· In a Binary search tree, it takes 0(log(n)) time to search an element and is hence known as a search tree.
If you want to learn more about types of
trees in a data structure, visit India’s leading educational platform, Help me
study Bro. Help me study Bro is the best and most trusted platform for everyone
who wants to learn data structure in a very efficient way. The website covers all the topics of data structure
including types of trees in datastructure, types of binary search tree, hashing problems, and
solutions, stacks, queues, and many others.
Help me study Bro provides all the study
materials related to Data Structure topics that are useful in competitive exams
and interviews of IT companies. So, if you want to learn data structure in a
very easy manner, connect Help me study bro.
Comments
Post a Comment