CHAPTER 9 HASH TABLES, MAPS, AND SKIP LISTS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++,

Slides:



Advertisements
Similar presentations
Skip Lists. Outline and Reading What is a skip list (§9.4) – Operations (§9.4.1) – Search – Insertion – Deletion Implementation Analysis (§9.4.2) – Space.
Advertisements

© 2004 Goodrich, Tamassia Hash Tables
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.
Briana B. Morrison Adapted from William Collins
© 2004 Goodrich, Tamassia Hash Tables
CSCE 3400 Data Structures & Algorithm Analysis
Skip List & Hashing CSE, POSTECH.
Hashing as a Dictionary Implementation
© 2004 Goodrich, Tamassia Hash Tables1  
Hashing Chapters What is Hashing? A technique that determines an index or location for storage of an item in a data structure The hash function.
Chapter 9: Maps, Dictionaries, Hashing Nancy Amato Parasol Lab, Dept. CSE, Texas A&M University Acknowledgement: These slides are adapted from slides provided.
Maps. Hash Tables. Dictionaries. 2 CPSC 3200 University of Tennessee at Chattanooga – Summer 2013 © 2010 Goodrich, Tamassia.
Data Structures Lecture 12 Fang Yu Department of Management Information Systems National Chengchi University Fall 2010.
Data Structures Lecture 13 Fang Yu Department of Management Information Systems National Chengchi University Fall 2010.
Maps, Dictionaries, Hashtables
© 2004 Goodrich, Tamassia Skip Lists1  S0S0 S1S1 S2S2 S3S3    2315.
Dictionaries and Hash Tables1  
1 Chapter 9 Maps and Dictionaries. 2 A basic problem We have to store some records and perform the following: add new record add new record delete record.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 48 Hashing.
Hash Tables1 Part E Hash Tables  
Hash Tables1 Part E Hash Tables  
Hash Tables1 Part E Hash Tables  
COMP 171 Data Structures and Algorithms Tutorial 10 Hash Tables.
Data Structures Using C++ 2E Chapter 9 Searching and Hashing Algorithms.
Skip Lists1 Skip Lists William Pugh: ” Skip Lists: A Probabilistic Alternative to Balanced Trees ”, 1990  S0S0 S1S1 S2S2 S3S3 
Dictionaries 4/17/2017 3:23 PM Hash Tables  
Introducing Hashing Chapter 21 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Maps, Dictionaries, Hashing
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.
CS 221 Analysis of Algorithms Data Structures Dictionaries, Hash Tables, Ordered Dictionary and Binary Search Trees.
1 HashTable. 2 Dictionary A collection of data that is accessed by “key” values –The keys may be ordered or unordered –Multiple key values may/may-not.
Hash Tables1   © 2010 Goodrich, Tamassia.
Dictionaries and Hash Tables1 Hash Tables  
1 CSE 326: Data Structures: Hash Tables Lecture 12: Monday, Feb 3, 2003.
Maps, Hash Tables, Skip Lists, Sets last Update: Nov 4, 2014 EECS2011: Maps, Hash Tables, Skip Lists, Sets1.
© 2004 Goodrich, Tamassia Hash Tables1  
Hashing as a Dictionary Implementation Chapter 19.
1 Hashing - Introduction Dictionary = a dynamic set that supports the operations INSERT, DELETE, SEARCH Dictionary = a dynamic set that supports the operations.
Tirgul 11 Notes Hash tables –reminder –examples –some new material.
1 Chapter 7 Skip Lists and Hashing Part 2: Hashing.
CH 9 : MAPS AND DICTIONARIES 1 ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA.
Prof. Amr Goneid, AUC1 CSCI 210 Data Structures and Algorithms Prof. Amr Goneid AUC Part 5. Dictionaries(2): Hash Tables.
Lecture14: Hashing Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
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.
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.
Advanced Associative Structures
Chapter 28 Hashing.
Skip Lists.
Data Structures Maps and Hash.
Dictionaries 11/23/2018 5:34 PM Hash Tables   Hash Tables.
Dictionaries and Hash Tables
Chapter 21 Hashing: Implementing Dictionaries and Sets
Hash Tables   Maps Dictionaries 12/7/2018 5:58 AM Hash Tables  
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.
Parasol Lab, Dept. CSE, Texas A&M University
Hash Tables Computer Science and Engineering
CH 9 : Maps And Dictionary
Hash Tables Computer Science and Engineering
Dictionaries 4/5/2019 1:49 AM Hash Tables  
CS210- Lecture 17 July 12, 2005 Agenda Collision Handling
CS210- Lecture 16 July 11, 2005 Agenda Maps and Dictionaries Map ADT
Dictionaries and Hash Tables
Presentation transcript:

CHAPTER 9 HASH TABLES, MAPS, AND SKIP LISTS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++, GOODRICH, TAMASSIA AND MOUNT (WILEY 2004) AND SLIDES FROM NANCY M. AMATO  

READING Map ADT (Ch. 9.1) Dictionary ADT (Ch. 9.5) Ordered Maps (Ch. 9.3) Hash Tables (Ch. 9.2)

MAP ADT A map models a searchable collection of key-value pair (called entries) Multiple items with the same key are not allowed Applications: address book or student records mapping host names (e.g., cs16.net) to internet addresses (e.g., ) Often called “associative” containers

LIST-BASED MAP IMPLEMENTATION tail header nodes/positions entries 9 c 6 c 5 c 8 c

DIRECT ADDRESS TABLE MAP IMPLEMENTATION

DICTIONARY ADT The dictionary ADT models a searchable collection of key-value entries The main difference from a map is that multiple items with the same key are allowed Any data structure that supports a dictionary also supports a map Applications: Dictionary which has multiple definitions for the same word

ORDERED MAP/DICTIONARY ADT An Ordered Map/Dictionary supports the usual map/dictionary operations, but also maintains an order relation for the keys. Naturally supports Ordered search tables - store dictionary in a vector by non-decreasing order of the keys Utilizes binary search

EXAMPLE OF ORDERED MAP: BINARY SEARCH m l h m l h m l h l  m  h

MAP/DICTIONARY IMPLEMENTATIONS Space Unsorted list Direct Address Table (map only) Ordered Search Table (ordered map/dictionary)

CH. 9.2 HASH TABLES

HASH TABLES

ISSUES WITH HASH TABLES Issues Collisions - some keys will map to the same index of H (otherwise we have a Direct Address Table). Chaining - put values that hash to same location in a linked list (or a “bucket”) Open addressing - if a collision occurs, have a method to select another location in the table. Load factor Rehashing

EXAMPLE     …

HASH FUNCTIONS

HASH CODES Memory address: We reinterpret the memory address of the key object as an integer Good in general, except for numeric and string keys Integer cast: We reinterpret the bits of the key as an integer Suitable for keys of length less than or equal to the number of bits of the integer type (e.g., byte, short, int and float in C++) Component sum: We partition the bits of the key into components of fixed length (e.g., 16 or 32 bits) and we sum the components (ignoring overflows) Suitable for numeric keys of fixed length greater than or equal to the number of bits of the integer type (e.g., long and double in C++)

HASH CODES Cyclic Shift: Like polynomial accumulation except use bit shifts instead of multiplications and bitwise or instead of addition Can be used on floating point numbers as well by converting the number to an array of characters

COMPRESSION FUNCTIONS

COLLISION RESOLUTION WITH SEPARATE CHAINING Collisions occur when different elements are mapped to the same cell Separate Chaining: let each cell in the table point to a linked list of entries that map there Chaining is simple, but requires additional memory outside the table   

EXERCISE SEPARATE CHAINING

COLLISION RESOLUTION WITH OPEN ADDRESSING - LINEAR PROBING

SEARCH WITH LINEAR PROBING

UPDATES WITH LINEAR PROBING

EXERCISE OPEN ADDRESSING – LINEAR PROBING

COLLISION RESOLUTION WITH OPEN ADDRESSING – QUADRATIC PROBING

COLLISION RESOLUTION WITH OPEN ADDRESSING - DOUBLE HASHING

PERFORMANCE OF HASHING

UNIFORM HASHING ASSUMPTION

PERFORMANCE OF UNIFORM HASHING

ON REHASHING Keeping the load factor low is vital for performance When resizing the table: Reallocate space for the array Design a new hash function (new parameters) for the new array size For each item you reinsert it into the table

SUMMARY MAPS/DICTIONARIES (SO FAR) Space Log File Direct Address Table (map only) Lookup Table (ordered map/dictionary) Hashing (chaining) Hashing (open addressing)

CH. 9.4 SKIP LISTS  S0S0 S1S1 S2S2 S3S3    2315

RANDOMIZED ALGORITHMS

WHAT IS A SKIP LIST?     31  64  3134  23 S0S0 S1S1 S2S2 S3S3

IMPLEMENTATION x quad-node

 S0S0 S1S1 S2S2 S3S3  31  64  3134   

EXERCISE SEARCH  S0S0 S1S1 S2S2 S3S3  31  64  3134   

 S0S0 S1S1 S2S2 S3S3    2315  1036  23  S0S0 S1S1 S2S2 p0p0 p1p1 p2p2

 4512  23  S0S0 S1S1 S2S2  S0S0 S1S1 S2S2 S3S3    2334 p0p0 p1p1 p2p2

SPACE USAGE

HEIGHT

SEARCH AND UPDATE TIMES

EXERCISE You are working for ObscureDictionaries.com a new online start-up which specializes in sci-fi languages. The CEO wants your team to describe a data structure which will efficiently allow for searching, inserting, and deleting new entries. You believe a skip list is a good idea, but need to convince the CEO. Perform the following: Illustrate insertion of “X-wing” into this skip list. Randomly generated (1, 1, 1, 0). Illustrate deletion of an incorrect entry “Enterprise” Argue the complexity of deleting from a skip list   YodaBoba Fett  Enterprise   S0S0 S1S1 S2S2

SUMMARY Using a more complex probabilistic analysis, one can show that these performance bounds also hold with high probability Skip lists are fast and simple to implement in practice