BinaryTree BST
BinaryTree BST
Objectives
Upon completion you will be able to
A node is a parent if it has successor nodes—that is, if it has an outdegree greater than
zero.
An ancestor is any node in the path from the root to the node.
A descendant 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 descendants of that node.
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.
The level of a node is its distance from the root. Because the root has a zero distance
from itself, the root is at level 0.
Data Structures: A Pseudocode Approach with C 6
Data Structures: A Pseudocode Approach with C 7
The height of the tree is the level of the leaf in the longest path from the root plus 1.
A tree may be divided into subtrees. A subtree is any connected structure below the
root. The first node in a subtree is known as the root of the subtree and is used to name
the subtree.
Maximum Height
Given that we need to store N nodes in a binary tree, the maximum height,
Hmax, is
Minimum
Height
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 the depth-first traversal, the processing proceeds along a path from the root
through one child to the most distant descendent of that first child before processing a
second child. In other words, in the depth-first traversal, we process all of the
descendants of a child before going on to the next child.
return (node);
}
}
}
Data Structures: A Pseudocode Approach with C 24
Postorder Traversal (LRN)
The last of the standard traversals is the postorder
traversal. It processes the root node after (post) the left and
right subtrees have been processed. It starts by locating the
far-left leaf and processing it. It then processes its right
sibling,
including its subtrees (if any). Finally, it processes the root
node.
/* frunction prototypes */
struct node** createQueue(int*, int*);
void enQueue(struct node**, int*, struct node*);
struct node* deQueue(struct node**, int*);
while (temp_node) {
printf("%d ", temp_node->data);
35
Construct Binary Tree from given Inorder and Preorder
traversals
Let us consider the below traversals:
Preorder sequence: A B D E F C G H J L K
Inorder sequence: D B E F A G C L J H K
The binary search tree and the AVL tree provide that
structure
Data Structures: A Pseudocode Approach with C 38
BINARY SEARCH TREE (BST)
Traversals
Searches
• Find the Smallest Node
• Find the Largest Node
• BST Search
Insertion
Deletion