Hashing 1 Lec# 12 Presented by Halla Abdel Hameed.

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

CS Data Structures Chapter 8 Hashing.
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.
Hashing. CENG 3512 Motivation The primary goal is to locate the desired record in a single access of disk. – Sequential search: O(N) – B+ trees: O(log.
CSCE 3400 Data Structures & Algorithm Analysis
Skip List & Hashing CSE, POSTECH.
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.
Hashing Part One Reaching for the Perfect Search Most of this material stolen from "File Structures" by Folk, Zoellick and Riccardi.
Chapter 11. Hashing.
Log Files. O(n) Data Structure Exercises 16.1.
1.1 Data Structure and Algorithm Lecture 9 Hashing Topics Reference: Introduction to Algorithm by Cormen Chapter 12: Hash Tables.
1 Hashing (Walls & Mirrors - end of Chapter 12). 2 I hate quotations. Tell me what you know. – Ralph Waldo Emerson.
© 2006 Pearson Addison-Wesley. All rights reserved13 A-1 Chapter 13 Hash Tables.
Hash Tables1 Part E Hash Tables  
Hash Tables1 Part E Hash Tables  
Quick Review of material covered Apr 8 B+-Tree Overview and some definitions –balanced tree –multi-level –reorganizes itself on insertion and deletion.
COMP 171 Data Structures and Algorithms Tutorial 10 Hash Tables.
Hashing General idea: Get a large array
CpSc 3220 File and Database Processing Hashing. Exercise – Build a B + - Tree Construct an order-4 B + -tree for the following set of key values: (2,
ICS220 – Data Structures and Algorithms Lecture 10 Dr. Ken Cosh.
CS212: DATA STRUCTURES Lecture 10:Hashing 1. Outline 2  Map Abstract Data type  Map Abstract Data type methods  What is hash  Hash tables  Bucket.
CHAPTER 09 Compiled by: Dr. Mohammad Omar Alhawarat Sorting & Searching.
Hashing Table Professor Sin-Min Lee Department of Computer Science.
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.
Comp 335 File Structures Hashing.
Hashing Sections 10.2 – 10.3 CS 302 Dr. George Bebis.
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.
Chapter 12 Hash Table. ● So far, the best worst-case time for searching is O(log n). ● Hash tables  average search time of O(1).  worst case search.
March 23 & 28, Csci 2111: Data and File Structures Week 10, Lectures 1 & 2 Hashing.
March 23 & 28, Hashing. 2 What is Hashing? A Hash function is a function h(K) which transforms a key K into an address. Hashing is like indexing.
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.
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.
Hash Table March COP 3502, UCF 1. Outline Hash Table: – Motivation – Direct Access Table – Hash Table Solutions for Collision Problem: – Open.
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables IV.
Data Structures1 Overview(1) O(1) access to files Variation of the relative file Record number for a record is not arbitrary; rather, it is obtained by.
Hashing Suppose we want to search for a data item in a huge data record tables How long will it take? – It depends on the data structure – (unsorted) linked.
Hashtables. An Abstract data type that supports the following operations: –Insert –Find –Remove Search trees can be used for the same operations but require.
Hashing 1 Hashing. Hashing 2 Hashing … * Again, a (dynamic) set of elements in which we do ‘search’, ‘insert’, and ‘delete’ n Linear ones: lists, stacks,
Copyright © Curt Hill Hashing A quick lookup strategy.
1 CSCD 326 Data Structures I Hashing. 2 Hashing Background Goal: provide a constant time complexity method of searching for stored data The best traditional.
Hashing by Rafael Jaffarove CS157b. Motivation  Fast data access  Search  Insertion  Deletion  Ideal seek time is O(1)
1 Chapter 9 Searching And Table. 2 OBJECTIVE Introduces: Basic searching concept Type of searching Hash function Collision problems.
File Structure SNU-OOPSLA Lab 1 Chap11. Hashing Chap11. Hashing 서울대학교 컴퓨터공학부 객체지향시스템연구실 SNU-OOPSLA-LAB 교수 김 형 주 File Strutures by Folk, Zoellick and Riccardi.
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. 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.
Hashing, Hash Function, Collision & Deletion
Hash table CSC317 We have elements with key and satellite data
LEARNING OBJECTIVES O(1), O(N) and O(LogN) access times. Hashing:
Subject Name: File Structures
EEE2108: Programming for Engineers Chapter 8. Hashing
Review Graph Directed Graph Undirected Graph Sub-Graph
Dictionaries Dictionaries 07/27/16 16:46 07/27/16 16:46 Hash Tables 
Hash functions Open addressing
Hash Table.
Hash Table.
Hash Tables.
Chapter 10 Hashing.
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
CS202 - Fundamental Structures of Computer Science II
Hashing Sections 10.2 – 10.3 Lecture 26 CS302 Data Structures
Chapter 11. Hashing.
Hashing.
What we learn with pleasure we never forget. Alfred Mercier
Lecture-Hashing.
Presentation transcript:

Hashing 1 Lec# 12 Presented by Halla Abdel Hameed

1.Introduction to Hashing. 2.Hash functions 3.Distribution of records among addresses(synonyms and collisions) 4.Collision resolution by progressive overflow or linear probing Contents….

Hashing is a useful searching technique, used for implementing indexes. The main motivation for Hashing is improving searching time. Hashing search time compared to other: 1.Simple Indexes (using binary search) :O (Log 2 N) 2.B Trees and B+ trees (will see later) : O ( log k N) 3.Hashing: O(1) Motivation

What is Hashing? The idea is to discover the location of a key by simply examining the key, For that we need to design a hash function. A Hash Function is a function h(k) that transforms a key into an address (the available addresses is specified first) If we have 1000 address and U is the set of all possible keys, the hash function is from U to {0,1,…,999} h: U {0,1,…,999}

Example of Hashing Function

Hint ….. There is no obvious connection between the key and the location….(Randomizing) Two different keys may be sent to the same address generating a Collision. Example of collision: LOWELL- LOCK- OLIVER and any word with first two letters L and O will be mapped to the same address So…h(LOWELL) = h(LOCK)= h(OLIVER)=4 Home Address Synonyms

Collision… Avoiding collisions is extremely difficult Birthday Paradox Ways of reducing collisions: 1.Spread out the records by choosing a good hash function 2.Use extra memory:increase the size of the address space (Ex reserve 5000 available addresses rather than 1000) 3.Put more than one record at a single address ( use of buckets)

A Simple Hash Function To compute this hash function apply 3 steps: Step 1 : transform the key into a number Step 2: fold and add (chop off pieces of the number and add them together) and take the mod by a prime number

A Simple Hash Function..con. Step3: divide by the size of the address space preferably a prime number

Distribution of Records among Addresses There are3 possibilities Uniform distributions are extremely rare Random distributions are acceptable and more easily obtainable

What is better than Random Distribution? Examine keys for patterns: Numerical keys spread out naturally such as keys are years between ( ) Use prime number when dividing the key : Dividing by a number is good when there are sequences of consecutive numbers When there is no natural separation between keys try randomization

Example of Hash Functions…

Collision Resolution : Progressive Overflow Progressive Overflow/ linear probing works as follows: Insertion of key k: 1.Go to the home address of k : h(k) 2.If free place the key there. 3.If occupied try the next position until an empty position is found (the next position for the last position is position 0 i.e. wrap around)

Searching for key k 1.Go to the home address of k :h(k) 2.If k is in home address we are done 3.Otherwise try the next position until key is found or empty space is found or home address is reached (in the last 2 cases the key is not found)

Search length,,,, Search Length is the Number of accesses required to retrieve a record