22C:21 Problem 4.3 - PowerPoint PPT Presentation

About This Presentation
Title:

22C:21 Problem 4.3

Description:

22C:21 Problem 4.3 Solution Outline Trie Store characters in each node, not keys Use characters of the key to guide the search process From retrieval, but pronounced ... – PowerPoint PPT presentation

Number of Views:45
Avg rating:3.0/5.0
Slides: 14
Provided by: Saur82
Category:
Tags: 22c | problem | querying

less

Transcript and Presenter's Notes

Title: 22C:21 Problem 4.3


1
22C21 Problem 4.3
  • Solution Outline

2
Trie
  • Store characters in each node, not keys
  • Use characters of the key to guide the search
    process
  • From retrieval, but pronounced try

3
Example
g
s
t
i
o
u
h
go
m
e
n
she
Make sure the word she is not found unless
it has been explicitly inserted!
sun
d
l
e
shed
time
l
shell
4
Applications
  • Spell checkers
  • Data compression
  • Computational biology
  • Routing tables for IP addresses
  • Storing/Querying XML documents
  • and many other

5
Building block - Class Node
6
Class Trie
  • Specify root node
  • Insert method
  • public void insert (String s)
  • Search method
  • public boolean search (String s)

7
T.insert(tick)
g
s
t
i
o
u
h
go
m
c
e
n
sun
d
l
e
k
shed
time
tick
l
shell
place a marker
8
T.insert(tick)
g
s
t
i
o
u
h
go
m
c
e
n
sun
d
l
e
k
shed
time
tick
l
shell
9
T.search(group)
g
s
t
i
o
null
u
h
Failure return false
go
m
c
e
n
sun
d
l
e
k
shed
time
tick
l
shell
10
T.search(timer)
g
s
t
i
o
u
h
go
m
c
e
n
sun
d
l
e
k
shed
time
tick
l
Failure return false
null
shell
11
T.search(she)
g
s
t
i
o
u
h
go
m
c
e
n
String found. But no marker!
sun
Failure return false
d
l
e
k
shed
time
tick
l
shell
12
T.search(shed)
g
s
t
i
o
u
h
go
m
c
e
n
sun
String found. Marker found!
d
l
e
k
shed
time
tick
Success return true
l
shell
13
Quiz 4 Problem 4.2
  • Draw a trie corresponding to the collection of
    words
  • abacus, abode, dreaded, dust, dusty, planar,
    east
  • Write a main() method that defines a trie and
    performs successive insertions of the above
    strings.
Write a Comment
User Comments (0)
About PowerShow.com