Docsity

Binary Search Trees: Data Organization and Traversal Techniques for Quick Search, Assignments of Data Structures and Algorithms

Toggle sidebar
bg1
BINARY SEARCH TREE
Binary search tree also known as BST is a special kind of binary tree that is efficient to organize
data for quick search. It is a collection of nodes with edges that connect them. The nodes are
organized in two levels. The top-level is called the root node. Each node can have a parent node
and a child node. All the nodes of the left sub-tree must be lesser than the root node and the
value of all the nodes in the right sub-tree must be greater than the root node. Each node can
have at most two children. Nodes which don’t have any child is called leaf node. In BST, node’s
left child must have value less than its parent value and node’s right child must have value
greater than its parent value.
Root Edge
Parent
Child Leaf
BST OPERATIONS:
Traversal Operation in BST:
Tree is not a linear data structure like an array or a linked list therefore; it can be traversed in
many ways. We broadly classify traversal into two ways:
The breadth first traversal
The depth first traversal.
These techniques are general ways of traversing.
The breadth first traversal:
It is also known as level order traversal. It refers to traversing the tree nodes in a level by level
fashion. Let’s see it with example.
18
23
15
27201712
A
CB
E
D
pf3

Partial preview of the text

Download Binary Search Trees: Data Organization and Traversal Techniques for Quick Search and more Assignments Data Structures and Algorithms in PDF only on Docsity!

BINARY SEARCH TREE

Binary search tree also known as BST is a special kind of binary tree that is efficient to organize data for quick search. It is a collection of nodes with edges that connect them. The nodes are organized in two levels. The top-level is called the root node. Each node can have a parent node and a child node. All the nodes of the left sub-tree must be lesser than the root node and the value of all the nodes in the right sub-tree must be greater than the root node. Each node can have at most two children. Nodes which don’t have any child is called leaf node. In BST, node’s left child must have value less than its parent value and node’s right child must have value greater than its parent value. Root Edge Parent Child Leaf

BST OPERATIONS:

Traversal Operation in BST:

Tree is not a linear data structure like an array or a linked list therefore; it can be traversed in many ways. We broadly classify traversal into two ways:  The breadth first traversal  The depth first traversal. These techniques are general ways of traversing. The breadth first traversal: It is also known as level order traversal. It refers to traversing the tree nodes in a level by level fashion. Let’s see it with example.

A

B C

D E

Depth first traversal has further categories. It can be preorder traversal, post order traversal and inorder traversal.

Application of binary search tree:

Multidimensional Binary Search Trees in Database: Binary search tree is used to

store very large data efficiently. It is very suitable tool that allow database to respond number of different kind of queries to be answered rapidly. Designers used the concept of b-tree in database to retrieve the records from the disk to the database.  Use of B+ tree in database: B+ tree used to store very large database and it is very similar to b-tree. The only difference of b+ tree is that the leaf nodes denotes actual pointer. All leaf nodes remain at same height and they are linked using linked list. The internal nodes just store keys. Data records are only stored in leaf nodes that’s why we b+ tree is used instead of b-tree. It also occupies more space than b-tree.

Internal node