DATA STRUCTURES-COLLISION TECHNIQUES

Slides:



Advertisements
Similar presentations
Chapter 11. Hash Tables.
Advertisements

David Luebke 1 6/7/2014 ITCS 6114 Skip Lists Hashing.
Analysis of Algorithms CS 477/677
CS Data Structures Chapter 8 Hashing.
Hash Tables CIS 606 Spring 2010.
Hashing.
What we learn with pleasure we never forget. Alfred Mercier Smitha N Pai.
CS 253: Algorithms Chapter 11 Hashing Credit: Dr. George Bebis.
CS Section 600 CS Section 002 Dr. Angela Guercio Spring 2010.
Data Structures – LECTURE 11 Hash tables
Tirgul 10 Rehearsal about Universal Hashing Solving two problems from theoretical exercises: –T2 q. 1 –T3 q. 2.
11.Hash Tables Hsu, Lih-Hsing. Computer Theory Lab. Chapter 11P Directed-address tables Direct addressing is a simple technique that works well.
Tirgul 8 Universal Hashing Remarks on Programming Exercise 1 Solution to question 2 in theoretical homework 2.
Hash Tables1 Part E Hash Tables  
Tirgul 7. Find an efficient implementation of a dynamic collection of elements with unique keys Supported Operations: Insert, Search and Delete. The keys.
Lecture 10: Search Structures and Hashing
CS Data Structures Chapter 8 Hashing (Concentrating on Static Hashing)
Hashing General idea: Get a large array
1. 2 Problem RT&T is a large phone company, and they want to provide enhanced caller ID capability: –given a phone number, return the caller’s name –phone.
Hashtables David Kauchak cs302 Spring Administrative Talk today at lunch Midterm must take it by Friday at 6pm No assignment over the break.
Spring 2015 Lecture 6: Hash Tables
CSC 211 Data Structures Lecture 31
Symbol Tables Symbol tables are used by compilers to keep track of information about variables functions class names type names temporary variables etc.
CS212: DATA STRUCTURES Lecture 10:Hashing 1. Outline 2  Map Abstract Data type  Map Abstract Data type methods  What is hash  Hash tables  Bucket.
Hashing Chapter 20. Hash Table A hash table is a data structure that allows fast find, insert, and delete operations (most of the time). The simplest.
Implementing Dictionaries Many applications require a dynamic set that supports dictionary-type operations such as Insert, Delete, and Search. E.g., a.
Hash Tables.
David Luebke 1 10/25/2015 CS 332: Algorithms Skip Lists Hash Tables.
Comp 335 File Structures Hashing.
Hashing Sections 10.2 – 10.3 CS 302 Dr. George Bebis.
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Hashing Hashing is another method for sorting and searching data.
Lecture 12COMPSCI.220.FS.T Symbol Table and Hashing A ( symbol) table is a set of table entries, ( K,V) Each entry contains: –a unique key, K,
1 Hashing - Introduction Dictionary = a dynamic set that supports the operations INSERT, DELETE, SEARCH Dictionary = a dynamic set that supports the operations.
Hashing 8 April Example Consider a situation where we want to make a list of records for students currently doing the BSU CS degree, with each.
Been-Chian Chien, Wei-Pang Yang, and Wen-Yang Lin 8-1 Chapter 8 Hashing Introduction to Data Structure CHAPTER 8 HASHING 8.1 Symbol Table Abstract Data.
Chapter 10 Hashing. The search time of each algorithm depend on the number n of elements of the collection S of the data. A searching technique called.
Ihab Mohammed and Safaa Alwajidi. Introduction Hash tables are dictionary structure that store objects with keys and provide very fast access. Hash table.
Hashing Fundamental Data Structures and Algorithms Margaret Reid-Miller 18 January 2005.
Introduction to Algorithms 6.046J/18.401J LECTURE7 Hashing I Direct-access tables Resolving collisions by chaining Choosing hash functions Open addressing.
Copyright © Curt Hill Hashing A quick lookup strategy.
Midterm Midterm is Wednesday next week ! The quiz contains 5 problems = 50 min + 0 min more –Master Theorem/ Examples –Quicksort/ Mergesort –Binary Heaps.
Hashtables David Kauchak cs302 Spring Administrative Midterm must take it by Friday at 6pm No assignment over the break.
CS6045: Advanced Algorithms Data Structures. Hashing Tables Motivation: symbol tables –A compiler uses a symbol table to relate symbols to associated.
CSC 413/513: Intro to Algorithms Hash Tables. ● Hash table: ■ Given a table T and a record x, with key (= symbol) and satellite data, we need to support:
Hash table CSC317 We have elements with key and satellite data
CS 332: Algorithms Hash Tables David Luebke /19/2018.
Hashing Alexandra Stefan.
Hashing Alexandra Stefan.
Review Graph Directed Graph Undirected Graph Sub-Graph
Hash functions Open addressing
Hash Table.
Hash Table.
Dictionaries and Their Implementations
Introduction to Algorithms 6.046J/18.401J
Data Structures – Week #7
Introduction to Algorithms
Data Structures and Algorithms (AT70. 02) Comp. Sc. and Inf. Mgmt
Hashing Sections 10.2 – 10.3 Lecture 26 CS302 Data Structures
Hashing and Collision.
EE 312 Software Design and Implementation I
Data Structures – Week #7
What we learn with pleasure we never forget. Alfred Mercier
CS 3343: Analysis of Algorithms
Slide Sources: CLRS “Intro. To Algorithms” book website
DATA STRUCTURES-COLLISION TECHNIQUES
17CS1102 DATA STRUCTURES © 2018 KLEF – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS RESERVED.
DATA STRUCTURES-COLLISION TECHNIQUES
EE 312 Software Design and Implementation I
Hash Tables – 2 1.
Presentation transcript:

DATA STRUCTURES-COLLISION TECHNIQUES 17CS1102 DATA STRUCTURES-COLLISION TECHNIQUES © 2018 KLEF – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS RESERVED

TYPES OF HASH FUNCTIONS DIVISION METHOD MULTIPLICATION METHOD MID-SQUARE METHOD FOLDING METHOD UNIVERSAL HASHING © 2018 KLEF – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS RESERVED

Hash Functions A hash function transforms a key into a table address What makes a good hash function? (1) Easy to compute (2) Approximates a random function: for every input, every output is equally likely (simple uniform hashing) In practice, it is very hard to satisfy the simple uniform hashing property i.e., we don’t know in advance the probability distribution that keys are drawn from

Good Approaches for Hash Functions Minimize the chance that closely related keys hash to the same slot Strings such as pt and pts should hash to different slots Derive a hash value that is independent from any patterns that may exist in the distribution of the keys

The Division Method Idea: Map a key k into one of the m slots by taking the remainder of k divided by m h(k) = k mod m Advantage: fast, requires only one operation Disadvantage: Certain values of m are bad, e.g., power of 2 non-prime numbers

Example - The Division Method 100 If m = 2p, then h(k) is just the least significant p bits of k p = 1  m = 2  h(k) = , least significant 1 bit of k p = 2  m = 4  h(k) = , least significant 2 bits of k Choose m to be a prime, not close to a power of 2 Column 2: Column 3: {0, 1} {0, 1, 2, 3} k mod 97 k mod 100

The Multiplication Method Idea: Multiply key k by a constant A, where 0 < A < 1 Extract the fractional part of kA Multiply the fractional part by m Take the floor of the result h(k) = = m (k A mod 1) SQRT 5-1/2 => A=0.6180339887 Disadvantage: Slower than division method Advantage: Value of m is not critical, e.g., typically 2p fractional part of kA = kA - kA

Example – Multiplication Method

MID-SQUARE METHOD STEP 1: Square the value of the key. K square. Step2 : extract the middle r bits of the result from step 1 H(k)=s where s is obtained by selection r bits from k2 example: K=1234, and 5642, m=100 R=2 K=1234, K2=1522756, H(K)=27 K=5642, K2=31832164, H(K)=21. © 2018 KLEF – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS RESERVED

FOLDING METHOD STEP 1: DIVIDE THE KEY VALUE INTO NUMBER OF PARTS. K INTO k1,k2,k3,….kn, where each part of the key have same no.of digits except the last part which may lesser than other parts STEP 2: ADD THE INDIVIDUAL PARTS. I.E K1+K2+……..Kn. THE HASH VALUE IS PRODUCED BY IGNORING THE LAST CARRY, IF ANY EXAMPLE: K=5678,321,34567, M=100 K=5675,, DIVIDE INTO PARTS 56, 75, THEN SUM IS 56+75=134, THEN HASH VALU IS 34. K=321== 32, 1=32+1=33. HASH VALUE=33, K=34567, 34,56,7 =34+56+7=97. HASH VALUE=97. © 2018 KLEF – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS RESERVED

Universal Hashing In practice, keys are not randomly distributed Any fixed hash function might yield Θ(n) time Goal: hash functions that produce random table indices irrespective of the keys Idea: Select a hash function at random, from a designed class of functions at the beginning of the execution

Universal Hashing (at the beginning of the execution)

Definition of Universal Hash Functions H={h(k): U(0,1,..,m-1)}

How is this property useful? Pr(h(x)=h(y))=

Universal Hashing – Main Result With universal hashing the chance of collision between distinct keys k and l is no more than the 1/m chance of collision if locations h(k) and h(l) were randomly and independently chosen from the set {0, 1, …, m – 1}

Designing a Universal Class of Hash Functions Choose a prime number p large enough so that every possible key k is in the range [0 ... p – 1] Zp = {0, 1, …, p - 1} and Zp* = {1, …, p - 1} Define the following hash function ha,b(k) = ((ak + b) mod p) mod m,  a  Zp* and b  Zp The family of all such hash functions is Hp,m = {ha,b: a  Zp* and b  Zp} a , b: chosen randomly at the beginning of execution The class Hp,m of hash functions is universal

Example: Universal Hash Functions E.g.: p = 17, m = 6 ha,b(k) = ((ak + b) mod p) mod m h3,4(8) = ((38 + 4) mod 17) mod 6 = (28 mod 17) mod 6 = 11 mod 6 = 5

Advantages of Universal Hashing Universal hashing provides good results on average, independently of the keys to be stored Guarantees that no input will always elicit the worst- case behavior Poor performance occurs only when the random choice returns an inefficient hash function – this has small probability