SlideShare a Scribd company logo
Digital Search Tree
Presented By 
Nayeem Hasan 
ID: 2013-1-60-066 
S.M.Sadman Sadid 
ID: 2013-1-60-065 
Tanzim Rizwan 
ID: 2013-1-60-063 
Department of Computer Science & Engineering 
East West University 
Slide: 1
OVERVIEW 
Definition. 
Structure. 
Application. 
Insertion. 
Search. 
Deletion. 
Slide: 2
What is DST? 
Definition 
Digital search tree is one kind of binary tree which 
contains only binary data. 
If the bit of DST starts with 0 then it is in left subtree and if 
the bit starts with 1 then it is in right subtree and this 
process works recursively. 
Slide: 3
Simple Structure(4 bits only) 
**** 
0*** 
00** 
001* 
1*** 
10** 
100* 
11** 
110* 
Slide: 4
Digital Search Tree Example 
A 00001 
S 10011 
E 00101 
R 10010 
C 00011 
H 01000 
A 
S 
R 
E 
C H 
Slide: 5
Search Time Of DST 
Searching is based on binary representation of data. 
If the data are randomly distributed then the average 
search time per operation in O(log N), where N is the 
height of the tree. 
However, Worst case is O(b), where b is the number 
of bits in the search key. 
Slide: 6
Application Of DST 
IP routing. 
IPv4 – 32 bit IP address. 
IPv6 – 128 bit IP address. 
Firewalls. 
Slide: 7
What is IPv4 and IPv6? 
IPv4 is the fourth generation of internet protocol version and the 
most used version. 
IPv4 uses 32 bit address which divided into four 8- bit parts and 
which limits the address space to 4,294,967,296 (232 ) possible 
unique address. 
Slide: 8
IPv6 is the Internet's next-generation protocol and the current version of 
internet protocol which replace the IPv4. 
IPv6 uses 128- bit hexadecimal address which divides in 8 parts and each 
part contains 16 bit binary number and which is designed to identification 
and location system for computers on networks and routes traffic across the 
Internet. 
Slide: 9
What is firewall? 
• A firewall is a network security system, either hardware or software based, 
that controls incoming and outgoing network traffic based on a set of rules. 
• Firewall is a software program or piece of hardware that helps screen out 
hackers, viruses, and worms that try to reach your computer over the 
Internet 
Slide: 10
Insertion, search and deletion in DST are easier than 
the Binary search tree and AVL tree. 
This tree does not required additional information to 
maintain the balance of the tree because the depth of 
the tree is limited by the length of the key element. 
DST requires less memory than Binary search tree and 
AVL tree. 
Benefit Of DST 
Slide: 11
Drawbacks Of DST 
Bitwise operations are not always easy. 
Handling duplicates is problematic. 
Similar problem with keys of different lengths. 
Data is not sorted. 
If a key is long search and comparisons are costly, this 
can be problem 
Slide: 12
Insertion of DST 
 To insert an element in DST. There will be four(4) possible 
cases. 
 Tree Empty 
 If found ‘0’, then go left 
 If found ‘1’ then go right 
 If found same key, then insert with prefix equal 
Slide: 13
Insertion of DST (Cont.) 
Start with an empty 
digital search tree and 
insert a pair whose key 
is 1001 
A 
1001 
Slide: 14
Insertion of DST (Cont.) 
Start with an empty 
digital search tree and 
insert a pair whose key 
is 1001 
A 
1001 
Now, insert a pair 
whose key is 0110 
A 
1001 
B 
0110 
Slide: 15
Insertion of DST (Cont.) 
Now, insert a pair 
whose key is 1111 
A 
1001 
B 
0110 
C 
1111 
Slide: 16
Insertion of DST (Cont.) 
Now, insert a pair 
whose key is 0000 
A 
1001 
B 
0110 
C 
1111 
D 
0000 
Slide: 17
Insertion of DST (Cont.) 
Now, insert a pair 
whose key is 0100 
A 
1001 
B 
0110 
C 
1111 
D E 
0000 0100 
Slide: 18
Insertion of DST (Cont.) 
Now, insert a pair 
whose key is 0101 
A 
1001 
B 
0110 
C 
1111 
D E 
0000 0100 
0101 
G 
Slide: 19
Insertion of DST (Cont.) 
Now, insert a pair 
whose key is 1110 
A 
1001 
B 
0110 
C 
1111 
D E 
0000 0100 
0101 
G 
I 
1110 
Slide: 20
Insertion of DST (Cont.) 
Now, insert a pair 
whose key is 11 
A 
1001 
B 
0110 
C 
1111 
D E 
0000 0100 
0101 
G 
11 
F 
1110 
I 
Slide: 21
Insertion of DST (Cont.) 
Now, insert a pair 
whose key is 11 
A 
1001 
B 
0110 
C 
1111 
D E 
0000 0100 
0101 
G 
11 
F 
I 
1110 
Slide: 22
Insertion Pseudo Code of DST 
insert() 
To insert an item, with a key, k, we begin a search from the root node to 
locate the insertion position for the item. 
 if t->root is null then 
{ 
t->root = new node for the item with key k; 
return null; 
} 
p = t->root; 
i = max_b; 
Slide: 23
loop 
{ 
if p->key == k then a matching item has been found 
return p->item; 
i = i - 1; /*Traverse left or right branch, depending on the current bit.*/ 
let j be the value of the (i)th bit of k; 
if p->a[j] is null then 
{ 
p->a[j] = new node for the item with key k; 
return null; 
} 
p = p->a[j]; 
} 
Insertion Pseudo Code of DST 
Slide: 24
Insertion Pseudo Code of DST 
In the above pseudo-code, insertion fails if there is already an item with key 
k in the tree, and a pointer to the matching item will be returned. 
Otherwise, when insertion is successful, a null pointer is returned. When the 
new node, x, is created, its fields are initialized as follows. 
x->key = k; 
x->item = item; 
x->a[0] = x->a[1] = NULL; 
Slide: 25
DST search for key K 
Search 
For each node T in the tree we have 4 possible results 
T is empty 
K matches T 
Current bit of K is a 0 and go to left child 
Current bit of K is a 1 and go to right child 
Slide: 26
Example 
Search 0001 
NOT FOUND 
A 
1001 
1111 
11 
0110 
0000 0100 
0101 1110 
B 
C 
D 
E 
F 
G 
I 
Slide: 27
Search 0000 
Now 0000=D 
So K found 
1001 
1111 
11 
0110 
0000 0100 
0101 1110 
Example 
A 
B 
C 
D 
E 
F 
G 
I 
Slide: 28
Search 1110 
Now 1110=I 
So K found 
1001 
1111 
11 
0110 
0000 0100 
0101 1110 
Example 
A 
B 
C 
D 
E 
F 
G 
I 
Slide: 29
Search 0100 
Now 0100=E 
So K found 
1001 
1111 
11 
0110 
0000 0100 
0101 1110 
Example 
A 
B 
C 
D 
E 
F 
G 
I 
Slide: 30
Struct node{ 
int key,info; 
struct node *l,*r ; 
} 
static struct node *head,*z; 
unsigned bits(unsigned x, int k, int j) 
return (x>>k) & ~(~0<<j); 
Int digital_search(int v) 
{ 
struct node *x=head; 
int b=maxb; // maxb is the number of bits in the key to be sorted 
z->key=v; 
while(v!=x->key) 
x=(bits(v,b--,1) ? x->r : x->l; 
return x->info; 
} 
C code of DST Search 
Slide: 31
For each node T in the tree we have 3 possible cases. 
 No child 
 One child 
 Two children 
Delete 
Slide: 32
Example 
Delete G(0101) 
A 
1001 
1111 
11 
0110 
0000 0100 
0101 1110 
B 
C 
D 
E 
F 
G 
I 
Slide: 33
Example 
Delete G(0101) 
G has no child, 
So simply remove G 
And replace 
by a NIL pointer 
A 
1001 
1111 
11 
0110 
0000 0100 
0101 1110 
B 
C 
D 
E 
F 
G 
I 
Slide: 34
Example 
Delete F(11) 
F has one child, 
So, first remove F 
A 
1001 
1111 
11 
0110 
0000 0100 
0101 1110 
B 
C 
D 
E 
F 
G 
I 
Slide: 35
Example 
Delete F(11) 
And link C with I 
1001 
0110 1111 
0000 0100 
0101 
1110 
A 
B 
C 
D 
E 
G 
I 
Slide: 36
Example 
Delete B(0110) 
B has two children 
D(0000) and E(0100) 
1001 
0110 1111 
0000 0100 
0101 
11 
A 
B 
C 
D 
E 
G 
F 
I 
1110 
Slide: 37
Example 
Delete B(0110) 
Remove B and replace 
with one of its child 
1001 
0110 1111 
0000 0100 
0101 
11 
A 
B 
C 
D 
E 
G 
F 
I 
1110 
Slide: 38
Example 
Delete B(0110) 
Replace B with D 
1001 
0000 1111 
0100 
0101 
11 
A 
C 
D 
E 
G 
F 
I 
1110 
Slide: 39
1001 
1111 
11 
0000 
0100 
0101 
1110 
A 
C 
D 
E 
G F 
I 
Example 
Delete B(0110) 
OR 
Replace B with E 
Slide: 40
Delete Pseudo code of DST 
1.Search key 
2. if(key==Node) 
free(Node); 
if(Node->left==NULL && Node->right==NULL 
Do Nothing; 
else if(Node->left!=NULL) 
Replace Node with next left Node 
else if(Node->right!=NULL) 
Replace Node with next right Node 
else if(Node->right!=NULL && Node->left!=NULL ) 
Replace Node with next any Node 
Slide: 41
Conclusion 
The digital search trees can be recommended for use whenever 
the keys stored are integers 
Character strings of fixed width. 
DSTs are also suitable in many cases when the keys are strings 
of variable length. 
Slide: 42
THANK YOU ALL !!! 
Slide: 43

More Related Content

What's hot (20)

PDF
3b. LMD & RMD.pdf
TANZINTANZINA
 
PDF
Red black tree
Dr Sandeep Kumar Poonia
 
PPTX
AVL Tree in Data Structure
Vrushali Dhanokar
 
PPT
Data Structure and Algorithms Binary Search Tree
ManishPrajapati78
 
PPTX
Binary Search Tree in Data Structure
Dharita Chokshi
 
PPSX
Data Structure (Queue)
Adam Mukharil Bachtiar
 
PPTX
The n Queen Problem
Sukrit Gupta
 
PPTX
Linear Search Presentation
Markajul Hasnain Alif
 
PPT
String matching algorithm
Alokeparna Choudhury
 
PPTX
Binary Tree Traversal
Dhrumil Panchal
 
PPTX
Lecture 14 run time environment
Iffat Anjum
 
PDF
Array data structure
maamir farooq
 
PPTX
CLR AND LALR PARSER
Akila Krishnamoorthy
 
PPTX
Syntax-Directed Translation into Three Address Code
sanchi29
 
PPTX
Merge sort algorithm power point presentation
University of Science and Technology Chitttagong
 
PPT
Np cooks theorem
Narayana Galla
 
PPT
Symbol table management and error handling in compiler design
Swati Chauhan
 
PPTX
Backtracking
subhradeep mitra
 
PPTX
Python strings presentation
VedaGayathri1
 
3b. LMD & RMD.pdf
TANZINTANZINA
 
Red black tree
Dr Sandeep Kumar Poonia
 
AVL Tree in Data Structure
Vrushali Dhanokar
 
Data Structure and Algorithms Binary Search Tree
ManishPrajapati78
 
Binary Search Tree in Data Structure
Dharita Chokshi
 
Data Structure (Queue)
Adam Mukharil Bachtiar
 
The n Queen Problem
Sukrit Gupta
 
Linear Search Presentation
Markajul Hasnain Alif
 
String matching algorithm
Alokeparna Choudhury
 
Binary Tree Traversal
Dhrumil Panchal
 
Lecture 14 run time environment
Iffat Anjum
 
Array data structure
maamir farooq
 
CLR AND LALR PARSER
Akila Krishnamoorthy
 
Syntax-Directed Translation into Three Address Code
sanchi29
 
Merge sort algorithm power point presentation
University of Science and Technology Chitttagong
 
Np cooks theorem
Narayana Galla
 
Symbol table management and error handling in compiler design
Swati Chauhan
 
Backtracking
subhradeep mitra
 
Python strings presentation
VedaGayathri1
 

Viewers also liked (20)

PPTX
Application of tries
Tech_MX
 
PPT
Fundamental File Processing Operations
Rico
 
PPTX
Tries - Tree Based Structures for Strings
Amrinder Arora
 
PPTX
Hashing Technique In Data Structures
SHAKOOR AB
 
DOC
Advance data structure
ashok kumar
 
PDF
Lecture storage-buffer
Klaas Krona
 
PPT
Avl trees
ppreeta
 
PPTX
B tree short
Nikhil Sharma
 
PPTX
Introduction to statistics ii
Strand Life Sciences Pvt Ltd
 
PDF
Introduction of suffix tree
Liou Shu Hung
 
PPT
Packet forwarding in wan.46
myrajendra
 
PPT
06 file processing
Issay Meii
 
PPTX
Binary Search Trees - AVL and Red Black
Amrinder Arora
 
PPT
Avl trees
Mohd Arif
 
PPTX
AVL Tree
Chhatra Thapa
 
PPT
Trie tree
Shakil Ahmed
 
PPTX
Suffix Tree and Suffix Array
Harshit Agarwal
 
PPTX
Data structure tries
Md. Naim khan
 
PPTX
File Structure Concepts
Dileep Kodira
 
Application of tries
Tech_MX
 
Fundamental File Processing Operations
Rico
 
Tries - Tree Based Structures for Strings
Amrinder Arora
 
Hashing Technique In Data Structures
SHAKOOR AB
 
Advance data structure
ashok kumar
 
Lecture storage-buffer
Klaas Krona
 
Avl trees
ppreeta
 
B tree short
Nikhil Sharma
 
Introduction to statistics ii
Strand Life Sciences Pvt Ltd
 
Introduction of suffix tree
Liou Shu Hung
 
Packet forwarding in wan.46
myrajendra
 
06 file processing
Issay Meii
 
Binary Search Trees - AVL and Red Black
Amrinder Arora
 
Avl trees
Mohd Arif
 
AVL Tree
Chhatra Thapa
 
Trie tree
Shakil Ahmed
 
Suffix Tree and Suffix Array
Harshit Agarwal
 
Data structure tries
Md. Naim khan
 
File Structure Concepts
Dileep Kodira
 

Similar to Digital Search Tree (20)

PPTX
Digital Search Tree
SM. Aurnob
 
PPTX
Digital search tree
Mahmudul Hasan
 
PDF
Basics in algorithms and data structure
Eman magdy
 
PPT
Lecture 7-BinarySearchTrees.ppt
DrBashirMSaad
 
PPTX
Binary Search Tree
sagar yadav
 
PPTX
8.binry search tree
Chandan Singh
 
PPT
Chapter 9 ds
Hanif Durad
 
PPTX
Lecture 9 data structures and algorithms
Aakash deep Singhal
 
PDF
01_trees dsa pitt lololololololololo.pdf
wyf2tmczgd
 
PPTX
Introduction of Searching in data structure & its types.
SwatiShinde79
 
PDF
Tree
maamir farooq
 
PPT
BINARY TREE REPRESENTATION.ppt
SeethaDinesh
 
PPTX
Data Structures and Agorithm: DS 10 Binary Search Tree.pptx
RashidFaridChishti
 
PPTX
UNIT III Non Linear Data Structures - Trees.pptx
VISWANATHAN R V
 
PPTX
UNIT 2 TREES & GRAPH COMPLETE NOTES OF DATA STRUCTURE
sahadevbkbiet2023
 
PPT
Data Structures 8
Dr.Umadevi V
 
PDF
BinarySearchTree-bddicken
Benjamin Dicken
 
PDF
Unit iv data structure-converted
Shri Shankaracharya College, Bhilai,Junwani
 
PPT
Binary Search Tree
Zafar Ayub
 
PPT
Binary search tree(bst)
Hossain Md Shakhawat
 
Digital Search Tree
SM. Aurnob
 
Digital search tree
Mahmudul Hasan
 
Basics in algorithms and data structure
Eman magdy
 
Lecture 7-BinarySearchTrees.ppt
DrBashirMSaad
 
Binary Search Tree
sagar yadav
 
8.binry search tree
Chandan Singh
 
Chapter 9 ds
Hanif Durad
 
Lecture 9 data structures and algorithms
Aakash deep Singhal
 
01_trees dsa pitt lololololololololo.pdf
wyf2tmczgd
 
Introduction of Searching in data structure & its types.
SwatiShinde79
 
BINARY TREE REPRESENTATION.ppt
SeethaDinesh
 
Data Structures and Agorithm: DS 10 Binary Search Tree.pptx
RashidFaridChishti
 
UNIT III Non Linear Data Structures - Trees.pptx
VISWANATHAN R V
 
UNIT 2 TREES & GRAPH COMPLETE NOTES OF DATA STRUCTURE
sahadevbkbiet2023
 
Data Structures 8
Dr.Umadevi V
 
BinarySearchTree-bddicken
Benjamin Dicken
 
Unit iv data structure-converted
Shri Shankaracharya College, Bhilai,Junwani
 
Binary Search Tree
Zafar Ayub
 
Binary search tree(bst)
Hossain Md Shakhawat
 

More from East West University (6)

PPTX
An approach to enhancing image contrast using genetic algorithm
East West University
 
PPTX
Comparative Analysis of Distance Vector Routing & Link State Protocols
East West University
 
PDF
Simulation of food serving system of EWU canteen using Arena software
East West University
 
PDF
Right to be Forgotten
East West University
 
PDF
Wannacry Virus
East West University
 
PDF
Software piracy in Bangladesh
East West University
 
An approach to enhancing image contrast using genetic algorithm
East West University
 
Comparative Analysis of Distance Vector Routing & Link State Protocols
East West University
 
Simulation of food serving system of EWU canteen using Arena software
East West University
 
Right to be Forgotten
East West University
 
Wannacry Virus
East West University
 
Software piracy in Bangladesh
East West University
 

Recently uploaded (20)

PPTX
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 
PPTX
Numbers of a nation: how we estimate population statistics | Accessible slides
Office for National Statistics
 
PDF
Choosing the Right Database for Indexing.pdf
Tamanna
 
PDF
Web Scraping with Google Gemini 2.0 .pdf
Tamanna
 
PDF
Avatar for apidays apidays PRO June 07, 2025 0 5 apidays Helsinki & North 2...
apidays
 
PDF
OOPs with Java_unit2.pdf. sarthak bookkk
Sarthak964187
 
PDF
Data Chunking Strategies for RAG in 2025.pdf
Tamanna
 
PPT
deep dive data management sharepoint apps.ppt
novaprofk
 
PPTX
ER_Model_with_Diagrams_Presentation.pptx
dharaadhvaryu1992
 
PDF
The European Business Wallet: Why It Matters and How It Powers the EUDI Ecosy...
Lal Chandran
 
PPTX
b6057ea5-8e8c-4415-90c0-ed8e9666ffcd.pptx
Anees487379
 
PDF
Context Engineering for AI Agents, approaches, memories.pdf
Tamanna
 
PDF
Merits and Demerits of DBMS over File System & 3-Tier Architecture in DBMS
MD RIZWAN MOLLA
 
PDF
Copia de Strategic Roadmap Infographics by Slidesgo.pptx (1).pdf
ssuserd4c6911
 
PDF
apidays Helsinki & North 2025 - APIs in the healthcare sector: hospitals inte...
apidays
 
PDF
AUDITABILITY & COMPLIANCE OF AI SYSTEMS IN HEALTHCARE
GAHI Youssef
 
PPTX
recruitment Presentation.pptxhdhshhshshhehh
devraj40467
 
PDF
apidays Helsinki & North 2025 - API-Powered Journeys: Mobility in an API-Driv...
apidays
 
PPTX
Exploring Multilingual Embeddings for Italian Semantic Search: A Pretrained a...
Sease
 
PPTX
apidays Helsinki & North 2025 - From Chaos to Clarity: Designing (AI-Ready) A...
apidays
 
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 
Numbers of a nation: how we estimate population statistics | Accessible slides
Office for National Statistics
 
Choosing the Right Database for Indexing.pdf
Tamanna
 
Web Scraping with Google Gemini 2.0 .pdf
Tamanna
 
Avatar for apidays apidays PRO June 07, 2025 0 5 apidays Helsinki & North 2...
apidays
 
OOPs with Java_unit2.pdf. sarthak bookkk
Sarthak964187
 
Data Chunking Strategies for RAG in 2025.pdf
Tamanna
 
deep dive data management sharepoint apps.ppt
novaprofk
 
ER_Model_with_Diagrams_Presentation.pptx
dharaadhvaryu1992
 
The European Business Wallet: Why It Matters and How It Powers the EUDI Ecosy...
Lal Chandran
 
b6057ea5-8e8c-4415-90c0-ed8e9666ffcd.pptx
Anees487379
 
Context Engineering for AI Agents, approaches, memories.pdf
Tamanna
 
Merits and Demerits of DBMS over File System & 3-Tier Architecture in DBMS
MD RIZWAN MOLLA
 
Copia de Strategic Roadmap Infographics by Slidesgo.pptx (1).pdf
ssuserd4c6911
 
apidays Helsinki & North 2025 - APIs in the healthcare sector: hospitals inte...
apidays
 
AUDITABILITY & COMPLIANCE OF AI SYSTEMS IN HEALTHCARE
GAHI Youssef
 
recruitment Presentation.pptxhdhshhshshhehh
devraj40467
 
apidays Helsinki & North 2025 - API-Powered Journeys: Mobility in an API-Driv...
apidays
 
Exploring Multilingual Embeddings for Italian Semantic Search: A Pretrained a...
Sease
 
apidays Helsinki & North 2025 - From Chaos to Clarity: Designing (AI-Ready) A...
apidays
 

Digital Search Tree

  • 2. Presented By Nayeem Hasan ID: 2013-1-60-066 S.M.Sadman Sadid ID: 2013-1-60-065 Tanzim Rizwan ID: 2013-1-60-063 Department of Computer Science & Engineering East West University Slide: 1
  • 3. OVERVIEW Definition. Structure. Application. Insertion. Search. Deletion. Slide: 2
  • 4. What is DST? Definition Digital search tree is one kind of binary tree which contains only binary data. If the bit of DST starts with 0 then it is in left subtree and if the bit starts with 1 then it is in right subtree and this process works recursively. Slide: 3
  • 5. Simple Structure(4 bits only) **** 0*** 00** 001* 1*** 10** 100* 11** 110* Slide: 4
  • 6. Digital Search Tree Example A 00001 S 10011 E 00101 R 10010 C 00011 H 01000 A S R E C H Slide: 5
  • 7. Search Time Of DST Searching is based on binary representation of data. If the data are randomly distributed then the average search time per operation in O(log N), where N is the height of the tree. However, Worst case is O(b), where b is the number of bits in the search key. Slide: 6
  • 8. Application Of DST IP routing. IPv4 – 32 bit IP address. IPv6 – 128 bit IP address. Firewalls. Slide: 7
  • 9. What is IPv4 and IPv6? IPv4 is the fourth generation of internet protocol version and the most used version. IPv4 uses 32 bit address which divided into four 8- bit parts and which limits the address space to 4,294,967,296 (232 ) possible unique address. Slide: 8
  • 10. IPv6 is the Internet's next-generation protocol and the current version of internet protocol which replace the IPv4. IPv6 uses 128- bit hexadecimal address which divides in 8 parts and each part contains 16 bit binary number and which is designed to identification and location system for computers on networks and routes traffic across the Internet. Slide: 9
  • 11. What is firewall? • A firewall is a network security system, either hardware or software based, that controls incoming and outgoing network traffic based on a set of rules. • Firewall is a software program or piece of hardware that helps screen out hackers, viruses, and worms that try to reach your computer over the Internet Slide: 10
  • 12. Insertion, search and deletion in DST are easier than the Binary search tree and AVL tree. This tree does not required additional information to maintain the balance of the tree because the depth of the tree is limited by the length of the key element. DST requires less memory than Binary search tree and AVL tree. Benefit Of DST Slide: 11
  • 13. Drawbacks Of DST Bitwise operations are not always easy. Handling duplicates is problematic. Similar problem with keys of different lengths. Data is not sorted. If a key is long search and comparisons are costly, this can be problem Slide: 12
  • 14. Insertion of DST  To insert an element in DST. There will be four(4) possible cases.  Tree Empty  If found ‘0’, then go left  If found ‘1’ then go right  If found same key, then insert with prefix equal Slide: 13
  • 15. Insertion of DST (Cont.) Start with an empty digital search tree and insert a pair whose key is 1001 A 1001 Slide: 14
  • 16. Insertion of DST (Cont.) Start with an empty digital search tree and insert a pair whose key is 1001 A 1001 Now, insert a pair whose key is 0110 A 1001 B 0110 Slide: 15
  • 17. Insertion of DST (Cont.) Now, insert a pair whose key is 1111 A 1001 B 0110 C 1111 Slide: 16
  • 18. Insertion of DST (Cont.) Now, insert a pair whose key is 0000 A 1001 B 0110 C 1111 D 0000 Slide: 17
  • 19. Insertion of DST (Cont.) Now, insert a pair whose key is 0100 A 1001 B 0110 C 1111 D E 0000 0100 Slide: 18
  • 20. Insertion of DST (Cont.) Now, insert a pair whose key is 0101 A 1001 B 0110 C 1111 D E 0000 0100 0101 G Slide: 19
  • 21. Insertion of DST (Cont.) Now, insert a pair whose key is 1110 A 1001 B 0110 C 1111 D E 0000 0100 0101 G I 1110 Slide: 20
  • 22. Insertion of DST (Cont.) Now, insert a pair whose key is 11 A 1001 B 0110 C 1111 D E 0000 0100 0101 G 11 F 1110 I Slide: 21
  • 23. Insertion of DST (Cont.) Now, insert a pair whose key is 11 A 1001 B 0110 C 1111 D E 0000 0100 0101 G 11 F I 1110 Slide: 22
  • 24. Insertion Pseudo Code of DST insert() To insert an item, with a key, k, we begin a search from the root node to locate the insertion position for the item.  if t->root is null then { t->root = new node for the item with key k; return null; } p = t->root; i = max_b; Slide: 23
  • 25. loop { if p->key == k then a matching item has been found return p->item; i = i - 1; /*Traverse left or right branch, depending on the current bit.*/ let j be the value of the (i)th bit of k; if p->a[j] is null then { p->a[j] = new node for the item with key k; return null; } p = p->a[j]; } Insertion Pseudo Code of DST Slide: 24
  • 26. Insertion Pseudo Code of DST In the above pseudo-code, insertion fails if there is already an item with key k in the tree, and a pointer to the matching item will be returned. Otherwise, when insertion is successful, a null pointer is returned. When the new node, x, is created, its fields are initialized as follows. x->key = k; x->item = item; x->a[0] = x->a[1] = NULL; Slide: 25
  • 27. DST search for key K Search For each node T in the tree we have 4 possible results T is empty K matches T Current bit of K is a 0 and go to left child Current bit of K is a 1 and go to right child Slide: 26
  • 28. Example Search 0001 NOT FOUND A 1001 1111 11 0110 0000 0100 0101 1110 B C D E F G I Slide: 27
  • 29. Search 0000 Now 0000=D So K found 1001 1111 11 0110 0000 0100 0101 1110 Example A B C D E F G I Slide: 28
  • 30. Search 1110 Now 1110=I So K found 1001 1111 11 0110 0000 0100 0101 1110 Example A B C D E F G I Slide: 29
  • 31. Search 0100 Now 0100=E So K found 1001 1111 11 0110 0000 0100 0101 1110 Example A B C D E F G I Slide: 30
  • 32. Struct node{ int key,info; struct node *l,*r ; } static struct node *head,*z; unsigned bits(unsigned x, int k, int j) return (x>>k) & ~(~0<<j); Int digital_search(int v) { struct node *x=head; int b=maxb; // maxb is the number of bits in the key to be sorted z->key=v; while(v!=x->key) x=(bits(v,b--,1) ? x->r : x->l; return x->info; } C code of DST Search Slide: 31
  • 33. For each node T in the tree we have 3 possible cases.  No child  One child  Two children Delete Slide: 32
  • 34. Example Delete G(0101) A 1001 1111 11 0110 0000 0100 0101 1110 B C D E F G I Slide: 33
  • 35. Example Delete G(0101) G has no child, So simply remove G And replace by a NIL pointer A 1001 1111 11 0110 0000 0100 0101 1110 B C D E F G I Slide: 34
  • 36. Example Delete F(11) F has one child, So, first remove F A 1001 1111 11 0110 0000 0100 0101 1110 B C D E F G I Slide: 35
  • 37. Example Delete F(11) And link C with I 1001 0110 1111 0000 0100 0101 1110 A B C D E G I Slide: 36
  • 38. Example Delete B(0110) B has two children D(0000) and E(0100) 1001 0110 1111 0000 0100 0101 11 A B C D E G F I 1110 Slide: 37
  • 39. Example Delete B(0110) Remove B and replace with one of its child 1001 0110 1111 0000 0100 0101 11 A B C D E G F I 1110 Slide: 38
  • 40. Example Delete B(0110) Replace B with D 1001 0000 1111 0100 0101 11 A C D E G F I 1110 Slide: 39
  • 41. 1001 1111 11 0000 0100 0101 1110 A C D E G F I Example Delete B(0110) OR Replace B with E Slide: 40
  • 42. Delete Pseudo code of DST 1.Search key 2. if(key==Node) free(Node); if(Node->left==NULL && Node->right==NULL Do Nothing; else if(Node->left!=NULL) Replace Node with next left Node else if(Node->right!=NULL) Replace Node with next right Node else if(Node->right!=NULL && Node->left!=NULL ) Replace Node with next any Node Slide: 41
  • 43. Conclusion The digital search trees can be recommended for use whenever the keys stored are integers Character strings of fixed width. DSTs are also suitable in many cases when the keys are strings of variable length. Slide: 42
  • 44. THANK YOU ALL !!! Slide: 43