SFU CMPT Lecture: Week 8
|
|
- Britton Arnold
- 5 years ago
- Views:
Transcription
1 SFU CMPT Lecture: Week 8 SFU CMPT Lecture: Week 8 Ján Maňuch jmanuch@sfu.ca Lecture on June 24, 2008, 5.30pm-8.20pm
2 SFU CMPT Lecture: Week 8 Universal hashing Overcomes problem of bad inputs by using randomization Mentioned: if adversary chooses keys to be hashed by fixed hash function, he can choose Ò keys that all hash into same slot All fixed hash functions have this problem Universal hashing: design class of parametrized hash functions À pick random ¾ À at beginning of execution (select at random parameters)
3 SFU CMPT Lecture: Week 8 À Let be a finite collection of hash functions that map given Í universe ¼ ½ Ñ ½ into À is said to be universal if for each pair ¾ Í of keys, the number of hash functions ¾ À with µ µ is at most À Ñ, i.e., the chance of a collision is at most À Ñ ½ Ñ À In other words: with randomly chosen from À, the chance of collision between arbitrary distinct keys and is just the same (½ Ñ) as a chance of collision µ if µ and were randomly and independently chosen ¼ Ñ ½ from
4 SFU CMPT Lecture: Week 8 Properties: average-case Let À be a universal collection of hash functions Theorem. Choose ¾ À randomly to hash Ò keys (set Ã) into table Ì of size Ñ, using chaining to resolve collisions. 1. If key is not in the table, then expected length Ò µ of list that hashes to is at most «. 2. If key is in the table, then expected length Ò µ of list containing is at most ½ «. Proof. Important: expectations over the choice of a hash function, do not depend on assumptions regarding distribution of keys! For each pair of distinct keys define a random variable with ½ iff µ µ, i.e, collision By definition, È ½µ ½ Ñ, and thus ½ Ñ
5 ¾Ã Ð ¾Ã SFU CMPT Lecture: Week 8 Now define for each key a random variable i.e. the number of keys other than that hash to same slot as. Clearly, ¾ ½ ¾ Ã Ñ ¾Ã ¾Ã Ñ
6 SFU CMPT Lecture: Week 8 It remains to count the number of ¾ Ã with Case 1: If ¾ Ã, then Ò µ and ¾ Ã Ò Thus Ò µ Ò Ñ «Case 2: If ¾ Ã, key appears in Ì µ. Also, count does not include itself. Thus Ò µ ½ and Thus ¾ Ã Ò ½ Ò µ ½ Ò ½µ Ñ ½ ½ «½ Ñ ½ «
7 SFU CMPT Lecture: Week 8 Universal hashing: sequence of operations Corollary. Using the universal hashing and chaining in a table Ñ with slots, it takes expected µ time to handle any sequence of Insert, Search, and Delete operations, Ç Ñµ containing Insert operations. Proof. the number of Insertions is Ç Ñµ thus the number of elements in the hash table at any time is Ò Ç Ñµ and «Ç ½µ. Insert and Delete take constant time, Search takes expected constant time (due «to Ç ½µ), by linearity of expectation, expected time for sequence of operations is Ç µ. Notice: Impossible for adversary to pick sequence of operations that forces the worst-case time This is now without the assumption of simple uniform hashing
8 SFU CMPT Lecture: Week 8 Construction of a universal class of hash functions Simple solution. take all functions mapping Í into ¼ ½ Ñ disadvantages: ½ size of the collection: Ñ Í number of random bits needed to pick a random function: Í ÐÓ Ñ a lot of preprocessing needed how to encode functions? we have to store the chosen function space needed: Í ÐÓ Ñ we need a much smaller collection of hash functions
9 SFU CMPT Lecture: Week 8 Assignment Problem 8.1. (deadline: July 8, 5:30pm) Prove that the class of all functions from Í to ¼ ½ Ñ ½ is universal.
10 SFU CMPT Lecture: Week 8 Number-theoretical solution. Let Ô be a prime number and let Ô ¼ ½ Ô ½ Ô ½ ¾ Ô ½ Lemma. For any ¾ Ô, ¾ Ô, the equation Ü ÑÓ Ô has a unique solution Ü ¾ Ô. (see Chapter 31.4 for a proof)
11 SFU CMPT Lecture: Week 8 Let Ô be a prime, large enough such that every possible key is in ¼ Ô ½, inclusive. for all ¾ Ô and ¾ Ô define hash functions : µ µ ÑÓ Ôµ ÑÓ Ñ (linear transformation followed by reductions modulo Ô and then modulo Ñ) Note: Ô Ñ since by the assumption, the size of universe of keys Í is greater than the number of slots the function maps Í Ô into Ñ Consider the universal class of hash functions: Note: size of Ô Ô ½µ class: can be chosen such that Ô ¾ Í (Bertrand s postulate) Ô picking randomly À from Ô Ñ means picking random number of bits needed to pick a function À from Ô Ñ Ç ÐÓ Í µ : À Ô Ñ ¾ Ô ¾ Ô
12 SFU CMPT Lecture: Week 8 Theorem. À Class Ô Ñ of hash functions is universal. Proof. Take two distinct keys and. How many functions are there À in Ô Ñ mapping and to the same slot? Consider ¾ À Ô Ñ. Let Ö µ ÑÓ Ô µ ÑÓ Ô Is it possible that Ö? By Lemma: No. If Ö then and are solutions to equation Ü Ö ÑÓ Ô and by uniqueness of solution,. no collisions at modulo Ô level
13 SFU CMPT Lecture: Week 8 There Ô Ô ½µ are functions À in Ô Ñ and there Ô Ô ½µ are possible Ö µ pairs such Ö that. Is there a one-to-one correspondence? Yes Values Ö and determine the function (remember and are still fixed): µ ¼ ÑÓ Ô Ö by Lemma (unknown ), is unique Ö ½ ÑÓ Ô by Lemma (unknown ), is unique implies uniquely determined by Ö and Conclusion: If we pick ¾ À Ô Ñ uniformly at random, the resulting pair Ö µ is equally likely to be any pair of distinct values from Ô.
14 Ô Ñ ½ Ô Ñ SFU CMPT Lecture: Week 8 When a collision between and happens? Hence, probability that and collide is equal to probability Ö that Ñ when Ö and are randomly chosen as distinct values from Ô. ÑÓ and collide when Ö ÑÓ Ñ Note: doesn t depend on and anymore pick any Ö, there are at most Ô Ñ choices of such that Ö ÑÓ Ñ, one of them is Ö hence, there are at most Ô Ñ ½ choices for such that Ö and hence, probability that Ö ÑÓ Ñ and Ö is at most Ö ÑÓ Ñ ½µ Ñ ½ Ô ½ ½ Ô Ô ½µ Ñ ½ Ñ Ô Final conclusion: À Ô Ñ is universal. ½
15 SFU CMPT Lecture: Week 8 Open addressing the second method for dealing with collisions recall, the first method was chaining elements are stored directly in hash table (not in linked lists) hence: the load «is always at most ½ (but the table can overflow) for every key we have a sequence of slots, called the probe sequence when inserting we try (probe) the first slot, if used, the second slot, etc., until we find an empty slot when searching we go over slots in sequence until we either find the searched element or empty slot no pointers used we can use more memory for the hash table instead, which results in fewer collisions, and so, faster searching
16 SFU CMPT Lecture: Week 8 Hash functions have now two parameters: the key ¾ Í the probe number ¾ ¼ ½ Ñ ½ Furthermore, the hash function Í ¼ ½ Ñ ½ ¼ ½ Ñ ½ must satisfy that for every key, the probe sequence ¼µ ½µ Ñ ½µ is a permutation of ¼ ½ Ñ ½ Now: every position is eventually considered as a slot for a new key (the algorithm fails with overflow only when there is no place in the entire table to insert a key)
17 SFU CMPT Lecture: Week 8 Assume that an empty slot contains the value NIL µ Hash-Insert Ì ¼ 1: 2: repeat 3: µ 4: if Ì NIL then 5: Ì 6: return 7: else ½ 8: 9: end if 10: until Ñ 11: error hash table overflow Idea: probing the probe sequence of until we find an empty slot
18 SFU CMPT Lecture: Week 8 Hash-Search Ì µ probes the same sequence, therefore the search can be terminated when an empty slot is found assuming that we didn t delete anything from the table µ Hash-Search Ì ¼ 1: 2: repeat 3: µ 4: if Ì then 5: return 6: else ½ 7: 8: end if 9: until Ì NIL or Ñ 10: return NIL returns where slot contains the key, or NIL, if is not in the table
19 SFU CMPT Lecture: Week 8 Hash-Delete Ì µ difficult operation: when we delete a key from the table, we cannot just mark the slot containing the key by NIL (empty) we could disconnect a sequence of occupied elements leading to the key Solution. mark the place with the special value DELETED (instead of NIL) modify Hash-Insert Ì µ so that it treats slot containing DELETED as empty Hash-Search Ì µ will treat such a slot as occupied, which we want, so no modification is needed Problem. the search time doesn t depend on «load #elements #slots, but rather on #elements #DELETED #slots, which can be quite bad Conclusion. when Delete operation is allowed, prefer to use hashing by chaining
20 SFU CMPT Lecture: Week 8 Assignment Problem 8.2. (deadline: July 8, 5:30pm) Write a pseudo-code for the modified Hash-Insert able to handle also the special value DELETED, and for the procedure Hash-Delete.
21 SFU CMPT Lecture: Week 8 Uniform hashing generalization of simple uniform hashing very strong conditions, in practice just some approximations are used useful for analysis assumption: each key is equally likely to have any Ñ of permutations of as its probe sequence ½ requires that all Ñ possible permutations (probe sequence) could be generated ¼ ½ Ñ Common techniques used are much worse: linear probing (only Ñ distinct probe sequences) quadratic probing (only Ñ distinct probe sequences) double (Ñ hashing distinct probe sequences) the best ¾ results
22 SFU CMPT Lecture: Week 8 Linear probing needs an ordinary hash function ¼ Í ¼ ½ Ñ ½, called an auxiliary hash function hash function: µ ¼ µ µ ÑÓ Ñ hence, for a key, the probe sequence is ¼ µ ¼ µ ½ Ò ½ ¼ ¼ µ ½ we start at the slot given by auxiliary hash function, and then probe consecutive slots first probe determines the entire sequence µ only Ñ distinct probe sequences
23 SFU CMPT Lecture: Week 8 Problem. primary clustering long clusters (sequences) of occupied slots increasing average search time why? consider a cluster with occupied slots, if the consecutive slot is empty, then it has a ½µ Ñ probability that it will be filled during next Insert operation
24 SFU CMPT Lecture: Week 8 Quadratic probing hash function: µ ¼ µ ½ ¾ ¾ µ ÑÓ Ñ where ¼ is again an auxiliary hash function, ¾ ¼ Problems: doesn t work for all values of ½ ¾ and Ñ still: a probe sequence for one key is shifted version of the probe sequence for another µ key Ñ only distinct probe sequences secondary clustering milder form of clustering (the keys mapped to the same slot will form a cluster)
25 SFU CMPT Lecture: Week 8 Assignment Problem 8.3. (deadline: July 8, 5:30pm) Consider a quadratic probing scheme with constants Ñ ¾ Ø for some integer Ø (i.e., Ñ is a power of ¾) and ½ ¾ ½ ¾. Prove that the function µ ¼ µ ½ ¾ ¾ µ ÑÓ Ñ is indeed a hash function, i.e., prove that all probe sequences are permutations ¼ ½ Ñ of ½. Hint: ¾ Congruence equivalent to ¾ ÑÓ ¾ congruence. Ø ½ ÑÓ ¾ Ø makes sense only if is even, and is
26 SFU CMPT Lecture: Week 8 Double hashing hash function: µ ½ µ ¾ µµ ÑÓ Ñ where ½ and ¾ are auxiliary hash functions first probe doesn t determine the entire sequence, depends also on the value of the second hash function (assuming we don t use ¾ ½ ) approximates behavior of uniform hashing, generated permutations have some characteristics of randomly chosen permutation
27 SFU CMPT Lecture: Week 8 Requires. The values of ¾ µ have to be relatively prime (coprime) to the size of hash Ñ table two easy ways: Ñ 1. is power of ¾, and ¾ produce only odd numbers Ñ 2. is a prime, and ¾ returns positive values smaller Ñ than each pair ½ µ ¾ µµ yields a distinct probe sequence, hence Ñ ¾ µ probing sequences are used
28 SFU CMPT Lecture: Week 8 Analysis of open-address hashing assume that we use uniform hashing : a new key has a probe sequence chosen uniformly at random from all possible permutations when we are looking for a key which is already in the table, we assume that every key is equally likely to be searched for we will express the expected number of probes in terms of the load «Ò Ñ ½
29 SFU CMPT Lecture: Week 8 Unsuccessful search Theorem. Given an open-address hash table with load «Ò Ñ ½, the expected number of probes in an unsuccessful search is at most ½ ½ «µ, assuming uniform hashing. Example. if «½ ¾ ( ¼± of table occupied) then the expected number of probes for unsuccessful search will be ½ ½ ½ ¾µ ¾ if «¼ ( ¼± of table occupied), then ½ ½ ½¼µ ½¼
30 SFU CMPT Lecture: Week 8 Proof. let be a random variable denoting the number of probes made in an unsuccessful search for ½ Ñ, let be the event that the -th probe to an occupied slot iff events ½ ½ happened and event didn t event is equivalent to event ½ ¾ ½, hence ½µ is È µ È ½ ¾ ½ µ we are looking for why do we need È µ? answer: Assignment Problem 8.4
31 ½ ½ SFU CMPT Lecture: Week 8 Assignment Problem 8.4. (deadline: July 8, 5:30pm) Consider a random variable having only positive integer values (i.e., it s mapping the probability space to the set of natural numbers). Prove that È ½µ È ¾µ È µ Hint: events ½, ¾,,..., are mutually exclusive (disjoint), hence ½ È µ È µ
32 SFU CMPT Lecture: Week 8 We will use the formula from Assignment Problem 5.2 again: È ½ ¾ ½ µ È ½ µ È ¾ ½ µ È ½ ¾ ¾ ½ µ Hence, to find out È µ it s enough to evaluate conditional probabilities È ½ ½ µ. case ½: È ½ µ Ò Ñ slots, Ò are occupied, uniform hashing, the first probe can be to any of (Ñ slots) Ñ
33 SFU CMPT Lecture: Week 8 case ½: assume ½ ½ occurred hence, first ½ probes were to occupied slots -th probe cannot be to any of these slots (the probe sequence is a permutation) hence, we have Ñ ½µ slots to choose from, and Ò ½µ of them are occupied conclusion: probability È ½ ½ µ is Ò ½µ Ñ ½µ
34 «½ ½ ½ «½ SFU CMPT Lecture: Week 8 We can now calculate È µ: ¾ µ Ò È Ò ½ Ñ ½ Ò Ñ Ñ ¾ Ò ½ Ñ Using Assignment Problem 8.4, È µ ½ ½ ½ ½ ««½ ¼ if «is constant, then ½ ½ «µ is also constant, and so an unsuccessful search runs in Ç ½µ time
35 the same expected number of probes: ½ ½ «µ SFU CMPT Lecture: Week 8 Insert Corollary. Inserting an element into an open-address hash table with load «requires at most ½ ½ «µ probes on average, assuming uniform hashing. Proof. there must be space in the table, «½ inserting a key is equivalent to unsuccessful search, where we insert the key to the final (empty) slot of unsuccessful search
36 SFU CMPT Lecture: Week 8 Successful search Theorem. Given an open-address hash table with load «½, the expected number of probes of successful search is at most ½ ÐÒ «½ «Ç ½µ ½ assuming uniform hashing and assuming that each key in the table is equally likely to be searched for. Example. 50% table full: expected number of probes in successful search: at most ½ 90% table full: ¾
37 SFU CMPT Lecture: Week 8 Proof. when looking for a key, we have to repeat the same probe sequence as when inserting into the table assume that keys were inserted to the table in the order ½ ¾ Ò hence, if we are looking for the key, the number of probe is the same as the number of probes we needed when inserting to the table at that time, table contained ½ elements, and the load factor was «½µ Ñ search for requires at most ½ «½ ½ ½µ Ñ Ñ ½ Ñ ½ probes on average
38 #probes ½ Ò Ñ Ò ½ «SFU CMPT Lecture: Week 8 as it can be any of Ò keys in the table with the same probability, we have to take the average of those expected numbers of probes: Ò Ñ Ñ ½ ½ ½ Ò ½ Ñ ¼ ½ À Ñ À Ñ Ò µ «À using ÐÒ Ç ½µ ÐÒ Ñ ÐÒ Ñ Òµ Ç ½µµ ½ «ÐÒ Ñ Ò Ç ½µ Ñ ½ «ÐÒ ½ «Ç ½µ ½
SFU CMPT Lecture: Week 9
SFU CMPT-307 2008-2 1 Lecture: Week 9 SFU CMPT-307 2008-2 Lecture: Week 9 Ján Maňuch E-mail: jmanuch@sfu.ca Lecture on July 8, 2008, 5.30pm-8.20pm SFU CMPT-307 2008-2 2 Lecture: Week 9 Binary search trees
More informationWorst-case running time for RANDOMIZED-SELECT
Worst-case running time for RANDOMIZED-SELECT is ), even to nd the minimum The algorithm has a linear expected running time, though, and because it is randomized, no particular input elicits the worst-case
More informationHashing. Yufei Tao. Department of Computer Science and Engineering Chinese University of Hong Kong
Department of Computer Science and Engineering Chinese University of Hong Kong In this lecture, we will revisit the dictionary search problem, where we want to locate an integer v in a set of size n or
More informationRSA (Rivest Shamir Adleman) public key cryptosystem: Key generation: Pick two large prime Ô Õ ¾ numbers È.
RSA (Rivest Shamir Adleman) public key cryptosystem: Key generation: Pick two large prime Ô Õ ¾ numbers È. Let Ò Ô Õ. Pick ¾ ½ ³ Òµ ½ so, that ³ Òµµ ½. Let ½ ÑÓ ³ Òµµ. Public key: Ò µ. Secret key Ò µ.
More informationScan Scheduling Specification and Analysis
Scan Scheduling Specification and Analysis Bruno Dutertre System Design Laboratory SRI International Menlo Park, CA 94025 May 24, 2000 This work was partially funded by DARPA/AFRL under BAE System subcontract
More information9/24/ Hash functions
11.3 Hash functions A good hash function satis es (approximately) the assumption of SUH: each key is equally likely to hash to any of the slots, independently of the other keys We typically have no way
More informationRSA (Rivest Shamir Adleman) public key cryptosystem: Key generation: Pick two large prime Ô Õ ¾ numbers È.
RSA (Rivest Shamir Adleman) public key cryptosystem: Key generation: Pick two large prime Ô Õ ¾ numbers È. Let Ò Ô Õ. Pick ¾ ½ ³ Òµ ½ so, that ³ Òµµ ½. Let ½ ÑÓ ³ Òµµ. Public key: Ò µ. Secret key Ò µ.
More informationFrom Static to Dynamic Routing: Efficient Transformations of Store-and-Forward Protocols
From Static to Dynamic Routing: Efficient Transformations of Store-and-Forward Protocols Christian Scheideler Ý Berthold Vöcking Þ Abstract We investigate how static store-and-forward routing algorithms
More informationUnit #5: Hash Functions and the Pigeonhole Principle
Unit #5: Hash Functions and the Pigeonhole Principle CPSC 221: Basic Algorithms and Data Structures Jan Manuch 217S1: May June 217 Unit Outline Constant-Time Dictionaries? Hash Table Outline Hash Functions
More informationWe assume uniform hashing (UH):
We assume uniform hashing (UH): the probe sequence of each key is equally likely to be any of the! permutations of 0,1,, 1 UH generalizes the notion of SUH that produces not just a single number, but a
More informationCS 241 Analysis of Algorithms
CS 241 Analysis of Algorithms Professor Eric Aaron Lecture T Th 9:00am Lecture Meeting Location: OLB 205 Business HW5 extended, due November 19 HW6 to be out Nov. 14, due November 26 Make-up lecture: Wed,
More informationHashing. Hashing Procedures
Hashing Hashing Procedures Let us denote the set of all possible key values (i.e., the universe of keys) used in a dictionary application by U. Suppose an application requires a dictionary in which elements
More informationCS 270 Algorithms. Oliver Kullmann. Generalising arrays. Direct addressing. Hashing in general. Hashing through chaining. Reading from CLRS for week 7
Week 9 General remarks tables 1 2 3 We continue data structures by discussing hash tables. Reading from CLRS for week 7 1 Chapter 11, Sections 11.1, 11.2, 11.3. 4 5 6 Recall: Dictionaries Applications
More informationAAL 217: DATA STRUCTURES
Chapter # 4: Hashing AAL 217: DATA STRUCTURES The implementation of hash tables is frequently called hashing. Hashing is a technique used for performing insertions, deletions, and finds in constant average
More informationWeek 9. Hash tables. 1 Generalising arrays. 2 Direct addressing. 3 Hashing in general. 4 Hashing through chaining. 5 Hash functions.
Week 9 tables 1 2 3 ing in ing in ing 4 ing 5 6 General remarks We continue data structures by discussing hash tables. For this year, we only consider the first four sections (not sections and ). Only
More informationFundamental Algorithms
Fundamental Algorithms Chapter 7: Hash Tables Michael Bader Winter 2011/12 Chapter 7: Hash Tables, Winter 2011/12 1 Generalised Search Problem Definition (Search Problem) Input: a sequence or set A of
More informationHashing Techniques. Material based on slides by George Bebis
Hashing Techniques Material based on slides by George Bebis https://www.cse.unr.edu/~bebis/cs477/lect/hashing.ppt The Search Problem Find items with keys matching a given search key Given an array A, containing
More informationResponse Time Analysis of Asynchronous Real-Time Systems
Response Time Analysis of Asynchronous Real-Time Systems Guillem Bernat Real-Time Systems Research Group Department of Computer Science University of York York, YO10 5DD, UK Technical Report: YCS-2002-340
More information9.5 Equivalence Relations
9.5 Equivalence Relations You know from your early study of fractions that each fraction has many equivalent forms. For example, 2, 2 4, 3 6, 2, 3 6, 5 30,... are all different ways to represent the same
More informationHash Tables. Hash functions Open addressing. March 07, 2018 Cinda Heeren / Geoffrey Tien 1
Hash Tables Hash functions Open addressing Cinda Heeren / Geoffrey Tien 1 Hash functions A hash function is a function that map key values to array indexes Hash functions are performed in two steps Map
More informationIII Data Structures. Dynamic sets
III Data Structures Elementary Data Structures Hash Tables Binary Search Trees Red-Black Trees Dynamic sets Sets are fundamental to computer science Algorithms may require several different types of operations
More informationUnderstand how to deal with collisions
Understand the basic structure of a hash table and its associated hash function Understand what makes a good (and a bad) hash function Understand how to deal with collisions Open addressing Separate chaining
More informationData Structures And Algorithms
Data Structures And Algorithms Hashing Eng. Anis Nazer First Semester 2017-2018 Searching Search: find if a key exists in a given set Searching algorithms: linear (sequential) search binary search Search
More informationData Structures and Algorithm Analysis (CSC317) Hash tables (part2)
Data Structures and Algorithm Analysis (CSC317) Hash tables (part2) Hash table We have elements with key and satellite data Operations performed: Insert, Delete, Search/lookup We don t maintain order information
More informationTABLES AND HASHING. Chapter 13
Data Structures Dr Ahmed Rafat Abas Computer Science Dept, Faculty of Computer and Information, Zagazig University arabas@zu.edu.eg http://www.arsaliem.faculty.zu.edu.eg/ TABLES AND HASHING Chapter 13
More informationHASH TABLES. Hash Tables Page 1
HASH TABLES TABLE OF CONTENTS 1. Introduction to Hashing 2. Java Implementation of Linear Probing 3. Maurer s Quadratic Probing 4. Double Hashing 5. Separate Chaining 6. Hash Functions 7. Alphanumeric
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 informationOnline Facility Location
Online Facility Location Adam Meyerson Abstract We consider the online variant of facility location, in which demand points arrive one at a time and we must maintain a set of facilities to service these
More informationTirgul 7. Hash Tables. In a hash table, we allocate an array of size m, which is much smaller than U (the set of keys).
Tirgul 7 Find an efficient implementation of a dynamic collection of elements with unique keys Supported Operations: Insert, Search and Delete. The keys belong to a universal group of keys, U = {1... M}.
More informationBBM371& Data*Management. Lecture 6: Hash Tables
BBM371& Data*Management Lecture 6: Hash Tables 8.11.2018 Purpose of using hashes A generalization of ordinary arrays: Direct access to an array index is O(1), can we generalize direct access to any key
More informationHASH TABLES. Goal is to store elements k,v at index i = h k
CH 9.2 : HASH TABLES 1 ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY 2004) AND SLIDES FROM JORY DENNY AND
More informationHash Table and Hashing
Hash Table and Hashing The tree structures discussed so far assume that we can only work with the input keys by comparing them. No other operation is considered. In practice, it is often true that an input
More informationSuccessful vs. Unsuccessful
Hashing Search Given: Distinct keys k 1, k 2,, k n and collection T of n records of the form (k 1, I 1 ), (k 2, I 2 ),, (k n, I n ) where I j is the information associated with key k j for 1
More informationAlgorithms and Data Structures
Algorithms and Data Structures Open Hashing Ulf Leser Open Hashing Open Hashing: Store all values inside hash table A General framework No collision: Business as usual Collision: Chose another index and
More informationOptimal Time Bounds for Approximate Clustering
Optimal Time Bounds for Approximate Clustering Ramgopal R. Mettu C. Greg Plaxton Department of Computer Science University of Texas at Austin Austin, TX 78712, U.S.A. ramgopal, plaxton@cs.utexas.edu Abstract
More informationChapter 5 Hashing. Introduction. Hashing. Hashing Functions. hashing performs basic operations, such as insertion,
Introduction Chapter 5 Hashing hashing performs basic operations, such as insertion, deletion, and finds in average time 2 Hashing a hash table is merely an of some fixed size hashing converts into locations
More informationGeneral Idea. Key could be an integer, a string, etc e.g. a name or Id that is a part of a large employee structure
Hashing 1 Hash Tables We ll discuss the hash table ADT which supports only a subset of the operations allowed by binary search trees. The implementation of hash tables is called hashing. Hashing is a technique
More informationDictionaries and Hash Tables
Dictionaries and Hash Tables Nicholas Mainardi Dipartimento di Elettronica e Informazione Politecnico di Milano nicholas.mainardi@polimi.it 14th June 2017 Dictionaries What is a dictionary? A dictionary
More informationHashing. Dr. Ronaldo Menezes Hugo Serrano. Ronaldo Menezes, Florida Tech
Hashing Dr. Ronaldo Menezes Hugo Serrano Agenda Motivation Prehash Hashing Hash Functions Collisions Separate Chaining Open Addressing Motivation Hash Table Its one of the most important data structures
More informationData Structure Lecture#22: Searching 3 (Chapter 9) U Kang Seoul National University
Data Structure Lecture#22: Searching 3 (Chapter 9) U Kang Seoul National University U Kang 1 In This Lecture Motivation of collision resolution policy Open hashing for collision resolution Closed hashing
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 informationHash Tables and Hash Functions
Hash Tables and Hash Functions We have seen that with a balanced binary tree we can guarantee worst-case time for insert, search and delete operations. Our challenge now is to try to improve on that...
More informationHashing. Manolis Koubarakis. Data Structures and Programming Techniques
Hashing Manolis Koubarakis 1 The Symbol Table ADT A symbol table T is an abstract storage that contains table entries that are either empty or are pairs of the form (K, I) where K is a key and I is some
More informationHash Tables. Hash functions Open addressing. November 24, 2017 Hassan Khosravi / Geoffrey Tien 1
Hash Tables Hash functions Open addressing November 24, 2017 Hassan Khosravi / Geoffrey Tien 1 Review: hash table purpose We want to have rapid access to a dictionary entry based on a search key The key
More informationHashing. Introduction to Data Structures Kyuseok Shim SoEECS, SNU.
Hashing Introduction to Data Structures Kyuseok Shim SoEECS, SNU. 1 8.1 INTRODUCTION Binary search tree (Chapter 5) GET, INSERT, DELETE O(n) Balanced binary search tree (Chapter 10) GET, INSERT, DELETE
More informationCOMP171. Hashing.
COMP171 Hashing Hashing 2 Hashing Again, a (dynamic) set of elements in which we do search, insert, and delete Linear ones: lists, stacks, queues, Nonlinear ones: trees, graphs (relations between elements
More informationAlgorithms in Systems Engineering ISE 172. Lecture 12. Dr. Ted Ralphs
Algorithms in Systems Engineering ISE 172 Lecture 12 Dr. Ted Ralphs ISE 172 Lecture 12 1 References for Today s Lecture Required reading Chapter 5 References CLRS Chapter 11 D.E. Knuth, The Art of Computer
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 informationOpen Addressing: Linear Probing (cont.)
Open Addressing: Linear Probing (cont.) Cons of Linear Probing () more complex insert, find, remove methods () primary clustering phenomenon items tend to cluster together in the bucket array, as clustering
More informationDesigning Networks Incrementally
Designing Networks Incrementally Adam Meyerson Kamesh Munagala Ý Serge Plotkin Þ Abstract We consider the problem of incrementally designing a network to route demand to a single sink on an underlying
More informationIntroduction hashing: a technique used for storing and retrieving information as quickly as possible.
Lecture IX: Hashing Introduction hashing: a technique used for storing and retrieving information as quickly as possible. used to perform optimal searches and is useful in implementing symbol tables. Why
More informationIntroduction. hashing performs basic operations, such as insertion, better than other ADTs we ve seen so far
Chapter 5 Hashing 2 Introduction hashing performs basic operations, such as insertion, deletion, and finds in average time better than other ADTs we ve seen so far 3 Hashing a hash table is merely an hashing
More informationProbabilistic analysis of algorithms: What s it good for?
Probabilistic analysis of algorithms: What s it good for? Conrado Martínez Univ. Politècnica de Catalunya, Spain February 2008 The goal Given some algorithm taking inputs from some set Á, we would like
More informationHashing. 5/1/2006 Algorithm analysis and Design CS 007 BE CS 5th Semester 2
Hashing Hashing A hash function h maps keys of a given type to integers in a fixed interval [0,N-1]. The goal of a hash function is to uniformly disperse keys in the range [0,N-1] 5/1/2006 Algorithm analysis
More informationCHAPTER 8. Copyright Cengage Learning. All rights reserved.
CHAPTER 8 RELATIONS Copyright Cengage Learning. All rights reserved. SECTION 8.3 Equivalence Relations Copyright Cengage Learning. All rights reserved. The Relation Induced by a Partition 3 The Relation
More informationHashing 1. Searching Lists
Hashing 1 Searching Lists There are many instanced when one is interested in storing and searching a list: phone company wants to provide caller ID: Given a phone number a name is returned. Somebody who
More informationModule 3: Hashing Lecture 9: Static and Dynamic Hashing. The Lecture Contains: Static hashing. Hashing. Dynamic hashing. Extendible hashing.
The Lecture Contains: Hashing Dynamic hashing Extendible hashing Insertion file:///c /Documents%20and%20Settings/iitkrana1/My%20Documents/Google%20Talk%20Received%20Files/ist_data/lecture9/9_1.htm[6/14/2012
More informationHash Open Indexing. Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1
Hash Open Indexing Data Structures and Algorithms CSE 373 SP 18 - KASEY CHAMPION 1 Warm Up Consider a StringDictionary using separate chaining with an internal capacity of 10. Assume our buckets are implemented
More information! A Hash Table is used to implement a set, ! The table uses a function that maps an. ! The function is called a hash function.
Hash Tables Chapter 20 CS 3358 Summer II 2013 Jill Seaman Sections 201, 202, 203, 204 (not 2042), 205 1 What are hash tables?! A Hash Table is used to implement a set, providing basic operations in constant
More informationHashing. 1. Introduction. 2. Direct-address tables. CmSc 250 Introduction to Algorithms
Hashing CmSc 250 Introduction to Algorithms 1. Introduction Hashing is a method of storing elements in a table in a way that reduces the time for search. Elements are assumed to be records with several
More informationMobile Agent Rendezvous in a Ring
Mobile Agent Rendezvous in a Ring Evangelos Kranakis Danny Krizanc Ý Nicola Santoro Cindy Sawchuk Abstract In the rendezvous search problem, two mobile agents must move along the Ò nodes of a network so
More informationHash Tables Outline. Definition Hash functions Open hashing Closed hashing. Efficiency. collision resolution techniques. EECS 268 Programming II 1
Hash Tables Outline Definition Hash functions Open hashing Closed hashing collision resolution techniques Efficiency EECS 268 Programming II 1 Overview Implementation style for the Table ADT that is good
More informationDirected Single Source Shortest Paths in Linear Average Case Time
Directed Single Source Shortest Paths in inear Average Case Time Ulrich Meyer MPI I 2001 1-002 May 2001 Author s Address ÍÐÖ ÅÝÖ ÅܹÈÐÒ¹ÁÒ ØØÙØ ĐÙÖ ÁÒÓÖÑØ ËØÙÐ ØÞÒÙ Û ½¾ ËÖÖĐÙÒ umeyer@mpi-sb.mpg.de www.uli-meyer.de
More informationCSE 2320 Notes 13: Hashing
CSE 30 Notes 3: Hashing (Last updated 0/7/7 : PM) CLRS.-. (skip.3.3) 3.A. CONCEPTS Goal: Achieve faster operations than balanced trees (nearly Ο( ) epected time) by using randomness in key sets by sacrificing
More informationCS 350 : Data Structures Hash Tables
CS 350 : Data Structures Hash Tables David Babcock (courtesy of James Moscola) Department of Physical Sciences York College of Pennsylvania James Moscola Hash Tables Although the various tree structures
More informationComputing optimal linear layouts of trees in linear time
Computing optimal linear layouts of trees in linear time Konstantin Skodinis University of Passau, 94030 Passau, Germany, e-mail: skodinis@fmi.uni-passau.de Abstract. We present a linear time algorithm
More informationComp 335 File Structures. Hashing
Comp 335 File Structures Hashing What is Hashing? A process used with record files that will try to achieve O(1) (i.e. constant) access to a record s location in the file. An algorithm, called a hash function
More informationOn the Performance of Greedy Algorithms in Packet Buffering
On the Performance of Greedy Algorithms in Packet Buffering Susanne Albers Ý Markus Schmidt Þ Abstract We study a basic buffer management problem that arises in network switches. Consider input ports,
More informationRandomized Algorithms, Hash Functions
Randomized Algorithms, Hash Functions Lecture A Tiefenbruck MWF 9-9:50am Center 212 Lecture B Jones MWF 2-2:50pm Center 214 Lecture C Tiefenbruck MWF 11-11:50am Center 212 http://cseweb.ucsd.edu/classes/wi16/cse21-abc/
More informationDisjoint, Partition and Intersection Constraints for Set and Multiset Variables
Disjoint, Partition and Intersection Constraints for Set and Multiset Variables Christian Bessiere ½, Emmanuel Hebrard ¾, Brahim Hnich ¾, and Toby Walsh ¾ ¾ ½ LIRMM, Montpelier, France. Ö Ð ÖÑÑ Ö Cork
More informationCpt S 223. School of EECS, WSU
Hashing & Hash Tables 1 Overview Hash Table Data Structure : Purpose To support insertion, deletion and search in average-case constant t time Assumption: Order of elements irrelevant ==> data structure
More informationA Modality for Recursion
A Modality for Recursion (Technical Report) March 31, 2001 Hiroshi Nakano Ryukoku University, Japan nakano@mathryukokuacjp Abstract We propose a modal logic that enables us to handle self-referential formulae,
More informationFast Lookup: Hash tables
CSE 100: HASHING Operations: Find (key based look up) Insert Delete Fast Lookup: Hash tables Consider the 2-sum problem: Given an unsorted array of N integers, find all pairs of elements that sum to a
More informationHash Tables. Hashing Probing Separate Chaining Hash Function
Hash Tables Hashing Probing Separate Chaining Hash Function Introduction In Chapter 4 we saw: linear search O( n ) binary search O( log n ) Can we improve the search operation to achieve better than O(
More informationData and File Structures Laboratory
Hashing Assistant Professor Machine Intelligence Unit Indian Statistical Institute, Kolkata September, 2018 1 Basics 2 Hash Collision 3 Hashing in other applications What is hashing? Definition (Hashing)
More informationMidterm 2. Read all of the following information before starting the exam:
Midterm 2 ECE 608 April 7, 2004, 7-9pm Name: Read all of the following information before starting the exam: NOTE: Unanswered questions are worth 30% credit, rounded down. Writing any answer loses this
More informationHashing 1. Searching Lists
Hashing 1 Searching Lists There are many instances when one is interested in storing and searching a list: A phone company wants to provide caller ID: Given a phone number a name is returned. Somebody
More informationHashTable CISC5835, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang Fall 2018
HashTable CISC5835, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang Fall 2018 Acknowledgement The set of slides have used materials from the following resources Slides for textbook by Dr. Y.
More informationWorst-Case Utilization Bound for EDF Scheduling on Real-Time Multiprocessor Systems
Worst-Case Utilization Bound for EDF Scheduling on Real-Time Multiprocessor Systems J.M. López, M. García, J.L. Díaz, D.F. García University of Oviedo Department of Computer Science Campus de Viesques,
More informationCSE200: Computability and complexity Interactive proofs
CSE200: Computability and complexity Interactive proofs Shachar Lovett January 29, 2018 1 What are interactive proofs Think of a prover trying to convince a verifer that a statement is correct. For example,
More informationHashing HASHING HOW? Ordered Operations. Typical Hash Function. Why not discard other data structures?
HASHING By, Durgesh B Garikipati Ishrath Munir Hashing Sorting was putting things in nice neat order Hashing is the opposite Put things in a random order Algorithmically determine position of any given
More informationExpected Runtimes of Evolutionary Algorithms for the Eulerian Cycle Problem
Expected Runtimes of Evolutionary Algorithms for the Eulerian Cycle Problem Frank Neumann Institut für Informatik und Praktische Mathematik Christian-Albrechts-Universität zu Kiel 24098 Kiel, Germany fne@informatik.uni-kiel.de
More informationCHAPTER 9 HASH TABLES, MAPS, AND SKIP LISTS
0 1 2 025-612-0001 981-101-0002 3 4 451-229-0004 CHAPTER 9 HASH TABLES, MAPS, AND SKIP LISTS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH,
More informationCSCI Analysis of Algorithms I
CSCI 305 - Analysis of Algorithms I 04 June 2018 Filip Jagodzinski Computer Science Western Washington University Announcements Remainder of the term 04 June : lecture 05 June : lecture 06 June : lecture,
More informationInformation-Theoretic Private Information Retrieval: A Unified Construction (Extended Abstract)
Information-Theoretic Private Information Retrieval: A Unified Construction (Extended Abstract) Amos Beimel ½ and Yuval Ishai ¾ ¾ ½ Ben-Gurion University, Israel. beimel@cs.bgu.ac.il. DIMACS and AT&T Labs
More informationUlysses: A Robust, Low-Diameter, Low-Latency Peer-to-Peer Network
1 Ulysses: A Robust, Low-Diameter, Low-Latency Peer-to-Peer Network Abhishek Kumar Shashidhar Merugu Jun (Jim) Xu Xingxing Yu College of Computing, School of Mathematics, Georgia Institute of Technology,
More informationCompetitive Analysis of On-line Algorithms for On-demand Data Broadcast Scheduling
Competitive Analysis of On-line Algorithms for On-demand Data Broadcast Scheduling Weizhen Mao Department of Computer Science The College of William and Mary Williamsburg, VA 23187-8795 USA wm@cs.wm.edu
More informationEfficiency versus Convergence of Boolean Kernels for On-Line Learning Algorithms
Efficiency versus Convergence of Boolean Kernels for On-Line Learning Algorithms Roni Khardon Tufts University Medford, MA 02155 roni@eecs.tufts.edu Dan Roth University of Illinois Urbana, IL 61801 danr@cs.uiuc.edu
More informationA Note on Karr s Algorithm
A Note on Karr s Algorithm Markus Müller-Olm ½ and Helmut Seidl ¾ ½ FernUniversität Hagen, FB Informatik, LG PI 5, Universitätsstr. 1, 58097 Hagen, Germany mmo@ls5.informatik.uni-dortmund.de ¾ TU München,
More informationCSC263 Week 5. Larry Zhang.
CSC263 Week 5 Larry Zhang http://goo.gl/forms/s9yie3597b Announcements PS3 marks out, class average 81.3% Assignment 1 due next week. Response to feedbacks -- tutorials We spent too much time on working
More informationExternal-Memory Breadth-First Search with Sublinear I/O
External-Memory Breadth-First Search with Sublinear I/O Kurt Mehlhorn and Ulrich Meyer Max-Planck-Institut für Informatik Stuhlsatzenhausweg 85, 66123 Saarbrücken, Germany. Abstract. Breadth-first search
More informationAcknowledgement HashTable CISC4080, Computer Algorithms CIS, Fordham Univ.
Acknowledgement HashTable CISC4080, Computer Algorithms CIS, Fordham Univ. Instructor: X. Zhang Spring 2018 The set of slides have used materials from the following resources Slides for textbook by Dr.
More informationHash table basics. ate à. à à mod à 83
Hash table basics After today, you should be able to explain how hash tables perform insertion in amortized O(1) time given enough space ate à hashcode() à 48594983à mod à 83 82 83 ate 84 } EditorTrees
More informationDictionaries and Hash Tables
Dictionaries and Hash Tables 0 1 2 3 025-612-0001 981-101-0002 4 451-229-0004 Dictionaries and Hash Tables 1 Dictionary ADT The dictionary ADT models a searchable collection of keyelement items The main
More informationTheorem 2.9: nearest addition algorithm
There are severe limits on our ability to compute near-optimal tours It is NP-complete to decide whether a given undirected =(,)has a Hamiltonian cycle An approximation algorithm for the TSP can be used
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 informationCMSC 341 Hashing (Continued) Based on slides from previous iterations of this course
CMSC 341 Hashing (Continued) Based on slides from previous iterations of this course Today s Topics Review Uses and motivations of hash tables Major concerns with hash tables Properties Hash function Hash
More informationMore on Hashing: Collisions. See Chapter 20 of the text.
More on Hashing: Collisions See Chapter 20 of the text. Collisions Let's do an example -- add some people to a hash table of size 7. Name h = hash(name) h%7 Ben 66667 6 Bob 66965 3 Steven -1808493797-5
More informationCS/COE 1501
CS/COE 1501 www.cs.pitt.edu/~lipschultz/cs1501/ Hashing Wouldn t it be wonderful if... Search through a collection could be accomplished in Θ(1) with relatively small memory needs? Lets try this: Assume
More informationHashing for searching
Hashing for searching Consider searching a database of records on a given key. There are three standard techniques: Searching sequentially start at the first record and look at each record in turn until
More information