7. Implement Binary Search Tree ADT using Linked List
7. Implement Binary Search Tree ADT using Linked List
7
Aim: Implement Binary Search Tree ADT using Linked List.
LO: LO4: Students will be able to select appropriate searching techniques for given problems
Theory: A binary tree is a tree data structure in which each node has at most two children, which are
referred to as the left child and the right child. Every node excluding a root in a tree is connected by a
directed edge from exactly one other node. This node is called a parent. On the other hand, each node
can be connected to arbitrary number of nodes, called children. Nodes with no children are called
leaves, or external nodes. Nodes which are not leaves are called internal nodes. Nodes with the same
parent are called siblings.
The depth of a node is the number of edges from the root to the node.
The height of a node is the number of edges from the node to the deepest leaf.
The height of a tree is a height of the root.
A full binary tree.is a binary tree in which each node has exactly zero or two children.
A complete binary tree is a binary tree, which is completely filled, with the possible exception
of the bottom level, which is filled from left to right.
Binary Search tree is a binary tree in which each internal node x stores an element such that the
element stored in the left subtree of x are less than or equal to x and elements stored in the right
subtree of x are greater than or equal to x. This is called binary-search-tree property.
Program:
#include <stdio.h>
#include <malloc.h>
struct node {
char data;
};
char array[ ] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', '\0', '\0', 'H' };
void main() {
root = constructTree( 0 );
inorder(root);
if (index != -1) {
temp->data = array[index];
return temp;
}
if (root != NULL) {
inorder(root->left);
printf("%c\t", root->data);
inorder(root->right);
Output:
Conclusion: We have implemented Binary Search Tree ADT using Linked List.