Download presentation
Presentation is loading. Please wait.
1
Autocomplete Based on Ternary Search Tree
Niu Wenhao, Lu Yan, Wang Sangtian
2
Motivation and Introduction
Part 1 Motivation and Introduction ——By Niu Wenhao
3
Motivation Motivation
To improve the performance of autocomplete function of Acemap.
4
Original autocomplete function
There are some problems in original autocomplete function. Large memory costs Redis Very slow for some keywords
5
Memory cost of 100,000 keywords
Our solution Ternary Search Tree (TST) Redis TST Memory cost of 100,000 keywords 210MB 136MB Response time Might be very long! 0.38ms
6
Demo Demo :8123/Autocomplete_v1.5 Return a JSON
7
Java Web Java Web Environment: Java SE Development Kit 8.0
Server: Apache Tomcat 7.0 IDE: Eclipse
8
Java Web Server Request JSP Page Servlet Response
9
Part 2 Details about TST ——By Lu Yan
10
Assign a character to each node. Give each node three links:
Ternary Search Tree Assign a character to each node. Give each node three links: Left link if key’s next character < node’s character Middle link if key’s next character == node’s character Right link if key’s next character > node’s character
11
After inserting “sam” s a s a w a m l d m p s e
12
After inserting “sam”, “sad”
w a m l d m p d s e
13
After inserting “sam”, “sad”, “sap”
w a m l d m p d p s e
14
After inserting “sam”, “sad”, “sap”, “same”
w a m l d m p d e p s e
15
After inserting “sam”, “sad”, “sap”, “same”, “a”
w a m l d m p d e p s e
16
After inserting “sam”, “sad”, “sap”, “same”, “a”, and “awls”
17
Performance Time Complexity Space Complexity Redis O(L) O(N * L * L)
(should be better since there could be many collisions) Trie O(K * L) O(N * L * R) Trie with hashmaps O(N * L) TST O(K * (L + log N)) N = # number of words L = # average length of words K = # number of matches we wish to return R = # size of alphabet
18
Keep TST in memory forever.
Very important! Build a TST: long time Search in TST: no more than 1ms
19
Improve user experience
Part 3 Improve user experience ——By Wang Sangtian
20
Improve user experience
Sorry, I type in wrong prefix! What’s your middle name? What about abbreviation? They have same name…… Useless data in database.
21
Sorry, I type in wrong prefix!
Users may type in wrong prefix. Xinbing Wang xinbing xinbnig Wrong xinbiing
22
Sorry, I type wrong prefix!
Exhaustion method Exchange adjacent characters xibnnig xinnbig xinbnig xinbing xinbngi
23
Sorry, I type wrong prefix!
Exhaustion method Delete one character xibiing delete “n” xiniig delete “b” xinbiing xinbing delete “i” … delete “i”, “n”, “g”
24
What’s your middle name?
Some users don’t know the author’s middle name. Author’s Full name User’s input “Obert P. Castleberry” “obert cas” “Brian B. Avants” “brian ava”
25
What about abbreviation?
Users are more familiar with abbreviations of affiliations. Affiliation Abbreviation Shanghai Jiao Tong University SJTU University of California Los Angeles UCLA
26
They have same name… There are 16 authors named “Tao Wang” in our database. tao wang:7D1EAAC6 Name + ID tao wang:7DAE408A tao wang:7DC34BA9
27
Useless data in database
There are some useless data in database. Author name Author ID Paper count “Zhang” 81ED2B9C 8059 “Wang” 85AA6692 4512
28
Q & A
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.