Representing and Searching Sets of Strings
|
|
- Brianna Shaw
- 5 years ago
- Views:
Transcription
1 Representing and Searching Sets of Strings Antonio Carzaniga Faculty of Informatics University of Lugano December 1, 2006
2 Outline Radix search Ternary search tries
3 Why Sets of Strings?
4 Why Sets of Strings? Several very important applications
5 Why Sets of Strings? Several very important applications E.g., dictionary symbol table in a compiler all kinds of key-based index...
6 Symbol Table Operations
7 Symbol Table Operations insert(key) delete(key) search(key) min() max()
8 Dictionary Operations
9 Dictionary Operations insert(key) search(key)
10 Dictionary Operations insert(key) search(key) No delete operation Built once and searched many times
11 Binary Search BINARYSEARCH(A, k) 1 first 1 2 last length(a) 3 while first last 4 do m (first + last)/2 5 if A[m] = k 6 then return TRUE 7 elseif first = last 8 then return FALSE 9 elseif A[m] > k 10 then last m 1 11 else fisrt m return FALSE TREE-SEARCH(T, k) 1 x root(t) 2 while x = NIL k = key(x) 3 do if k < key(x) 4 then x left(x) 5 else x right(x) 6 if x = NIL 7 then return TRUE 8 else return FALSE
12 Binary Search BINARYSEARCH(A, k) 1 first 1 2 last length(a) 3 while first last 4 do m (first + last)/2 5 if A[m] = k 6 then return TRUE 7 elseif first = last 8 then return FALSE 9 elseif A[m] > k 10 then last m 1 11 else fisrt m return FALSE TREE-SEARCH(T, k) 1 x root(t) 2 while x = NIL k = key(x) 3 do if k < key(x) 4 then x left(x) 5 else x right(x) 6 if x = NIL 7 then return TRUE 8 else return FALSE Complexity?
13 Binary Search BINARYSEARCH(A, k) 1 first 1 2 last length(a) 3 while first last 4 do m (first + last)/2 5 if A[m] = k 6 then return TRUE 7 elseif first = last 8 then return FALSE 9 elseif A[m] > k 10 then last m 1 11 else fisrt m return FALSE TREE-SEARCH(T, k) 1 x root(t) 2 while x = NIL k = key(x) 3 do if k < key(x) 4 then x left(x) 5 else x right(x) 6 if x = NIL 7 then return TRUE 8 else return FALSE Complexity? we must account for the complexity of string comparisons
14 String Comparison
15 String Comparison Assuming a string is an array of bytes, A[m] = K becomes STRINGEQUALS(S 1, S 2 ) 1 if length(s 1 ) = length(s 2 ) 2 then return FALSE 3 for i 0 to length(s 1 ) 4 do if S 1 [i] = S 2 [i] 5 then return FALSE 6 return TRUE
16 String Comparison Assuming a string is an array of bytes, A[m] = K becomes STRINGEQUALS(S 1, S 2 ) 1 if length(s 1 ) = length(s 2 ) 2 then return FALSE 3 for i 0 to length(s 1 ) 4 do if S 1 [i] = S 2 [i] 5 then return FALSE 6 return TRUE The complexity of STRINGEQUALS(S 1, S 2 ) is O(M), where M is the max string size
17 String Comparison Assuming a string is an array of bytes, A[m] = K becomes STRINGEQUALS(S 1, S 2 ) 1 if length(s 1 ) = length(s 2 ) 2 then return FALSE 3 for i 0 to length(s 1 ) 4 do if S 1 [i] = S 2 [i] 5 then return FALSE 6 return TRUE The complexity of STRINGEQUALS(S 1, S 2 ) is O(M), where M is the max string size So, the complexity of BINARYSEARCH(A, K) is O(M lg N)
18 What About a Hash Table CHAINED-HASH-SEARCH(T, k) 1 L T[h(k)] 2 return LIST-SEARCH(L, k) HASH-SEARCH(T, k) 1 for i 1 to length(t) 2 do j h(k, i) 3 if T[j] = k 4 then return TRUE 5 if T[j] = NIL 6 then return FALSE 7 return FALSE
19 What About a Hash Table CHAINED-HASH-SEARCH(T, k) 1 L T[h(k)] 2 return LIST-SEARCH(L, k) HASH-SEARCH(T, k) 1 for i 1 to length(t) 2 do j h(k, i) 3 if T[j] = k 4 then return TRUE 5 if T[j] = NIL 6 then return FALSE 7 return FALSE Complexity?
20 What About a Hash Table CHAINED-HASH-SEARCH(T, k) 1 L T[h(k)] 2 return LIST-SEARCH(L, k) HASH-SEARCH(T, k) 1 for i 1 to length(t) 2 do j h(k, i) 3 if T[j] = k 4 then return TRUE 5 if T[j] = NIL 6 then return FALSE 7 return FALSE Complexity? here, too, we must account for the string comparisons
21 What About a Hash Table CHAINED-HASH-SEARCH(T, k) 1 L T[h(k)] 2 return LIST-SEARCH(L, k) HASH-SEARCH(T, k) 1 for i 1 to length(t) 2 do j h(k, i) 3 if T[j] = k 4 then return TRUE 5 if T[j] = NIL 6 then return FALSE 7 return FALSE Complexity? here, too, we must account for the string comparisons and for the hash functions
22 Observation
23 Observation When we start BINARYSEARCH(A, K) A[m] is probably far away from K so, STRINGEQUALS(A[m], K) is likely to return quickly
24 Observation When we start BINARYSEARCH(A, K) A[m] is probably far away from K so, STRINGEQUALS(A[m], K) is likely to return quickly Later in BINARYSEARCH(A, K) A[m] gets closer and closer to K so, STRINGEQUALS(A[m], K) is likely to iterate for nearly M steps
25 Observation When we start BINARYSEARCH(A, K) A[m] is probably far away from K so, STRINGEQUALS(A[m], K) is likely to return quickly Later in BINARYSEARCH(A, K) A[m] gets closer and closer to K so, STRINGEQUALS(A[m], K) is likely to iterate for nearly M steps problem is STRINGEQUALS(A[m], K) is likely to go through the same prefix of K many times
26 A New Data Structure Idea: a data structure where common prefixes are shared
27 A New Data Structure Idea: a data structure where common prefixes are shared a l g o c c i a i a o / c l a s s l u g a n o n a t i c
28 A Trie Data structure useful for information retrieval (pronounced try to distinguish it from a tree... )
29 A Trie Data structure useful for information retrieval (pronounced try to distinguish it from a tree... ) Every node holds one character
30 A Trie Data structure useful for information retrieval (pronounced try to distinguish it from a tree... ) Every node holds one character Keys with a common prefix share a branch representing that prefix
31 A Trie Data structure useful for information retrieval (pronounced try to distinguish it from a tree... ) Every node holds one character Keys with a common prefix share a branch representing that prefix Keys are stored at (or just represented by) leaf nodes
32 A Trie Data structure useful for information retrieval (pronounced try to distinguish it from a tree... ) Every node holds one character Keys with a common prefix share a branch representing that prefix Keys are stored at (or just represented by) leaf nodes Question is: how do we represent nodes and links? one way would be to hold Σ = 256 links one for each character of the given alphabet Σ
33 Radix Search Every element x has an array of links links(x) e.g., in radix-256, an element represents a byte in a string (of bytes) Every element x has a value(x) that is TRUE if that prefix corresponds to a string in the dictionary this is to distinguish an entire word from a prefix
34 Every element x has an array of links links(x) Radix Search e.g., in radix-256, an element represents a byte in a string (of bytes) Every element x has a value(x) that is TRUE if that prefix corresponds to a string in the dictionary this is to distinguish an entire word from a prefix RADIXSEARCH(Root, K) 1 n Root 2 for i 1 to length(k) 3 do if links(n)[k[i]] = NIL 4 then return FALSE 5 else n = links(n)[k[i]] 6 return value
35 Complexities of Radix Search What is the complexity of Radix Search with a dictionary of N strings of up to M characters?
36 Complexities of Radix Search What is the complexity of Radix Search with a dictionary of N strings of up to M characters? T(N, M) = Θ(M)
37 Complexities of Radix Search What is the complexity of Radix Search with a dictionary of N strings of up to M characters? T(N, M) = Θ(M) What is the space complexity?
38 Complexities of Radix Search What is the complexity of Radix Search with a dictionary of N strings of up to M characters? T(N, M) = Θ(M) What is the space complexity? S(N, M) = Θ(min( Σ MN, Σ M+2 ))
39 Idea We do not represent a full array of links
40 Idea We do not represent a full array of links Instead, we represent a small binary index of the existing links
41 Idea We do not represent a full array of links Instead, we represent a small binary index of the existing links E.g., prefixes xa, xb, xn, xk, and xs might be represented as follows a b + k x n + s
42 Idea We do not represent a full array of links Instead, we represent a small binary index of the existing links E.g., prefixes xa, xb, xn, xk, and xs might be represented as follows b a next character link next character index + k x n + s
43 Ternary Search Trie
44 Ternary Search Trie Every node n represent a byte character(n)
45 Ternary Search Trie Every node n represent a byte character(n) Every node n has three links lower(n) links to a node representing a lower character at the same position higher(n) links to a node representing a higher character at the same position equal(n) links to a node representing a character in the next position
46 Ternary Search Trie Every node n represent a byte character(n) Every node n has three links lower(n) links to a node representing a lower character at the same position higher(n) links to a node representing a higher character at the same position equal(n) links to a node representing a character in the next position A TST consists of a root node R
47 TST Search A recursive search where N is the current node, K is the key, and p is the current position within K TSTSEARCH(N, K, p) 1 if N = NIL 2 then return FALSE 3 elseif K[p] = 0 4 then return TRUE 5 elseif K[p] < character(n) 6 then return TSTSEARCH(lower(N), K, p) 7 elseif K[p] > character(n) 8 then return TSTSEARCH(higher(N), K, p) 9 elseif K[p] = character(n) 10 then return TSTSEARCH(equal(N), K, p + 1) The search starts with the root node TSTSEARCH(R, K, 0)
48 TST Insertion
49 TST Insertion Same recursive pattern where N is the current node, K is the key, and p is the current position within K TSTINSERT(N, K, p) 1 if N = NULL 2 then N NEWNODE(K[p]) 3 if K[p] = 0 4 then return N 5 elseif K[p] < character(n) 6 then lower(n) TSTINSERT(lower(N), K, p) 7 elseif K[p] > character(n) 8 then higher(n) TSTINSERT(higher(N), K, p) 9 elseif K[p] = character(n) 10 then equal(n) TSTINSERT(equal(N), K, p + 1) 11 return N The insertion starts with the root node R TSTINSERT(R, K, 0)
Elementary Data Structures and Hash Tables
Elementary Data Structures and Hash Tables Antonio Carzaniga Faculty of Informatics University of Lugano November 24, 2006 Outline Common concepts and notation Stacks Queues Linked lists Trees Direct-access
More informationBinary Search Trees. Antonio Carzaniga. Faculty of Informatics University of Lugano. October 22, Antonio Carzaniga 1
Binary Search Trees Antonio Carzaniga Faculty of Informatics University of Lugano October 22, 2008 2006 Antonio Carzaniga 1 Binary search trees Outline Randomized binary search trees 2006 Antonio Carzaniga
More informationBinary Search Trees. Motivation. Binary search tree. Tirgul 7
Tirgul 7 Binary Search Trees Motivation We would like to have a dynamic ADT that efficiently supports the following common operations: Insert & Delete Search for an element Minimum & Maximum Predecessor
More informationElementary Data Structures and Hash Tables
Elementary Data Structures and Hash Tables Antonio Carzaniga Faculty of Informatics Università della Svizzera italiana March 23, 2016 Outline Common concepts and notation Stacks Queues Linked lists Trees
More informationBinary Trees. Recursive definition. Is this a binary tree?
Binary Search Trees Binary Trees Recursive definition 1. An empty tree is a binary tree 2. A node with two child subtrees is a binary tree 3. Only what you get from 1 by a finite number of applications
More informationBinary Search Trees. 1. Inorder tree walk visit the left subtree, the root, and right subtree.
Binary Search Trees Search trees are data structures that support many dynamic set operations including Search, Minimum, Maximum, Predecessor, Successor, Insert, and Delete. Thus, a search tree can be
More informationDesign and Analysis of Algorithms Lecture- 9: Binary Search Trees
Design and Analysis of Algorithms Lecture- 9: Binary Search Trees Dr. Chung- Wen Albert Tsao 1 Binary Search Trees Data structures that can support dynamic set operations. Search, Minimum, Maximum, Predecessor,
More informationBinary search trees. Support many dynamic-set operations, e.g. Search. Minimum. Maximum. Insert. Delete ...
Binary search trees Support many dynamic-set operations, e.g. Search Minimum Maximum Insert Delete... Can be used as dictionary, priority queue... you name it Running time depends on height of tree: 1
More informationBinary Search Tree Binary Search tree is a binary tree in which each internal node x stores an element such that the element stored in the left subtree of x are less than or equal to x and elements stored
More informationCSCI 104 Tries. Mark Redekopp David Kempe
1 CSCI 104 Tries Mark Redekopp David Kempe TRIES 2 3 Review of Set/Map Again Recall the operations a set or map performs Insert(key) Remove(key) find(key) : bool/iterator/pointer Get(key) : value [Map
More informationCS/COE 1501 cs.pitt.edu/~bill/1501/ Searching
CS/COE 1501 cs.pitt.edu/~bill/1501/ Searching Review: Searching through a collection Given a collection of keys C, how to we search for a given key k? Store collection in an array Unsorted Sorted Linked
More informationBinary Tree. Preview. Binary Tree. Binary Tree. Binary Search Tree 10/2/2017. Binary Tree
0/2/ Preview Binary Tree Tree Binary Tree Property functions In-order walk Pre-order walk Post-order walk Search Tree Insert an element to the Tree Delete an element form the Tree A binary tree is a tree
More informationBinary search trees :
Binary search trees Binary search trees : Search trees are data structures that generally offer the following dynamic-set operations : SEARCH MINIMUM MAXIMUM PREDECESSOR SUCCESSOR INSERT DELETE Basic operations
More informationBinary Search Trees. Antonio Carzaniga. Faculty of Informatics University of Lugano. October 21, Antonio Carzaniga 1
Binary Search Trees Antonio Carzaniga Faculty of Informatics University of Lugano October 21, 2010 2006 Antonio Carzaniga 1 Binary search trees Outline Randomized binary search trees 2006 Antonio Carzaniga
More informationLecture 6: Analysis of Algorithms (CS )
Lecture 6: Analysis of Algorithms (CS583-002) Amarda Shehu October 08, 2014 1 Outline of Today s Class 2 Traversals Querying Insertion and Deletion Sorting with BSTs 3 Red-black Trees Height of a Red-black
More informationCS 220: Discrete Structures and their Applications. Recursive objects and structural induction in zybooks
CS 220: Discrete Structures and their Applications Recursive objects and structural induction 6.9 6.10 in zybooks Using recursion to define objects We can use recursion to define functions: The factorial
More informationLecture Notes on Tries
Lecture Notes on Tries 15-122: Principles of Imperative Computation Thomas Cortina Notes by Frank Pfenning Lecture 24 April 19, 2011 1 Introduction In the data structures implementing associative arrays
More informationCISC 235 Topic 3. General Trees, Binary Trees, Binary Search Trees
CISC 235 Topic 3 General Trees, Binary Trees, Binary Search Trees Outline General Trees Terminology, Representation, Properties Binary Trees Representations, Properties, Traversals Recursive Algorithms
More informationB-Trees. CS321 Spring 2014 Steve Cutchin
B-Trees CS321 Spring 2014 Steve Cutchin Topics for Today HW #2 Once Over B Trees Questions PA #3 Expression Trees Balance Factor AVL Heights Data Structure Animations Graphs 2 B-Tree Motivation When data
More informationAnimations. 01/29/04 Lecture
Animations BST: http://babbage.clarku.edu/~achou/cs160/examples/bst_animation/bst-example.html Rotations: http://babbage.clarku.edu/~achou/cs160/examples/bst_animation/index2.html RB-Trees: http://babbage.clarku.edu/~achou/cs160/examples/bst_animation/redblacktree-example.html
More informationData Structures. Dynamic Sets
Data Structures Binary Search Tree Dynamic Sets Elements have a key and satellite data Dynamic sets support queries such as: Search(S, k) Minimum(S) Maximum(S) Successor(S, x) Predecessor(S, x) Insert(S,
More informationspeller.c dictionary contains valid words, one per line 1. calls load on the dictionary file
mispellings speller.c 1. calls load on the dictionary file dictionary contains valid words, one per line 2. calls check on each word in the text file and prints all misspelled words 3. calls size to determine
More informationSuffix trees and applications. String Algorithms
Suffix trees and applications String Algorithms Tries a trie is a data structure for storing and retrieval of strings. Tries a trie is a data structure for storing and retrieval of strings. x 1 = a b x
More informationLecture Notes on Tries
Lecture Notes on Tries 15-122: Principles of Imperative Computation Thomas Cortina, Frank Pfenning, Rob Simmons, Penny Anderson Lecture 22 June 20, 2014 1 Introduction In the data structures implementing
More informationCOSC 2007 Data Structures II Final Exam. Part 1: multiple choice (1 mark each, total 30 marks, circle the correct answer)
COSC 2007 Data Structures II Final Exam Thursday, April 13 th, 2006 This is a closed book and closed notes exam. There are total 3 parts. Please answer the questions in the provided space and use back
More informationRange Searching and Windowing
CS 6463 -- Fall 2010 Range Searching and Windowing Carola Wenk 1 Orthogonal range searching Input: n points in d dimensions E.g., representing a database of n records each with d numeric fields Query:
More informationSearch trees, binary trie, patricia trie Marko Berezovský Radek Mařík PAL 2012
Search trees, binary trie, patricia trie Marko Berezovský Radek Mařík PAL 212 p 2
More informationFriday Four Square! 4:15PM, Outside Gates
Binary Search Trees Friday Four Square! 4:15PM, Outside Gates Implementing Set On Monday and Wednesday, we saw how to implement the Map and Lexicon, respectively. Let's now turn our attention to the Set.
More informationNeed Backtracking! L 0 A 1 B 2 K 3 P 4 C 5 I 6 Z 7 S 8 A 9 N 10 X 11 A 12 N 13 X 14 P 15
CSE 100: TRIES Need Backtracking! L 0 A 1 B 2 K 3 P 4 C 5 I 6 Z 7 S 8 A 9 N 10 X 11 A 12 N 13 X 14 P 15 isonboard(g,v, word ) ( v is the vertex where the search starts, word is the word we are looking
More informationCS Algorithms and Complexity
CS 350 - Algorithms and Complexity Basic Sorting Sean Anderson 1/18/18 Portland State University Table of contents 1. Core Concepts of Sort 2. Selection Sort 3. Insertion Sort 4. Non-Comparison Sorts 5.
More informationToday s Outline. CS 561, Lecture 8. Direct Addressing Problem. Hash Tables. Hash Tables Trees. Jared Saia University of New Mexico
Today s Outline CS 561, Lecture 8 Jared Saia University of New Mexico Hash Tables Trees 1 Direct Addressing Problem Hash Tables If universe U is large, storing the array T may be impractical Also much
More informationCSE Data Structures and Introduction to Algorithms... In Java! Instructor: Fei Wang. Binary Search Trees. CSE2100 DS & Algorithms 1
CSE 2100 Data Structures and Introduction to Algorithms...! In Java!! Instructor: Fei Wang! Binary Search Trees 1 R-10.6, 10.7!!! Draw the 11-entry hash table that results from using the hash function
More information1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1
Asymptotics, Recurrence and Basic Algorithms 1. [1 pt] What is the solution to the recurrence T(n) = 2T(n-1) + 1, T(1) = 1 2. O(n) 2. [1 pt] What is the solution to the recurrence T(n) = T(n/2) + n, T(1)
More informationLecture 5: Scheduling and Binary Search Trees
Lecture 5: Scheduling and Binary Search Trees Lecture Overview Runway reservation system Definition How to solve with lists Binary Search Trees Readings Operations CLRS Chapter 10, 12.1-3 Runway Reservation
More informationCOT 5407: Introduction to Algorithms. Giri Narasimhan. ECS 254A; Phone: x3748
COT 5407: Introduction to Algorithms Giri Narasimhan ECS 254A; Phone: x3748 giri@cis.fiu.edu http://www.cis.fiu.edu/~giri/teach/5407s17.html https://moodle.cis.fiu.edu/v3.1/course/view.php?id=1494 2/2/17
More informationDictionaries (Maps) Hash tables. ADT Dictionary or Map. n INSERT: inserts a new element, associated to unique value of a field (key)
Dictionaries (Maps) Hash tables ADT Dictionary or Map Has following operations: n INSERT: inserts a new element, associated to unique value of a field (key) n SEARCH: searches an element with a certain
More information12 Binary Search Tree
12 Binary Search Tree Binary Search Trees (BSTs) are data structures that support many dynamic set operations. The typical operations include: SEARCH INSERT DELETE MINIMUM MAXIMUM PREDECESSOR SUCCESSOR
More informationLecture: Analysis of Algorithms (CS )
Lecture: Analysis of Algorithms (CS583-002) Amarda Shehu Fall 2017 1 Binary Search Trees Traversals, Querying, Insertion, and Deletion Sorting with BSTs 2 Example: Red-black Trees Height of a Red-black
More informationCS 315 Data Structures mid-term 2
CS 315 Data Structures mid-term 2 1) Shown below is an AVL tree T. Nov 14, 2012 Solutions to OPEN BOOK section. (a) Suggest a key whose insertion does not require any rotation. 18 (b) Suggest a key, if
More information1 A node in a tree. Trees. Datatypes ISC
Datatypes ISC-5315 1 1 A node in a tree /*C*/ typedef struct _node { struct _node *left; struct _node *right; struct _node *parent; float value; node; # # Python example class Node: Node class: this is
More informationAnnouncements. Biostatistics 615/815 Lecture 8: Hash Tables, and Dynamic Programming. Recap: Example of a linked list
Announcements Biostatistics 615/815 Lecture 8:, and Dynamic Programming Hyun Min Kang February 1st, 2011 Homework #2 For problem 3, assume that all the input values are unique Include the class definition
More informationChapter 12 Digital Search Structures
Chapter Digital Search Structures Digital Search Trees Binary Tries and Patricia Multiway Tries C-C Tsai P. Digital Search Tree A digital search tree is a binary tree in which each node contains one element.
More informationAccess Methods. Basic Concepts. Index Evaluation Metrics. search key pointer. record. value. Value
Access Methods This is a modified version of Prof. Hector Garcia Molina s slides. All copy rights belong to the original author. Basic Concepts search key pointer Value record? value Search Key - set of
More informationA dictionary interface.
A dictionary interface. interface Dictionary { public Data search(key k); public void insert(key k, Data d); public void delete(key k); A dictionary behaves like a many-to-one function. The search method
More informationspeller.c dictionary contains valid words, one per line 1. calls load on the dictionary file
mispellings speller.c 1. calls load on the dictionary file dictionary contains valid words, one per line 2. calls check on each word in the text file and prints all misspelled words 3. calls size to determine
More informationCSE2331/5331. Topic 6: Binary Search Tree. Data structure Operations CSE 2331/5331
CSE2331/5331 Topic 6: Binary Search Tree Data structure Operations Set Operations Maximum Extract-Max Insert Increase-key We can use priority queue (implemented by heap) Search Delete Successor Predecessor
More informationCS 206 Introduction to Computer Science II
CS 206 Introduction to Computer Science II 07 / 15 / 2016 Instructor: Michael Eckmann Today s Topics Questions? Comments? Binary trees implementation Binary search trees Michael Eckmann - Skidmore College
More informationHO #13 Fall 2015 Gary Chan. Hashing (N:12)
HO #13 Fall 2015 Gary Chan Hashing (N:12) Outline Motivation Hashing Algorithms and Improving the Hash Functions Collisions Strategies Open addressing and linear probing Separate chaining COMP2012H (Hashing)
More informationTrees in java.util. A set is an object that stores unique elements In Java, two implementations are available:
Trees in java.util A set is an object that stores unique elements In Java, two implementations are available: The class HashSet implements the set with a hash table and a hash function The class TreeSet,
More informationModule 2: Classical Algorithm Design Techniques
Module 2: Classical Algorithm Design Techniques Dr. Natarajan Meghanathan Associate Professor of Computer Science Jackson State University Jackson, MS 39217 E-mail: natarajan.meghanathan@jsums.edu Module
More informationCS 124: Course Review for Final Exam. Grades So Far (with Top Students) Exam Format: Similar to Midterms Class Quizzes Some Topic Highlights
S : ourse Review for inal xam Grades So ar (with Top Students) xam ormat: Similar to Midterms lass Quizzes Some Topic Highlights Illustrations of O,, (lass Quiz ) f (N) g (N) g (N) True or false?. g (N)=O(f
More informationOPPA European Social Fund Prague & EU: We invest in your future.
OPPA European Social Fund Prague & EU: We invest in your future. Search trees, binary trie, patricia trie Marko Berezovský Radek Mařík PAL 212 p 2
More informationFinal Examination CSE 100 UCSD (Practice)
Final Examination UCSD (Practice) RULES: 1. Don t start the exam until the instructor says to. 2. This is a closed-book, closed-notes, no-calculator exam. Don t refer to any materials other than the exam
More informationRadix Searching. The insert procedure for digital search trees also derives directly from the corresponding procedure for binary search trees:
Radix Searching The most simple radix search method is digital tree searching - the binary search tree with the branch in the tree according to the bits of keys: at the first level the leading bit is used,
More informationRed-Black Trees (2) Antonio Carzaniga. April 23, Faculty of Informatics Università della Svizzera italiana Antonio Carzaniga
Red-Black Trees (2) Antonio Carzaniga Faculty of Informatics Università della Svizzera italiana April 23, 2013 Recap on Red-Black Trees 2006 Antonio Carzaniga Recap on Red-Black Trees 12 5 18 2 9 15 19
More informationApplied Databases. Sebastian Maneth. Lecture 14 Indexed String Search, Suffix Trees. University of Edinburgh - March 9th, 2017
Applied Databases Lecture 14 Indexed String Search, Suffix Trees Sebastian Maneth University of Edinburgh - March 9th, 2017 2 Recap: Morris-Pratt (1970) Given Pattern P, Text T, find all occurrences of
More informationLecture Notes on Tries
Lecture Notes on Tries 15-122: Principles of Imperative Computation Thomas Cortina, Frank Pfenning, Rob Simmons, Penny Anderson Lecture 21 November 10, 2014 1 Introduction In the data structures implementing
More informationTrees and Graphs Shabsi Walfish NYU - Fundamental Algorithms Summer 2006
Trees and Graphs Basic Definitions Tree: Any connected, acyclic graph G = (V,E) E = V -1 n-ary Tree: Tree s/t all vertices of degree n+1 A root has degree n Binary Search Tree: A binary tree such that
More informationQuiz 1 Solutions. (a) f(n) = n g(n) = log n Circle all that apply: f = O(g) f = Θ(g) f = Ω(g)
Introduction to Algorithms March 11, 2009 Massachusetts Institute of Technology 6.006 Spring 2009 Professors Sivan Toledo and Alan Edelman Quiz 1 Solutions Problem 1. Quiz 1 Solutions Asymptotic orders
More informationPredecessor. Predecessor Problem van Emde Boas Tries. Philip Bille
Predecessor Predecessor Problem van Emde Boas Tries Philip Bille Predecessor Predecessor Problem van Emde Boas Tries Predecessors Predecessor problem. Maintain a set S U = {,..., u-} supporting predecessor(x):
More informationData Structures and Methods. Johan Bollen Old Dominion University Department of Computer Science
Data Structures and Methods Johan Bollen Old Dominion University Department of Computer Science jbollen@cs.odu.edu http://www.cs.odu.edu/ jbollen January 20, 2004 Page 1 Lecture Objectives 1. To this point:
More informationExternal Sorting Methods
External Sorting Methods Assumptions: data is too large to be held in main memory; data is read or written in blocks; 1 or more external devices available for sorting Sorting in main memory is cheap or
More informationTrees. Prof. Dr. Debora Weber-Wulff
Trees Prof. Dr. Debora Weber-Wulff Flickr, _marmota, 2007 Major Sources Michell Waite & Robert Lafore, Data Structures & Algorithms in Java Michael T. Goodrich and Roberto Tamassia Data Structures and
More informationBinary Search Trees. EECS 214, Fall 2018
Binary Search Trees EECS 214, Fall 2018 2 A data structure for dictionaries There are several data structures that we can use to represent dictionaries: A list of keys-value pairs A hash table An array
More informationDSA - Seminar 6. Deadline for Project stage for projects without trees: today, until 11:59 PM
DSA - Seminar 6 Deadline for Project stage for projects without trees: today, until 11:59 PM 1. Iterator for a SortedMap represented on a hash table, collision resolution with separate chaining. - Assume
More informationExam Principles of Imperative Computation, Summer 2011 William Lovas. June 24, 2011
Exam 3 15-122 Principles of Imperative Computation, Summer 2011 William Lovas June 24, 2011 Name: Sample Solution Andrew ID: wlovas Instructions This exam is closed-book with one double-sided sheet of
More informationCache-Oblivious String Dictionaries
Cache-Oblivious String Dictionaries Gerth Stølting Brodal University of Aarhus Joint work with Rolf Fagerberg #"! Outline of Talk Cache-oblivious model Basic cache-oblivious techniques Cache-oblivious
More information! Tree: set of nodes and directed edges. ! Parent: source node of directed edge. ! Child: terminal node of directed edge
Trees & Heaps Week 12 Gaddis: 20 Weiss: 21.1-3 CS 5301 Fall 2018 Jill Seaman!1 Tree: non-recursive definition! Tree: set of nodes and directed edges - root: one node is distinguished as the root - Every
More informationDATA STRUCTURES AND ALGORITHMS
LECTURE 11 Babeş - Bolyai University Computer Science and Mathematics Faculty 2017-2018 In Lecture 9-10... Hash tables ADT Stack ADT Queue ADT Deque ADT Priority Queue Hash tables Today Hash tables 1 Hash
More information10/9/17. Using recursion to define objects. CS 220: Discrete Structures and their Applications
Using recursion to define objects CS 220: Discrete Structures and their Applications Recursive objects and 6.9 6.10 in zybooks We can use recursion to define functions: The factorial function can be defined
More informationData Structures and Algorithms 2018
Question 1 (12 marks) Data Structures and Algorithms 2018 Assignment 4 25% of Continuous Assessment Mark Deadline : 5pm Monday 12 th March, via Canvas Sort the array [5, 3, 4, 6, 8, 4, 1, 9, 7, 1, 2] using
More informationChapter 7. Space and Time Tradeoffs. Copyright 2007 Pearson Addison-Wesley. All rights reserved.
Chapter 7 Space and Time Tradeoffs Copyright 2007 Pearson Addison-Wesley. All rights reserved. Space-for-time tradeoffs Two varieties of space-for-time algorithms: input enhancement preprocess the input
More informationThe Domain Name System
The Domain Name System Antonio Carzaniga Faculty of Informatics University of Lugano March 27, 2007 c 2005 2007 Antonio Carzaniga 1 IP addresses and host names DNS architecture DNS process DNS requests/replies
More informationChapter 12: Indexing and Hashing (Cnt(
Chapter 12: Indexing and Hashing (Cnt( Cnt.) Basic Concepts Ordered Indices B+-Tree Index Files B-Tree Index Files Static Hashing Dynamic Hashing Comparison of Ordered Indexing and Hashing Index Definition
More informationPredecessor. Predecessor. Predecessors. Predecessors. Predecessor Problem van Emde Boas Tries. Predecessor Problem van Emde Boas Tries.
Philip Bille s problem. Maintain a set S U = {,..., u-} supporting predecessor(x): return the largest element in S that is x. sucessor(x): return the smallest element in S that is x. insert(x): set S =
More informationHow many leaves on the decision tree? There are n! leaves, because every permutation appears at least once.
Chapter 8. Sorting in Linear Time Types of Sort Algorithms The only operation that may be used to gain order information about a sequence is comparison of pairs of elements. Quick Sort -- comparison-based
More informationCSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)
Name: Email address: Quiz Section: CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators) Instructions: Read the directions for each question carefully before answering. We will
More informationR16 SET - 1 '' ''' '' ''' Code No: R
1. a) Define Latency time and Transmission time? (2M) b) Define Hash table and Hash function? (2M) c) Explain the Binary Heap Structure Property? (3M) d) List the properties of Red-Black trees? (3M) e)
More informationAlgorithms and Data Structures
Algorithms and Data Structures Optimal Search Trees; Tries Ulf Leser Content of this Lecture Optimal Search Trees Definition Construction Analysis Searching Strings: Tries Ulf Leser: Algorithms and Data
More informationCS 3343 Fall 2007 Red-black trees Carola Wenk
CS 3343 Fall 2007 Red-black trees Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk CS 334 Analysis of Algorithms 1 Search Trees A binary search tree is a binary tree.
More informationCS 361, Lecture 21. Outline. Things you can do. Things I will do. Evaluation Results
HW Difficulty CS 361, Lecture 21 Jared Saia University of New Mexico The HW in this class is inherently difficult, this is a difficult class. You need to be able to solve problems as hard as the problems
More informationSORTING. Practical applications in computing require things to be in order. To consider: Runtime. Memory Space. Stability. In-place algorithms???
SORTING + STRING COMP 321 McGill University These slides are mainly compiled from the following resources. - Professor Jaehyun Park slides CS 97SI - Top-coder tutorials. - Programming Challenges book.
More informationLecture 6: Hashing Steven Skiena
Lecture 6: Hashing Steven Skiena Department of Computer Science State University of New York Stony Brook, NY 11794 4400 http://www.cs.stonybrook.edu/ skiena Dictionary / Dynamic Set Operations Perhaps
More informationCPS 231 Exam 2 SOLUTIONS
CPS 231 Exam 2 SOLUTIONS Fall 2003 1:00-2:25, Tuesday November 20th Closed book exam NAME: Problem Max Obtained 1 10 2 25 3 (a) 15 3 (b) 15 3 (c) 10 4 (a) 10 4 (b) 15 4 (c) 10 Total 110 1 [10 points ]
More informationInter-Autonomous-System Routing: Border Gateway Protocol
Inter-Autonomous-System Routing: Border Gateway Protocol Antonio Carzaniga Faculty of Informatics University of Lugano December 10, 2014 Outline Hierarchical routing BGP Routing 2005 2007 Antonio Carzaniga
More informationECE250: Algorithms and Data Structures B-Trees (Part A)
ECE250: Algorithms and Data Structures B-Trees (Part A) Ladan Tahvildari, PEng, SMIEEE Associate Professor Software Technologies Applied Research (STAR) Group Dept. of Elect. & Comp. Eng. University of
More informationHash Tables. Reading: Cormen et al, Sections 11.1 and 11.2
COMP3600/6466 Algorithms 2018 Lecture 10 1 Hash Tables Reading: Cormen et al, Sections 11.1 and 11.2 Many applications require a dynamic set that supports only the dictionary operations Insert, Search
More informationLaboratory Module X B TREES
Purpose: Purpose 1... Purpose 2 Purpose 3. Laboratory Module X B TREES 1. Preparation Before Lab When working with large sets of data, it is often not possible or desirable to maintain the entire structure
More informationCS 270 Algorithms. Oliver Kullmann. Binary search. Lists. Background: Pointers. Trees. Implementing rooted trees. Tutorial
Week 7 General remarks Arrays, lists, pointers and 1 2 3 We conclude elementary data structures by discussing and implementing arrays, lists, and trees. Background information on pointers is provided (for
More informationComparisons. Θ(n 2 ) Θ(n) Sorting Revisited. So far we talked about two algorithms to sort an array of numbers. What is the advantage of merge sort?
So far we have studied: Comparisons Insertion Sort Merge Sort Worst case Θ(n 2 ) Θ(nlgn) Best case Θ(n) Θ(nlgn) Sorting Revisited So far we talked about two algorithms to sort an array of numbers What
More informationGrid of Segment Trees for Packet Classification
2010 24th IEEE International Conference on Advanced Information Networking and Applications Grid of Segment Trees for Packet Classification Yeim-Kuan Chang, Yung-Chieh Lin, and Chen-Yu Lin Department of
More informationString quicksort solves this problem by processing the obtained information immediately after each symbol comparison.
Lcp-Comparisons General (non-string) comparison-based sorting algorithms are not optimal for sorting strings because of an imbalance between effort and result in a string comparison: it can take a lot
More informationMultidimensional Indexes [14]
CMSC 661, Principles of Database Systems Multidimensional Indexes [14] Dr. Kalpakis http://www.csee.umbc.edu/~kalpakis/courses/661 Motivation Examined indexes when search keys are in 1-D space Many interesting
More informationApplications of Succinct Dynamic Compact Tries to Some String Problems
Applications of Succinct Dynamic Compact Tries to Some String Problems Takuya Takagi 1, Takashi Uemura 2, Shunsuke Inenaga 3, Kunihiko Sadakane 4, and Hiroki Arimura 1 1 IST & School of Engineering, Hokkaido
More informationComparisons. Heaps. Heaps. Heaps. Sorting Revisited. Heaps. So far we talked about two algorithms to sort an array of numbers
So far we have studied: Comparisons Tree is completely filled on all levels except possibly the lowest, which is filled from the left up to a point Insertion Sort Merge Sort Worst case Θ(n ) Θ(nlgn) Best
More information8. Write an example for expression tree. [A/M 10] (A+B)*((C-D)/(E^F))
DHANALAKSHMI COLLEGE OF ENGINEERING DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING EC6301 OBJECT ORIENTED PROGRAMMING AND DATA STRUCTURES UNIT IV NONLINEAR DATA STRUCTURES Part A 1. Define Tree [N/D 08]
More informationString Matching. Pedro Ribeiro 2016/2017 DCC/FCUP. Pedro Ribeiro (DCC/FCUP) String Matching 2016/ / 42
String Matching Pedro Ribeiro DCC/FCUP 2016/2017 Pedro Ribeiro (DCC/FCUP) String Matching 2016/2017 1 / 42 On this lecture The String Matching Problem Naive Algorithm Deterministic Finite Automata Knuth-Morris-Pratt
More informationOrthogonal range searching. Range Trees. Orthogonal range searching. 1D range searching. CS Spring 2009
CS 5633 -- Spring 2009 Orthogonal range searching Range Trees Carola Wenk Slides courtesy of Charles Leiserson with small changes by Carola Wenk CS 5633 Analysis of Algorithms 1 Input: n points in d dimensions
More informationAlgorithms and Data Structures
Algorithms and Data Structures (Overflow) Hashing Marius Kloft This Module Introduction 2 Abstract Data Types 1 Complexity analysis 1 Styles of algorithms 1 Lists, stacks, queues 2 Sorting (lists) 3 Searching
More informationCSE 214 Computer Science II Searching
CSE 214 Computer Science II Searching Fall 2017 Stony Brook University Instructor: Shebuti Rayana shebuti.rayana@stonybrook.edu http://www3.cs.stonybrook.edu/~cse214/sec02/ Introduction Searching in a
More information