Hash Tables. Group Members: Syed Husnain Bukhari SP10-BSCS-92 Ahmad Inam SP10-BSCS-06 M.Umair Sharif SP10-BSCS-38.

Slides:



Advertisements
Similar presentations
Hash Tables CSC220 Winter What is strength of b-tree? Can we make an array to be as fast search and insert as B-tree and LL?
Advertisements

Hash Tables COT4810 Ken Pritchard 2 Sep 04.
CSE 1302 Lecture 23 Hashing and Hash Tables Richard Gesick.
HASH TABLE. HASH TABLE a group of people could be arranged in a database like this: Hashing is the transformation of a string of characters into a.
Lecture 6 Hashing. Motivating Example Want to store a list whose elements are integers between 1 and 5 Will define an array of size 5, and if the list.
Part II Chapter 8 Hashing Introduction Consider we may perform insertion, searching and deletion on a dictionary (symbol table). Array Linked list Tree.
Data Structures Using C++ 2E
Hashing as a Dictionary Implementation
File Processing - Indirect Address Translation MVNC1 Hashing Indirect Address Translation Chapter 11.
What we learn with pleasure we never forget. Alfred Mercier Smitha N Pai.
Appendix I Hashing. Chapter Scope Hashing, conceptually Using hashes to solve problems Hash implementations Java Foundations, 3rd Edition, Lewis/DePasquale/Chase21.
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.
Hashing21 Hashing II: The leftovers. hashing22 Hash functions Choice of hash function can be important factor in reducing the likelihood of collisions.
Searching Kruse and Ryba Ch and 9.6. Problem: Search We are given a list of records. Each record has an associated key. Give efficient algorithm.
Nov 12, 2009IAT 8001 Hash Table Bucket Sort. Nov 12, 2009IAT 8002  An array in which items are not stored consecutively - their place of storage is calculated.
Hashing Techniques.
© 2006 Pearson Addison-Wesley. All rights reserved13 A-1 Chapter 13 Hash Tables.
Hash Tables and Associative Containers CS-212 Dick Steflik.
Data Structures Using Java1 Chapter 8 Search Algorithms.
Hash Tables1 Part E Hash Tables  
Hashing General idea: Get a large array
Data Structures Using C++ 2E Chapter 9 Searching and Hashing Algorithms.
Aree Teeraparbseree, Ph.D
Hashing Lesson Plan - 8.
Introducing Hashing Chapter 21 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
© 2006 Pearson Addison-Wesley. All rights reserved13 B-1 Chapter 13 (excerpts) Advanced Implementation of Tables CS102 Sections 51 and 52 Marc Smith and.
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.
Searching Chapter 2.
Data Structures Using Java1 Chapter 8 Search Algorithms.
Chapter 13 File Structures. Understand the file access methods. Describe the characteristics of a sequential file. After reading this chapter, the reader.
Symbol Tables Symbol tables are used by compilers to keep track of information about variables functions class names type names temporary variables etc.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture8.
CS212: DATA STRUCTURES Lecture 10:Hashing 1. Outline 2  Map Abstract Data type  Map Abstract Data type methods  What is hash  Hash tables  Bucket.
File Structures Foundations of Computer Science  Cengage Learning.
Hashing Table Professor Sin-Min Lee Department of Computer Science.
Appendix E-A Hashing Modified. Chapter Scope Concept of hashing Hashing functions Collision handling – Open addressing – Buckets – Chaining Deletions.
Comp 335 File Structures Hashing.
©Brooks/Cole, 2003 Chapter 13 File Structures. ©Brooks/Cole, 2003 Understand the file access methods. Describe the characteristics of a sequential file.
13. File Structures. ACCESSMETHODSACCESSMETHODS 13.1.
1 5. Abstract Data Structures & Algorithms 5.2 Static Data Structures.
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.
Hashing as a Dictionary Implementation Chapter 19.
CS201: Data Structures and Discrete Mathematics I Hash Table.
Hash Tables. Introduction A hash table is a data structure that stores things and allows insertions, lookups, and deletions to be performed in O(1) time.
Data Structures and Algorithms Hashing First Year M. B. Fayek CUFE 2010.
1 Hashing - Introduction Dictionary = a dynamic set that supports the operations INSERT, DELETE, SEARCH Dictionary = a dynamic set that supports the operations.
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.
Chapter 11 Hash Tables © John Urrutia 2014, All Rights Reserved1.
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables IV.
Hashed Files Text Versus Binary Meghan Cavanagh. Hashed Files a file that is searched using one of the hashing methods User gives the key, the function.
1 Chapter 9 Searching And Table. 2 OBJECTIVE Introduces: Basic searching concept Type of searching Hash function Collision problems.
Hashing. Hashing is the transformation of a string of characters into a usually shorter fixed-length value or key that represents the original string.
Hashing O(1) data access (almost) -access, insertion, deletion, updating in constant time (on average) but at a price… references: Weiss, Goodrich & Tamassia,
Sets and Maps Chapter 9. Chapter Objectives  To understand the Java Map and Set interfaces and how to use them  To learn about hash coding and its use.
Hash Tables. Group Members: Syed Husnain Bukhari SP10-BSCS-92 Ahmad Inam SP10-BSCS-06 M.Umair Sharif SP10-BSCS-38.
Appendix I Hashing.
School of Computer Science and Engineering
Slides by Steve Armstrong LeTourneau University Longview, TX
Review Graph Directed Graph Undirected Graph Sub-Graph
Hash Table.
Hash Tables.
Chapter 10 Hashing.
Data Structures Hashing 1.
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 and Associative Containers
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
Data Structures – Week #7
What we learn with pleasure we never forget. Alfred Mercier
Collision Resolution.
Presentation transcript:

Hash Tables

Group Members: Syed Husnain Bukhari SP10-BSCS-92 Ahmad Inam SP10-BSCS-06 M.Umair Sharif SP10-BSCS-38

Description A hash table is a data structure that stores things and allows insertions, lookups, and deletions to be performed in O(1) time. An algorithm converts an object, typically a string, to a number. Then the number is compressed according to the size of the table and used as an index. There is the possibility of distinct items being mapped to the same key. This is called a collision and must be resolved.

Key  Hash Code Generator  Number  Compression  Index Smith  Bob Smith 123 Main St. Orlando, FL

Definition: Hashing is a key-to-address mapping process. Terms must be familiarized. Collision: A collision occurs when a hashing algorithm produces an address for an insertion key and that address is already occupied. Home address: The address produced by the hashing algorithm is known as the home address. Prime area: The memory that contains all of the home addresses is known as the prime area. Probe: Each calculation of an address and test for success is known as a probe.

Collision Resolution There are two kinds of collision resolution: 1 – Chaining makes each entry a linked list so that when a collision occurs the new entry is added to the end of the list. 2 – Open Addressing uses probing to discover an empty spot. With chaining, the table does not have to be resized. With open addressing, the table must be resized when the number of elements is larger than the capacity.

Smith  Bob Smith 123 Main St. Orlando, FL Jim Smith 123 Elm St. Orlando, FL Chaining

Smith  Bob Smith 123 Main St. Orlando, FL Jim Smith 123 Elm St. Orlando, FL Probing

Hashing Methods There are eight hashing methods they are: 1: Direct method 2: Subtraction method 3: Modulo-division 4: Mid square 5: Digit extraction 6: Rotation 7: Folding 8: Pseudorandom generation

Hashing Methods Direct Method In direct hashing the key is the address without any algorithmic manipulation. Direct hashing is limited, but it can be very powerful because it guarantees that there are no synonyms and therefore no collision.

Modulo-division Method This is also known as division remainder method. This algorithm works with any list size, but a list size that is a prime number produces fewer collisions than other list sizes. The formula to calculate the address is: Address = key MODULO listsize + 1 Where listsize is the number of elements in the array.

Example: Given data : Keys are : % = % = % = 2

Digit-extraction Method Using digit extraction selected digits are extracted from the key and used as the address. Example : Using six-digit employee number to hash to a three digit address ( ), we could select the first, third, and fourth digits( from the left) and use them as the address. The keys are: > > > 388

Folding Method Two folding methods are used they are: 1: Fold shift 2: Fold boundary 1: Fold Shift In fold shift the key value is divided into parts whose size matches the size of the required address. Then the left and right parts are shifted and added with the middle part.

Fold boundary In fold boundary the left and right numbers are folded on a fixed boundary between them and the center number. The two outside values are thus reversed.

Midsquare Method In midsquare hashing the key is squared and the address is selected from the middle of the square number. Limitation is the size of the key. Example: = : address is 3403

Rotation Method Rotation method is generally not used by itself but rather is incorporated in combination with other hashing methods. It is most useful when keys are assigned serially.

Pseudorandom Hashing A common random-number generator is shown below. y= ax + c To use the pseudorandom-number generator as a hashing method, we set x to the key, multiply it by the coefficient a, and then add the constant c. The result is then divided by the list size, with the remainder being the hashed address. Example: Y= ((17 * ) + 7) modulo 307 Y= ( ) modulo 307 Y= Y=41

Hash Table Uses Compilers use hash tables for symbol storage. The Linux Kernel uses hash tables to manage memory pages and buffers. High speed routing tables use hash tables. Database systems use hash tables.

Summary A hash table is a convenient data structure for storing items that provides O(1) access time. The concepts that drive selection of the key generation and compression functions can be complicated, but there is a lot of research information available. There are many areas where hash tables are used. Modern programming languages typically provide a hash table implementation ready for use in applications.

References Knuth, Donald A. The Art of Computer Programming. Philippines: Addison-Wesley Publishing Company, Loudon, Kyle. Mastering Algorithms with C. Sebastopol: O’Reilly & Associates, 1999 Watt, David A., and Deryck F. Brown. Java Collections. West Sussex: John Wiley & Sons, 2001 Dewdney, A. K. The New Turing Omnibus. New York: Henry Holt and Company, 2001

Any Question