Chapter 3 - Nonlinear Data Structures - Trees
Chapter 3 - Nonlinear Data Structures - Trees
Root Node:The root node is the topmost node in the tree hierarchy.
Sub Tree: If the root node is not null, the tree T1,T2 and T3 is called sub-trees of the root node.
Leaf Node:The node of tree, which doesn't have any child node, is called leaf node.
Path: The sequence of consecutive edges is called path. In the tree shown in the above image, path to
the node E is A→ B → E.
Ancestor node:An ancestor of a node is any predecessor node on a path from root to that node.
Degree: Degree of a node is equal to number of children, a node has.
Level Number: Each node of the tree is assigned a level number in such a way that each node is
present at one level higher than its parent. Root node of the tree is always present at level 0.
Give the preorder, inorder and postorder traversals given the following Trees:
Searching in BST. If the tree is empty, then the target key is not in the tree. If the target key is
found in the root item then the target key is found in the root item. If the target key is
smaller than the root’s key then search the left subtree, otherwise search the right subtree.
Insertion on BST. If the tree is empty, then insert the new item in the tree’s root node. If the
root’s key matches the new item’s key then skip insertion. If the new item’s key is smaller
than the root’s key, then insert the new item in the root’s left subtree. Otherwise insert the
new item in the root’s right subtree.
Deletion on BST. First, we find the deletion node p. Find the successor node of p . Replace
the content of node p with the content of the successor node Delete the successor node.
Create the binary search tree using the following data elements.
− 43, 10, 79, 90, 12, 54, 11, 9, 50
AVL Tree is invented by GM Adelson - Velsky and EM Landis in 1962. The tree is
named AVL in honour of its inventors. AVL Tree can be defined as height balanced
binary search tree in which each node is associated with a balance factor which is
calculated by subtracting the height of its right sub-tree from that of its left sub-tree.
Tree is said to be balanced if balance factor of each node is in between -1 to 1,
otherwise, the tree will be unbalanced and need to be balanced.
A Tree is a recursive data structure containing the set of one or more data nodes
where one node is designated as the root of the tree while the remaining nodes are
called as the children of the root.
A tree can be a general tree, forests, binary tree, binary search tree, expression tree
and tournament tree.
Binary Tree is a special type of generic tree in which, each node can have at most two
children.
A tree can be traversed preorder, inorder and postorder traversal.
CHAPTER 3: NONLINEAR DATA STRUCUTURES - TREES Sunday, 19 February 2023 26
SUMMARY CONT…
A binary can be represented using linked (linked list) and sequential (array) representation.
Binary Search tree can be defined as a class of binary trees, in which the nodes are arranged
in a specific order.This is also called ordered binary tree.
BST has an algorithm in Searching, Insertion and Deletion of nodes.
AVL Tree is a height balanced binary search tree in which each node is associated with a
balance factor which is calculated by subtracting the height of its right sub-tree from that of
its left sub-tree.
Balancing an AVL tree includes 4 operations, these are: LL Rotation, RR Rotation, LR Rotation
and RL Rotation.