Log Files. O(n) Data Structure Exercises 16.1.

Slides:



Advertisements
Similar presentations
© 2004 Goodrich, Tamassia Hash Tables
Advertisements

1 Designing Hash Tables Sections 5.3, 5.4, Designing a hash table 1.Hash function: establishing a key with an indexed location in a hash table.
Hash Tables.
© 2004 Goodrich, Tamassia Hash Tables1  
Hashing CS 3358 Data Structures.
Maps, Dictionaries, Hashtables
Dictionaries and Hash Tables1  
© 2006 Pearson Addison-Wesley. All rights reserved13 A-1 Chapter 13 Hash Tables.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 48 Hashing.
1 CSE 326: Data Structures Hash Tables Autumn 2007 Lecture 14.
CS 206 Introduction to Computer Science II 11 / 17 / 2008 Instructor: Michael Eckmann.
Hash Tables1 Part E Hash Tables  
Hash Tables1 Part E Hash Tables  
Hashing COMP171 Fall Hashing 2 Hash table * Support the following operations n Find n Insert n Delete. (deletions may be unnecessary in some applications)
Introduction to Hashing CS 311 Winter, Dictionary Structure A dictionary structure has the form: (Key, Data) Dictionary structures are organized.
Hash Tables1 Part E Hash Tables  
Hashing General idea: Get a large array
Dictionaries 4/17/2017 3:23 PM Hash Tables  
CS 206 Introduction to Computer Science II 04 / 06 / 2009 Instructor: Michael Eckmann.
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.
Hashing 1. Def. Hash Table an array in which items are inserted according to a key value (i.e. the key value is used to determine the index of the item).
CS 221 Analysis of Algorithms Data Structures Dictionaries, Hash Tables, Ordered Dictionary and Binary Search Trees.
Data Structures and Algorithm Analysis Hashing Lecturer: Jing Liu Homepage:
Dictionaries and Hash Tables. Dictionary A dictionary, in computer science, implies a container that stores key-element pairs called items, and allows.
Implementing Dictionaries Many applications require a dynamic set that supports dictionary-type operations such as Insert, Delete, and Search. E.g., a.
Hash Tables1   © 2010 Goodrich, Tamassia.
1 CSE 326: Data Structures: Hash Tables Lecture 12: Monday, Feb 3, 2003.
Hashing1 Hashing. hashing2 Observation: We can store a set very easily if we can use its keys as array indices: A: e.g. SEARCH(A,k) return A[k]
Hashing Sections 10.2 – 10.3 CS 302 Dr. George Bebis.
1 HASHING Course teacher: Moona Kanwal. 2 Hashing Mathematical concept –To define any number as set of numbers in given interval –To cut down part of.
Hashing Hashing is another method for sorting and searching data.
© 2004 Goodrich, Tamassia Hash Tables1  
Ihab Mohammed and Safaa Alwajidi. Introduction Hash tables are dictionary structure that store objects with keys and provide very fast access. Hash table.
Chapter 11 Hash Tables © John Urrutia 2014, All Rights Reserved1.
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables IV.
Hashtables. An Abstract data type that supports the following operations: –Insert –Find –Remove Search trees can be used for the same operations but require.
Chapter 13 C Advanced Implementations of Tables – Hash Tables.
Data Structure & Algorithm Lecture 8 – Hashing JJCAO Most materials are stolen from Prof. Yoram Moses’s course.
1 the hash table. hash table A hash table consists of two major components …
Hash Tables ADT Data Dictionary, with two operations – Insert an item, – Search for (and retrieve) an item How should we implement a data dictionary? –
Hashing Goal Perform inserts, deletes, and finds in constant average time Topics Hash table, hash function, collisions Collision handling Separate chaining.
Hash Tables Ellen Walker CPSC 201 Data Structures Hiram College.
Chapter 11 (Lafore’s Book) Hash Tables Hwajung Lee.
CSC 212 – Data Structures Lecture 28: More Hash and Dictionaries.
Hash Maps Rem Collier Room A1.02 School of Computer Science and Informatics University College Dublin, Ireland.
Hash Tables 1/28/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M.
Hashing (part 2) CSE 2011 Winter March 2018.
Chapter 27 Hashing Jung Soo (Sue) Lim Cal State LA.
Hashing CSE 2011 Winter July 2018.
Dictionaries Dictionaries 07/27/16 16:46 07/27/16 16:46 Hash Tables 
© 2013 Goodrich, Tamassia, Goldwasser
Dictionaries 9/14/ :35 AM Hash Tables   4
Hash Tables 3/25/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M.
Hash Table.
Hash Table.
Chapter 28 Hashing.
Hash In-Class Quiz.
Dictionaries and Hash Tables
Chapter 21 Hashing: Implementing Dictionaries and Sets
Resolving collisions: Open addressing
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
Dictionaries and Hash Tables
Dictionaries 1/17/2019 7:55 AM Hash Tables   4
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
Hash Tables Computer Science and Engineering
Pseudorandom number, Universal Hashing, Chaining and Linear-Probing
Dictionaries 4/5/2019 1:49 AM Hash Tables  
CS210- Lecture 16 July 11, 2005 Agenda Maps and Dictionaries Map ADT
Dictionaries and Hash Tables
Presentation transcript:

Log Files

O(n)

Data Structure Exercises 16.1

Hash Tables

In general, the approach of Summing Components can be extended to keys with m components. Let the key be k = (x 0, x 1, …, x m-1 ), we compute the integer. We may use the following expression as its hash code: hash code =

v(t) + v(e) + v(m) + v(p) + v(0) + v(1)

where the key is k = (x 0, x 1, …, x m-2, x m-1 ). Polynomial Hash Codes In this approach, we choose a constant a  1 and calculate the integer value

A = 9 A carefully chosen value of the constant a can reduce the number of conflicts significantly. Good values include 33, 37, 39, and 41 according to some experimental studies.

where N is a prime number, a and b are nonnegative integers randomly chosen at the time when the compression function is determined so that a mod N  0. This method is more sophisticated works better.

Collision-Handling Schemes Recall that if there is no collision, we can store the item (k, e) in the bucket array cell A[h(k)]. However, collision does occur time to time. In this case, two different keys, k 1 and k 2 cause the hash function to return a same value: h(k 1 ) = h(k 2 ). Therefore we cannot store -the item directly in A[h(k)]. The two schemes to handle collisions: Separate Chaining Open Addressing

Separate Chaining In this approach, what stored in A[h(k)]. is a reference to a sequence S k rather than the item. In turn, the items that have the same hash function value k are all stored in S k. The sequence S k can be implemented as a log file.

Data Structure Exercises 16.2

Linear Probing - A simple opening addressing scheme Assume that we want to insert an item (k, e) and I = h(k). The operation goes like this: If the bucket A[i] is not empty, we try the next bucket A[(i+1) mod N]. If this is not empty, then we try A[(i+2) mod N], and so on, until we find an empty bucket. Example:

One of disadvantages with Linear probing is that it tends to cluster the items of the dictionary into contiguous runs. This causes the searches to slow down quite a bit. To avoid this, we can use quadratic probing. Quadratic Probing Rather than searching the buckets for, we search the buckets A[(i + j) mod N] for j = 0, 1, 2, …, we search the buckets A[(i + j 2 ) mod N].

Double Hashing In this approach, we search the buckets A[(i+f(i)) mod N], where f(i) = j*h’(k) and h’(k) is the secondary hash function. In this approach, the secondary hash function is not allowed to be zero. A common choice is h’(k) = q – (k mod q) where q < N is some prime number, which can be divide by 1 and itself.

h’(k) = 6

Data Structure Exercises 17.1

The Ordered Dictionary ADT