topic 25 clicker 1 tries
play

Topic 25 Clicker 1 Tries (Edward) Fredkin recommended A. that - PowerPoint PPT Presentation

Topic 25 Clicker 1 Tries (Edward) Fredkin recommended A. that BBN (Bolt, Beranek and Newman, now B. ee BBN Technologies) purchase the very first PDP-1 to support research projects at C. BBN. The PDP-1 came with no software D. whatsoever.


  1. Topic 25 Clicker 1 Tries (Edward) Fredkin recommended A. that BBN (Bolt, Beranek and Newman, now B. ee BBN Technologies) purchase the very first PDP-1 to support research projects at C. BBN. The PDP-1 came with no software D. whatsoever. E. something else Fredkin wrote a PDP-1 assembler called FRAP (Free of Rules Assembly Program Tries were first described by René de la Briandais in File searching using variable length keys . CS314 Tries 2 Tries aka Prefix Trees Predictive Text and AutoComplete Pronunciation: Search engines and texting applications guess what you want after typing only a few From re trie val characters Name coined by Computer Scientist Edward Fredkin CS314 Tries 3 CS314 Tries 4

  2. AutoComplete Searching a Dictionary So do other programs such as IDEs How? Could search a set for all values that start with the given prefix. Naively O(N) (search the whole data structure). Could improve if possible to do a binary search for prefix and then localize search to that location. Difficulties if prefix is not actually in the set or dictionary CS314 Tries 5 CS314 Tries 6 Tries René de la Briandais Original Paper A general tree Root node (or possible a list of root nodes) Nodes can have many children not a binary tree In simplest form each node stores a character and a data structure (list?) to refer to its children Stores all the words or phrases in a dictionary. How? CS314 Tries 7 CS314 Tries 8

  3. ???? Can Picture of a Dinosaur CS314 Tries 9 CS314 Tries 10 Candy Fox CS314 Tries 11 CS314 Tries 12

  4. Clicker 2 Clicker 3 Trie? Trie? A. No A. No B. Yes B. Yes C. It depends C. It depends CS314 Tries 13 CS314 Tries 14 Tries Predictive Text and AutoComplete Another example As characters are entered of a Trie we descend the Trie Each node stores: A char A boolean we can descend to indicating if the terminators and leaves to string ending at see all possible words that node is a word based on current prefix A list of children b, e, e -> bee, been, bees CS314 Tries 15 CS314 Tries 16

  5. Tries Implementing a Trie Stores words and phrases. other values possible, but typically Strings The whole word or phrase is not actually stored at a single spot. Rather the path in the tree represents CS314 Tries 18 the word TNode Class Basic Operations Adding a word to the Trie Getting all words with given prefix Demo in IDE Basic implementation uses a LinkedList of TNode objects for children Other options? ArrayList? Something more exotic? CS314 Tries 19 CS314 Tries 20

  6. Compressed Tries Compressed Trie Some words, especially long ones, lead to a Reduce number of nodes, by having nodes chain of nodes with single child, followed by store Strings single child: A chain of single child followed by single s b compressed to a single node with that String Does not have to be a chain that terminates e t e i u in a leaf node o l Can be an internal chain of nodes a y o l d p c l r y l k CS314 Tries 22 Original, Uncompressed Compressed Version s s b b ell e t to e i e id u u ck p o l a ar sy y y s l d ll p c l r y l 8 fewer nodes compared to uncompressed version k s t o c - k CS314 Tries 23 CS314 Tries 24

  7. Data Structures Data Structures Data structures we have studied We have not covered every data structure arrays, array based lists, linked lists, maps, sets, stacks, queue, trees, binary search trees, graphs, hash tables, red-black trees, priority queues, heaps Most program languages have some built in data structures, native or library Must be familiar with performance of data structures best learned by implementing them yourself CS314 Heaps 25 Heaps http://en.wikipedia.org/wiki/List_of_data_structures Data Structures deque, b-trees, quad-trees, binary space partition trees, skip list, sparse list, sparse matrix, union-find data structure, Bloom filters, AVL trees, trie, 2-3-4 trees, and more! Must be able to learn new and apply new data structures CS314 Heaps 27

Recommend


More recommend