Data Structures and Analysis (COMP 410)

Slides:



Advertisements
Similar presentations
Tries Standard Tries Compressed Tries Suffix Tries.
Advertisements

Design a Data Structure Suppose you wanted to build a web search engine, a la Alta Vista (so you can search for “banana slugs” or “zyzzyvas”) index say.
Binary Tree Properties & Representation. Minimum Number Of Nodes Minimum number of nodes in a binary tree whose height is h. At least one node at each.
Design a Data Structure Suppose you wanted to build a web search engine, a la Alta Vista (so you can search for “banana slugs” or “zyzzyvas”) index say.
Chapter 9 contd. Binary Search Trees Anshuman Razdan Div of Computing Studies
Different Tree Data Structures for Different Problems
AVL Trees Neil Ghani University of Strathclyde. General Trees Recall a tree is * A leaf storing an integer * A node storing a left subtree, an integer.
David Stotts Computer Science Department UNC Chapel Hill.
David Stotts Computer Science Department UNC Chapel Hill.
Lecture 12 : Trie Data Structure Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University.
David Stotts Computer Science Department UNC Chapel Hill.
1 Tries When searching for the name “Smith” in a phone book, we first locate the group of names starting with “S”, then within those we search for “m”,
David Stotts Computer Science Department UNC Chapel Hill.
Sets of Digital Data CSCI 2720 Fall 2005 Kraemer.
David Stotts Computer Science Department UNC Chapel Hill.
Radix search trie (RST) R-way trie (RT) De la Briandias trie (DLB)
Week 14 - Wednesday.  What did we talk about last time?  Heapsort  Timsort  Counting sort  Radix sort.
1 Binary Search Trees  Average case and worst case Big O for –insertion –deletion –access  Balance is important. Unbalanced trees give worse than log.
Contents What is a trie? When to use tries
Search Radix search trie (RST) R-way trie (RT) De la Briandias trie (DLB)
Generic Trees—Trie, Compressed Trie, Suffix Trie (with Analysi
Tries 4/16/2018 8:59 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Searching, Maps,Tries (hashing)
Lecture 19: Binary Trees reading: 17.1 – 17.3
Data Structures and Design in Java © Rick Mercer
Trees Chapter 15.
Tries 07/28/16 11:04 Text Compression
CSE 373 Binary search trees; tree height and balance
Higher Order Tries Key = Social Security Number.
Recursive Objects (Part 4)
Big-O notation Linked lists
Building Java Programs
Mark Redekopp David Kempe
Lecture 16 Multiway Search Trees
Data Structures and Analysis (COMP 410)
Trees Lecture 12 CS2110 – Fall 2017.
Trees Another Abstract Data Type (ADT)
Lecture 22 Binary Search Trees Chapter 10 of textbook
Data Structures and Analysis (COMP 410)
Hashing Exercises.
Radix search trie (RST) R-way trie (RT) De la Briandias trie (DLB)
Digital Search Trees & Binary Tries
Binary Trees, Binary Search Trees
Binary Search Trees.
Fibonacci Heaps Remove arbitrary is useful in (for example) correspondence structures and may also be used to do an increase key in a min structure (remove.
CMSC 341 Lecture 10 B-Trees Based on slides from Dr. Katherine Gibson.
Tries A trie is another type of tree structure. The word “trie” comes from the word “retrieval,” but is usually pronounced like “try.” For our purposes,
Data Structures and Analysis (COMP 410)
Data Structures and Analysis (COMP 410)
Binary Search Tree AVL Tree
Tree A tree is a data structure in which each node is comprised of some data as well as node pointers to child nodes
Trees Another Abstract Data Type (ADT)
B- Trees D. Frey with apologies to Tom Anastasio
Trees Lecture 9 CS2110 – Fall 2009.
Trees Another Abstract Data Type (ADT)
Trees CMSC 202, Version 5/02.
Digital Search Trees & Binary Tries
CMSC 202 Trees.
Higher Order Tries Key = Social Security Number.
Fibonacci Heaps Remove arbitrary is useful in (for example) correspondence structures.
Data Structures and Analysis (COMP 410)
Data Structures and Analysis (COMP 410)
Data Structures and Analysis (COMP 410)
Announcements Prelim 1 on Tuesday! A4 will be posted today
Building Java Programs
Binary Tree Properties & Representation
Trees.
Tree A tree is a data structure in which each node is comprised of some data as well as node pointers to child nodes
Topic 25 Tries “In 1959, (Edward) Fredkin recommended that BBN (Bolt, Beranek and Newman, now BBN Technologies) purchase the very first PDP-1 to support.
Trees Lecture 10 CS2110 – Spring 2013.
Presentation transcript:

Data Structures and Analysis (COMP 410) David Stotts Computer Science Department UNC Chapel Hill

Design Problem

Real Problem Type ahead Like on google search, phone typing… you type a few chars and the program fills in a list of possible choices for you… based on the prefix you have typed Keep typing more chars, the choices narrow and change Design a data structure that will let you do this Describe the time complexity of using it… searching it as typing is done, generating alternatives, etc.

Take some time Discuss an approach with your neighbor In 5-10 mins we will discuss ideas as a class

Let’s not use node to store a whole word Use child link to represent a char typed Path is then the word Basic idea t <root> n a a a e r o s e n tar to as an a w tea new

Basic idea… This tree encodes (stores) these words: tar, tan, tea, to, ton, toe, a, an, ant, as, net, nest, new, no t <root> n a a n e tan a o o r s n e no tar to as an a n w t s e t tea ton ant new t net toe nest

Representation How many children at each node? As many as there are chars you can type Let’s say 26 for this example node { string val = null; node[26] child = new [null,null,…,null]; boolean isWord = false; }

Representation node { string val = null; node[26] child = new [null,null,…,null]; boolean isWord = false; } val: isWord: false . . . child: 0 1 2 3 4 5 6 7 . . . 22 23 24 25

Representation . . . . . . . . . . . . val: isWord: false child: 0 1 2 3 4 5 6 7 . . . 22 23 24 25 val: “b” child: isWord: false . . . 0 1 2 3 4 5 6 7 . . . 22 23 24 25 val: “a” child: isWord: true . . . 0 1 2 3 4 5 6 7 . . . 22 23 24 25 val: “be” child: isWord: true . . . 0 1 2 3 4 5 6 7 . . . 22 23 24 25

Representation . . . . . . . . . . . . val: isWord: false child: b a 0 1 2 3 4 5 6 7 . . . 22 23 24 25 a b e be <root> val: “b” child: isWord: false . . . 0 1 2 3 4 5 6 7 . . . 22 23 24 25 val: “a” child: isWord: true . . . 0 1 2 3 4 5 6 7 . . . 22 23 24 25 val: “be” child: isWord: true . . . 0 1 2 3 4 5 6 7 . . . 22 23 24 25

Analysis Big Oh time complexity is always expressed in terms of some problem size Here the problem size is not the number of words encoded in the tree, like we say for BST Rather we choose M, the length of a word being inserted or searched for

Analysis The worst case time needed to find a word of length M is… O(M) This is true if the tree contains 10 words or 10 million words Length of the longest path in the tree is length of the longest word stored in the tree

This has a name Trie Pronounced “try” or “tree”, both ways Or “trie tree” tree-tree, try-tree Comes from “ re TRIE val ” Used for prefix-based retrieval of strings formed over an alphabet

Beyond this is just templates END Beyond this is just templates