Content

Friday, November 27, 2020

Trie (Prefix Tree)

Source : 

Link1 Link2 

Visualization : 

 Link

Code : 


Applications : 

1.Insert, Search, Remove a word from dictionary. [If there are multiple testcases then Delete the trie else it will cause MLE.]

:: Implemented in the given code.

2. Find if a word in dictionary is a prefix of another word from dictionary. 

Example : 12345, 1245, 123, 1634... Here 123 is a prefix of 12345.

:: In the time of Insertion we will check if we find a end-mark==true for a word or  after ending a word there is a child-node which is not NULL.

3. Find how many time a prefix occurs in a dictionary.

Example : algo, azzy, algea, also, else... Here "al" prefix occurs 3 times.

:: Here we will keep a counter variable in each node. In the time of insertion we will increase it each time.

4. Creating suggestion box. Given a word, print all words whose prefix is this word.

Example : algo, azzy, algea, also, else...Here "al" is given print "algo", "algea", "also".

:: Go to its child node which are not null and print them all.

5. Find maximum & minimum xor of sub-array from an array.

Example : 6 8 2 4 2 have maximum xor = 14 & minimum xor = 2.

:: Read Link2.


6. [Loading...]


Problems : 

1. 1129 - Consistency Checker   [Easy]

2. 11488 - Hyper Prefix Sets [Easy]

3. 12506 - Shortest Names [Easy]

4. Shortest Prefixes [Easy]

5. TRYCOMP - Try to complete [Medium-Easy]

6. 1269 - Consecutive Sum [Medium-Easy]

7. 1114 - Easily Readable [Easy (Try Array Implementation as Pointer Implementation will give MLE)]

8. D. Polycarp's phone book [Easy] 

9. B. A Lot of Games [Medium-Easy]

10. SUBXOR - SubXor [Medium-Easy]

11. E. Sausage Maximization [Medium-Easy]

No comments:

Post a Comment