# Using tries dictionary tree 3

Source: Internet
Author: User

Complexity Analysis

In the introduction, you can find that the complexity of searching and inserting a word is linear, but we have not completed this analysis. Lowering a layer in a tree during insertion and search can be completed within a constant time. At the same time, each time this program lowers a layer, it will remove a character from the string; we can conclude that each function accesses the L layer in the tree. Each function accesses the next layer in the tree, which is a constant time, then, you can insert and search for a word in the dictionary tree at O (l) time. The memory used in this dictionary tree is determined by the storage edge and the number of words with the same prefix.

Other types of dictionary trees

We use the dictionary tree to store words with lower-case letters, but the dictionary tree can also store many other things. We can use digits or bytes to replace lowercase letters. Each data structure can exist in this tree, not just strings. Use the dictionary tree to make your imagination fly. For example, if you want to find a word with a deleted letter in the dictionary. You can modify countwords to the following format:

Countwords (vertex, word, missingletters) <br/> K = firstcharacter (Word) <br/> If isempty (Word) <br/> return vertex. word <br/> else if notexists (edges [k]) and missingletters = 0 <br/> return 0 <br/> else if notexists (edges [k]) <br/> cutleftmostcharacter (Word) <br/> return countwords (vertex, word, missingLetters-1) <br/> here we cut a character but we don't go lower in the tree <br/> else <br/> we are adding the two possibilities: the first <br/> character has been deleted plus the first character is present <br/> r = countwords (vertex, word, missingLetters-1) <br/> cutleftmostcharacter (word) <br/> r = R + countwords (edges [K], word, missingletters) <br/> return r <br/>

This function may be more complex than the initial one, but it must judge all the substrings of a word faster.

Exercise

Wordfind SRM 232
Searchbox SRM 361
Cyclicwords SRM 358
Tagalogdictionary SRM 342
Joinedstring SRM 302
Cmpdwords SRM 268
Scruffle 2007 TCCC marathon online Round 1

PS: Because I am really not good at it, please point it out if the translation is inappropriate.

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.