0% found this document useful (0 votes)
41 views

Binary Search Trees: By-Vidushi Parashar MCA A1000713025

Binary search trees have the following properties: 1) They are a type of binary tree where each node has at most two children. 2) The value in each node is greater than all values in its left subtree and less than all values in its right subtree. 3) Searching for a value in a binary search tree involves recursively comparing the target value to the value of each node and traversing left or right. 4) Common operations on binary search trees include searching to find a node matching a target value.

Uploaded by

Saurabh Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Binary Search Trees: By-Vidushi Parashar MCA A1000713025

Binary search trees have the following properties: 1) They are a type of binary tree where each node has at most two children. 2) The value in each node is greater than all values in its left subtree and less than all values in its right subtree. 3) Searching for a value in a binary search tree involves recursively comparing the target value to the value of each node and traversing left or right. 4) Common operations on binary search trees include searching to find a node matching a target value.

Uploaded by

Saurabh Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Binary search trees

By- Vidushi Parashar


MCA
A1000713025
A Taxonomy of Trees
General Trees any number of children /
node

Binary Trees max 2 children / node

Heaps parent < (>) children

Binary Search Trees



Binary Trees
Binary search tree
Every element has a unique key.
The keys in a nonempty left sub tree (right sub
tree) are smaller (larger) than the key in the
root of subtree.

63
41
89
34 56
72 95
the values in all nodes in the left subtree of a node are less than
the node value
the values in all nodes in the right subtree of a node are greater
than the node values
Organization Rule for BST
Binary Tree
typedef struct tnode *ptnode;
typedef struct node {
short int key;
ptnode right, left;
} ;

Searching in the BST
method search(key)
implements the binary search based on comparison of the items
in the tree
the items in the BST must be comparable (e.g integers, string, etc.)

The search starts at the root. It probes down, comparing the
values in each node with the target, till it finds the first item equal
to the target. Returns this item or null if there is none.
BST Operations: Search
if the tree is empty
return NULL

else if the item in the node equals the target
return the node value

else if the item in the node is greater than the target
return the result of searching the left subtree

else if the item in the node is smaller than the target
return the result of searching the right subtree
Search in BST - Pseudocode
THANK YOU

You might also like