SlideShare a Scribd company logo
1 of 25
Download to read offline
Search Data Structures
Tries and K-d Trees
Index
● Introduction
○ Tree
○ Terminology
○ Efficient Search
○ Application of Tree
● Tries
○ Search Problem 1
○ Solution: Creating and Searching in Trie
○ Application of Tries
● K-d Trees
○ Search Problem 2
○ Solution : Creating a kd Tree and range Searching in kD-Tree
○ Application of K-dTree
Introduction: Tree
1. Non Linear Data structure
2. Hierarchical Structure
3. Each node of tree has links to its siblings
Introduction:Terminology
Introduction:Efficient Search
Consider an array = [1,4,5,2,3,9,10]
● Linear Search takes time = (0)n
● Binary Search :
needs to be sorted((0)n logn) + (logn)
● Binary Search Tree : (0)n
● Balanced binary search tree (0) logn
Tree can reduce the search time efficiently.
Introduction: Application of Binary Trees
● Hierarchical Data Storage eg. File System
● Paging in Memory /Indexing in Books
● Compiler: Expression trees/ Parse trees
● Sorted data representation
● Indexing in Databases
Search Problem 1
How do we search efficiently a dictionary for a particular word ?
Given Dictionary: bear, bell, bid, bull, buy, sell, stock, stop
Search Word: Stop
Can we do faster than Binary Search tree Balanced Binary search tree : (0)log n
Here n is the size of dictionary
Search Problem 1
Using Trie
Complexity = (0)m
m is size of search string
TrieNode
{
TrieNode children[ALPHABET_SIZE];
bool isLeaf;
};
Tries: Representation
Tries : Create
insert(TrieNode root, const String key){
int level;
int index;
TrieNode current = root;
for (level = 0; level < key.length; level++)
{
index = CHAR_TO_INDEX(key[level]);
if (current->children[index])
current->children[index] =new TrieNode();
current = current->children[index];
}
// mark last node as leaf
temp->isLeaf = true;
}
Tries: Search
bool search(TrieNode root, String key){
int level;
int index;
struct TrieNode current = root;
for (level = 0; level < key.length; level++)
{
index = CHAR_TO_INDEX(key[level]);
if (!current->children[index])
return false;
current = current->children[index];
}
return (current != NULL && current->isLeaf);
}
Tries: Complexity
Search
● Time Complexity : (0)m
● Space Complexity: (0)n characters + (n)links
Tries: Complexity
To reduce space complexity of links
● Compressed Trie or Radix Trees
Tries : Applications
● Auto complete functionality eg in Google search
● Phone Contacts
● Automatic Command Completion in linux terminal
● Spell Checkers in Word or gmail
● …. etc
Search Problem 2
1. From a list of Restaurants find all the restaurants where X lies between 30-40 && Y between
40-50 ?
Name X Y
R1 30 40
R2 5 25
R3 10 12
R4 50 30
R5 35 45
K-d Trees
1. A K-d Tree(also called as K-Dimensional Tree) is a binary search tree where
data in each node is a K-Dimensional point in space.
2. K is a dimension can be 2-d Tree, 3-d Tree etc.
3. Each level has cutting dimension
4. Cutting dimensions cycle as we go down the tree
5. Each node has a Point
K-d Trees: K-d Tree Operations
List of points : (30,40), (5,25), (10,12), (70,70), (50,30), (35,45)
Different type of Queries:
Search Query: search a point (10,12)
Range Query: Range Query in 2 D tree is like list all points where x>30 and y> 40
K-d Trees : Create
K-d Trees : Create
insert(Point x, KDNode t, int cd) {
if t == null t = new KDNode(x)
else if (x == t.data)
// error! duplicate
else if (x[cd] < t.data[cd])
t.left = insert(x, t.left, (cd+1) % DIM)
else
t.right = insert(x, t.right, (cd+1) % DIM)
return t
}
KDNode
{
// To store k dimensional point
int point[k];
Node *left, *right;
};
K-d Trees : Range Search
Search
X is in range 30-40
Y is in range 40-50
K-d Trees: Complexity
Insert: (0)log n, in balanced K-d tree
Search : (0) logn
K-d Trees : Applications
● Database queries involving a multidimensional search key
● Nearest neighbour search
● Clustering in Machine Learning algorithm
● Geographical Databases
Implementations
1. http://www.geeksforgeeks.org/trie-insert-and-search/
2. http://www.geeksforgeeks.org/k-dimensional-tree/
References
1. de la Briandais, René (1959). File searching using variable length keys. Proc. Western J.
Computer Conf. pp. 295–298.Cited by Brass.
2. Bentley, J. L. (1975). "Multidimensional binary search trees used for associative searching".
Communications of the ACM. 18 (9): 509. doi:10.1145/361002.361007.
3. https://link.springer.com/chapter/10.1007/978-3-642-72617-0_17
4. http://goanna.cs.rmit.edu.au/~jz/fulltext/acsc03sz.pdf
5. http://www.cs.cmu.edu/~ckingsf/bioinfo-lectures/kdtrees.pdf
Search data structures

More Related Content

What's hot

Day 7 evaluating all integers
Day 7 evaluating all integersDay 7 evaluating all integers
Day 7 evaluating all integersErik Tjersland
 
Lecture 11 data structures and algorithms
Lecture 11 data structures and algorithmsLecture 11 data structures and algorithms
Lecture 11 data structures and algorithmsAakash deep Singhal
 
Solutions on log examples
Solutions on log examplesSolutions on log examples
Solutions on log examplesKristino Ikaw
 
Product and quotent rules
Product and quotent rulesProduct and quotent rules
Product and quotent rulesLorie Blickhan
 
17. Trees and Tree Like Structures
17. Trees and Tree Like Structures17. Trees and Tree Like Structures
17. Trees and Tree Like StructuresIntro C# Book
 
Slides September 16
Slides September 16Slides September 16
Slides September 16heviatar
 
Multi dimensional arrays
Multi dimensional arraysMulti dimensional arrays
Multi dimensional arraysAseelhalees
 
Unit 1 introduction to data structure
Unit 1   introduction to data structureUnit 1   introduction to data structure
Unit 1 introduction to data structurekalyanineve
 
SMU BCA SEM 1 FALL 2016 ASSIGNMENTS
SMU BCA SEM 1 FALL 2016 ASSIGNMENTSSMU BCA SEM 1 FALL 2016 ASSIGNMENTS
SMU BCA SEM 1 FALL 2016 ASSIGNMENTSsolved_assignments
 
Unit 4 lesson 4 properties
Unit 4 lesson 4 propertiesUnit 4 lesson 4 properties
Unit 4 lesson 4 propertiesmlabuski
 
A2 Domain Homework
A2 Domain HomeworkA2 Domain Homework
A2 Domain Homeworkvhiggins1
 
Data Structures Notes 2021
Data Structures Notes 2021Data Structures Notes 2021
Data Structures Notes 2021Sreedhar Chowdam
 
Balanced trees
Balanced trees                                                Balanced trees
Balanced trees meet darji
 
Data structures (introduction)
 Data structures (introduction) Data structures (introduction)
Data structures (introduction)Arvind Devaraj
 

What's hot (17)

Day 7 evaluating all integers
Day 7 evaluating all integersDay 7 evaluating all integers
Day 7 evaluating all integers
 
Lecture 11 data structures and algorithms
Lecture 11 data structures and algorithmsLecture 11 data structures and algorithms
Lecture 11 data structures and algorithms
 
Solutions on log examples
Solutions on log examplesSolutions on log examples
Solutions on log examples
 
Product and quotent rules
Product and quotent rulesProduct and quotent rules
Product and quotent rules
 
17. Trees and Tree Like Structures
17. Trees and Tree Like Structures17. Trees and Tree Like Structures
17. Trees and Tree Like Structures
 
Slides September 16
Slides September 16Slides September 16
Slides September 16
 
Multi dimensional arrays
Multi dimensional arraysMulti dimensional arrays
Multi dimensional arrays
 
Unit 1 introduction to data structure
Unit 1   introduction to data structureUnit 1   introduction to data structure
Unit 1 introduction to data structure
 
SMU BCA SEM 1 FALL 2016 ASSIGNMENTS
SMU BCA SEM 1 FALL 2016 ASSIGNMENTSSMU BCA SEM 1 FALL 2016 ASSIGNMENTS
SMU BCA SEM 1 FALL 2016 ASSIGNMENTS
 
Data structure ppt
Data structure pptData structure ppt
Data structure ppt
 
Unit 4 lesson 4 properties
Unit 4 lesson 4 propertiesUnit 4 lesson 4 properties
Unit 4 lesson 4 properties
 
A2 Domain Homework
A2 Domain HomeworkA2 Domain Homework
A2 Domain Homework
 
Quad eqn
Quad eqnQuad eqn
Quad eqn
 
Data Structures Notes 2021
Data Structures Notes 2021Data Structures Notes 2021
Data Structures Notes 2021
 
Balanced trees
Balanced trees                                                Balanced trees
Balanced trees
 
Data structures (introduction)
 Data structures (introduction) Data structures (introduction)
Data structures (introduction)
 
Alg2 lesson 8-3
Alg2 lesson 8-3Alg2 lesson 8-3
Alg2 lesson 8-3
 

Similar to Search data structures

CS-102 BST_27_3_14v2.pdf
CS-102 BST_27_3_14v2.pdfCS-102 BST_27_3_14v2.pdf
CS-102 BST_27_3_14v2.pdfssuser034ce1
 
CS-102 BST_27_3_14.pdf
CS-102 BST_27_3_14.pdfCS-102 BST_27_3_14.pdf
CS-102 BST_27_3_14.pdfssuser034ce1
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search treeKrish_ver2
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structuresNiraj Agarwal
 
part4-trees.ppt
part4-trees.pptpart4-trees.ppt
part4-trees.pptSuneel61
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)Trupti Agrawal
 
A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)Imdadul Himu
 
Mca admission in india
Mca admission in indiaMca admission in india
Mca admission in indiaEdhole.com
 
Revision Tour 1 and 2 complete.doc
Revision Tour 1 and 2 complete.docRevision Tour 1 and 2 complete.doc
Revision Tour 1 and 2 complete.docSrikrishnaVundavalli
 
Advanced data structure
Advanced data structureAdvanced data structure
Advanced data structureShakil Ahmed
 
Lecture 4 data structures and algorithms
Lecture 4 data structures and algorithmsLecture 4 data structures and algorithms
Lecture 4 data structures and algorithmsAakash deep Singhal
 

Similar to Search data structures (20)

CS-102 BST_27_3_14v2.pdf
CS-102 BST_27_3_14v2.pdfCS-102 BST_27_3_14v2.pdf
CS-102 BST_27_3_14v2.pdf
 
CS-102 BST_27_3_14.pdf
CS-102 BST_27_3_14.pdfCS-102 BST_27_3_14.pdf
CS-102 BST_27_3_14.pdf
 
1st lecture.ppt
1st lecture.ppt1st lecture.ppt
1st lecture.ppt
 
Trees gt(1)
Trees gt(1)Trees gt(1)
Trees gt(1)
 
4.2 bst 03
4.2 bst 034.2 bst 03
4.2 bst 03
 
1.5 binary search tree
1.5 binary search tree1.5 binary search tree
1.5 binary search tree
 
Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
 
Chapter 5 ds
Chapter 5 dsChapter 5 ds
Chapter 5 ds
 
Ch02
Ch02Ch02
Ch02
 
part4-trees.ppt
part4-trees.pptpart4-trees.ppt
part4-trees.ppt
 
Trees (data structure)
Trees (data structure)Trees (data structure)
Trees (data structure)
 
8.binry search tree
8.binry search tree8.binry search tree
8.binry search tree
 
A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)
 
Mca admission in india
Mca admission in indiaMca admission in india
Mca admission in india
 
Revision Tour 1 and 2 complete.doc
Revision Tour 1 and 2 complete.docRevision Tour 1 and 2 complete.doc
Revision Tour 1 and 2 complete.doc
 
Intro.ppt
Intro.pptIntro.ppt
Intro.ppt
 
Advanced data structure
Advanced data structureAdvanced data structure
Advanced data structure
 
Trie Data Structure
Trie Data StructureTrie Data Structure
Trie Data Structure
 
Dictionaries.pptx
Dictionaries.pptxDictionaries.pptx
Dictionaries.pptx
 
Lecture 4 data structures and algorithms
Lecture 4 data structures and algorithmsLecture 4 data structures and algorithms
Lecture 4 data structures and algorithms
 

Recently uploaded

VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...Call Girls in Nagpur High Profile
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 

Recently uploaded (20)

VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 

Search data structures

  • 2. Index ● Introduction ○ Tree ○ Terminology ○ Efficient Search ○ Application of Tree ● Tries ○ Search Problem 1 ○ Solution: Creating and Searching in Trie ○ Application of Tries ● K-d Trees ○ Search Problem 2 ○ Solution : Creating a kd Tree and range Searching in kD-Tree ○ Application of K-dTree
  • 3. Introduction: Tree 1. Non Linear Data structure 2. Hierarchical Structure 3. Each node of tree has links to its siblings
  • 5. Introduction:Efficient Search Consider an array = [1,4,5,2,3,9,10] ● Linear Search takes time = (0)n ● Binary Search : needs to be sorted((0)n logn) + (logn) ● Binary Search Tree : (0)n ● Balanced binary search tree (0) logn Tree can reduce the search time efficiently.
  • 6. Introduction: Application of Binary Trees ● Hierarchical Data Storage eg. File System ● Paging in Memory /Indexing in Books ● Compiler: Expression trees/ Parse trees ● Sorted data representation ● Indexing in Databases
  • 7. Search Problem 1 How do we search efficiently a dictionary for a particular word ? Given Dictionary: bear, bell, bid, bull, buy, sell, stock, stop Search Word: Stop Can we do faster than Binary Search tree Balanced Binary search tree : (0)log n Here n is the size of dictionary
  • 8. Search Problem 1 Using Trie Complexity = (0)m m is size of search string
  • 10. Tries : Create insert(TrieNode root, const String key){ int level; int index; TrieNode current = root; for (level = 0; level < key.length; level++) { index = CHAR_TO_INDEX(key[level]); if (current->children[index]) current->children[index] =new TrieNode(); current = current->children[index]; } // mark last node as leaf temp->isLeaf = true; }
  • 11. Tries: Search bool search(TrieNode root, String key){ int level; int index; struct TrieNode current = root; for (level = 0; level < key.length; level++) { index = CHAR_TO_INDEX(key[level]); if (!current->children[index]) return false; current = current->children[index]; } return (current != NULL && current->isLeaf); }
  • 12. Tries: Complexity Search ● Time Complexity : (0)m ● Space Complexity: (0)n characters + (n)links
  • 13. Tries: Complexity To reduce space complexity of links ● Compressed Trie or Radix Trees
  • 14. Tries : Applications ● Auto complete functionality eg in Google search ● Phone Contacts ● Automatic Command Completion in linux terminal ● Spell Checkers in Word or gmail ● …. etc
  • 15. Search Problem 2 1. From a list of Restaurants find all the restaurants where X lies between 30-40 && Y between 40-50 ? Name X Y R1 30 40 R2 5 25 R3 10 12 R4 50 30 R5 35 45
  • 16. K-d Trees 1. A K-d Tree(also called as K-Dimensional Tree) is a binary search tree where data in each node is a K-Dimensional point in space. 2. K is a dimension can be 2-d Tree, 3-d Tree etc. 3. Each level has cutting dimension 4. Cutting dimensions cycle as we go down the tree 5. Each node has a Point
  • 17. K-d Trees: K-d Tree Operations List of points : (30,40), (5,25), (10,12), (70,70), (50,30), (35,45) Different type of Queries: Search Query: search a point (10,12) Range Query: Range Query in 2 D tree is like list all points where x>30 and y> 40
  • 18. K-d Trees : Create
  • 19. K-d Trees : Create insert(Point x, KDNode t, int cd) { if t == null t = new KDNode(x) else if (x == t.data) // error! duplicate else if (x[cd] < t.data[cd]) t.left = insert(x, t.left, (cd+1) % DIM) else t.right = insert(x, t.right, (cd+1) % DIM) return t } KDNode { // To store k dimensional point int point[k]; Node *left, *right; };
  • 20. K-d Trees : Range Search Search X is in range 30-40 Y is in range 40-50
  • 21. K-d Trees: Complexity Insert: (0)log n, in balanced K-d tree Search : (0) logn
  • 22. K-d Trees : Applications ● Database queries involving a multidimensional search key ● Nearest neighbour search ● Clustering in Machine Learning algorithm ● Geographical Databases
  • 24. References 1. de la Briandais, René (1959). File searching using variable length keys. Proc. Western J. Computer Conf. pp. 295–298.Cited by Brass. 2. Bentley, J. L. (1975). "Multidimensional binary search trees used for associative searching". Communications of the ACM. 18 (9): 509. doi:10.1145/361002.361007. 3. https://link.springer.com/chapter/10.1007/978-3-642-72617-0_17 4. http://goanna.cs.rmit.edu.au/~jz/fulltext/acsc03sz.pdf 5. http://www.cs.cmu.edu/~ckingsf/bioinfo-lectures/kdtrees.pdf