Presentation is loading. Please wait.

Presentation is loading. Please wait.

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 retrievalFrom.

Similar presentations


Presentation on theme: "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 retrievalFrom."— Presentation transcript:

1 22C:21 Problem 4.3 Solution Outline

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

3 Example u d en l h st o g l i e m go shed shell sun time she Make sure the word “she” is not found… …unless it has been explicitly inserted!

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”) u d en l h st o g l i e m go shed shell sun time k c tick place a marker

8 T.insert(“tick”) u d en l h st o g l i e m go shed shell sun time k c tick

9 T.search(“group”) u d en l h st o g l i e m go shed shell sun time k c tick null Failure return false

10 T.search(“timer”) u d en l h st o g l i e m go shed shell sun time k c tick null Failure return false

11 T.search(“she”) u d en l h st o g l i e m go shed shell sun time k c tick String found. But no marker! Failure return false

12 T.search(“shed”) u d en l h st o g l i e m go shed shell sun time k c tick String found. Marker found! Success return true

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.


Download ppt "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 retrievalFrom."

Similar presentations


Ads by Google