


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



1
2 private: Vector
3 **private: struct node { string word; node *left, right; }; node root; containsWord? !Tree search using ==, O(lgN) time containsPrefix? !Tree search using substr ==, O(lgN) add? !Tree search to find position, insert new leaf, O(lgN) space usage? ! Per-entry = string + left/right ptrs + balance factor ! " 18 bytes per word media fjord surf
4 **private: struct cell{ string word; cell next; }; cell buckets[NBuckets]; containsWord? !Hash to bucket, search bucket, O(N/B) containsPrefix? !Search all buckets, O(N) add? !Hash to bucket, search/add to bucket, O(N/B) space usage? ! Per-entry = string + 4-byte pointer + 4-byte bucket ptr ! " 16 bytes per word wacky flan mediate azure
5 bytes per word 8 18 16 add O(N) O(lgN) O(1) containsPrefix O(lgN) O(lgN) O(N) containsWord O(lgN) O(lgN) O(1) Sorted vector BST Hashtable
! Average length 8 characters, file is 1.1 MB
! How??? 6
straddle straddled straddler straddlers straddles straddling strafe strafed strafer strafers strafes strafing straggle straggled straggler stragglers straggles stragglier straggliest straggling straggly straight straightaway straightaways straighted straightedge straightedges straighten straightened straightener straighteners straightening straightens straighter straightest straightforward straightforwardly straightforwardness straighting straightjacket straightjackets straightlaced straightly straights straightway strain strained strainer strainers straining strains strait straiten straitened straitening straitens straiter straitest straitjacket straitjackets straitlaced straitly straitness straits strake straked strakes stramash stramashes stramonies stramony strand stranded strander stranders stranding strands strang strange strangely strangeness stranger strangered strangering strangers strangest strangle strangled stranglehold strangleholds strangler stranglers strangles strangling strangulate strangulated strangulates strangulating strangulation strap strapless strapped strapper strappers strapping strappings straps strass strasses strata stratagem stratagems stratal stratas strategic strategical strategically strategies strategist strategists strategy stratification stratifications stratified stratifies stratify stratifying stratosphere stratospheres stratospheric stratum stratums stratus stravage stravaged stravages stravaging stravaig stravaiged stravaiging stravaigs straw strawberries strawberry
s t
t r a o u m o o l p w a y e^ t s d (^) r e c b **private: struct node { char letter; bool isWord; node children[26]; }; node root; containsWord? !Trace path, check isWord, O(length) containsPrefix? !Trace path O(length) add? !Trace path, add new nodes as needed O(length) O(length) not dependent on num words?! ! Longest word (according to OED) pneumonoultramicroscopicsilicovolcanocaniosis (45)
space usage? ! Per-node = 106 bytes ! Trie for OSPD2 has ~250,000 nodes = 26.5 MB!!!
13 *private: struct node { char letter; bool isWord; int childIndex; int nChildren; }; node root; Unify suffixes as well as prefixes ! Trie had 250,000 nodes, dawg has just 80, ! 125,000 words — so many words have no unique nodes Space usage? ! Per-node = 10 bytes ! Dawg for OSPD2 has ~80,000 nodes = .8MB F (^126) 'A' T (^2712) 'B' F (^396) 'C' F (^4520) 'D' F (^558) 'S' T -1 0
14 *private: struct node { 5 bits letter; 1 bit isWord; 1 bit for lastChild 25 bits childIndex; }; node root; Bitpack node into smallest size ! Only 26 letters, don't need full ASCII, squeeze in 5 bits ! isWord/last each 1 bit ! Remaining 25 bits used for index ! Each node shrinks from 10 bytes down to 4 Space usage? ! Dawg for OSPD2 has ~80,000 nodes = .32 MB ! Just ~30% of the size of word file! F (^1) F 'A' T (^27) F 'B' F (^39) F 'C' F (^45) F 'D' F (^55) F 'S' T -1 T
! Just take the entire array and write it out as is ! Indexes don't change, no pointers! ! Easy to restore ! That's what the binary "lexicon.dat" file is
! Tweak width of "beam" as you traverse path to explore just near neighbors
! "The World's Fastest Scrabble Player", Appel & Jacobsen, CACM May 1988