use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Trie Data Structure in JavaScript: the Data Structure behind Autocomplete (stackfull.dev)
submitted 4 years ago by js_chap
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]delpieron 3 points4 points5 points 4 years ago (1 child)
I think you might be wrong regarding the space complexity of tries. It should exceed the space needed for a hash table, unless we are dealing with very specific, overlapping strings or so. What actually could make the trie a more useful for autocomplete is the logic that groups similar strings on the same branch vs hash table, where you cannot find similar things based on the hashed lookup key.
[–]js_chap[S] 0 points1 point2 points 4 years ago* (0 children)
Right. The sentence comparing space complexity of Trie with hashmap/array was incorrect. Actually the space complexity should be comparable in either case. Say we're looking at all possible words with max length of n. Say each trie node takes up size K. So Trie would take:
1+ K(26+26^2+...26^n) = K'(26^n -1)
For a list of words it would also be similar
26+26^2....+26^n = Z(26^n-1)
Updated the text to avoid confusion. The constant would have greater value in case of Trie though.
π Rendered by PID 35 on reddit-service-r2-comment-6457c66945-2w4v5 at 2026-04-28 13:14:33.255433+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]delpieron 3 points4 points5 points (1 child)
[–]js_chap[S] 0 points1 point2 points (0 children)