Hashing Lesson Plan - 8. Contents Evocation Objective Introduction General idea Hash Tables Types of Hashing Hash function Hashing methods Hashing algorithm.

Презентация:



Advertisements
Похожие презентации
Collision Resolution Lesson Plan - 9. Contents Evocation Objective Introduction Collision Resolution Separate Chaining Open addressing Linked list Bucket.
Advertisements

Searching Lesson Plan - 6. Contents Evocation Objective Introduction Sequential Search Algorithm Variations on sequential search Mind map Summary.
PAT312, Section 21, December 2006 S21-1 Copyright 2007 MSC.Software Corporation SECTION 21 GROUPS.
Loader Design Options Linkage Editors Dynamic Linking Bootstrap Loaders.
Time-Series Analysis and Forecasting – Part IV To read at home.
UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort.
1/27 Chapter 9: Template Functions And Template Classes.
© The McGraw-Hill Companies, Inc., Chapter 4 Counting Techniques.
© 2005 Cisco Systems, Inc. All rights reserved. BGP v Route Selection Using Policy Controls Applying Route-Maps as BGP Filters.
AVL-Trees COMP171 Fall AVL Trees / Slide 2 Balanced binary tree * The disadvantage of a binary search tree is that its height can be as large as.
HPC Pipelining Parallelism is achieved by starting to execute one instruction before the previous one is finished. The simplest kind overlaps the execution.
DRAFTING TECHNIQUES I 136. Here is a basic shape. From here, we will do some advanced drafting once we put this shape on a sheet as a drawing. Select.
Knot theory. In topology, knot theory is the study of mathematical knots. While inspired by knots which appear in daily life in shoelaces and rope, a.
Sequences Sequences are patterns. Each pattern or number in a sequence is called a term. The number at the start is called the first term. The term-to-term.
Designing Network Management Services © 2004 Cisco Systems, Inc. All rights reserved. Designing the Network Management Architecture ARCH v
In mathematics, the notion of permutation is used with several slightly different meanings, all related to the act of permuting (rearranging) objects.
REFERENCE ELEMENTS 64. If your REFERENCE ELEMENTS toolbar is not in view and not hidden, you can retrieve it from the toolbars menu seen here. 65.
Business Statistics 1-1 Chapter Two Describing Data: Frequency Distributions and Graphic Presentation GOALS When you have completed this chapter, you will.
Using Dreamweaver MX Slide 1 Window menu Manage Sites… Window menu Manage Sites… 2 2 Open Dreamweaver 1 1 Set up a website folder (1). Click New…
BREADTH FIRST TRAVERSAL Lesson Plan -3. Evocation.
Транксрипт:

Hashing Lesson Plan - 8

Contents Evocation Objective Introduction General idea Hash Tables Types of Hashing Hash function Hashing methods Hashing algorithm Mind map Summary

ANNEXURE-I Evocation

Objective To study the basic concept of hashing techniques and algorithm

ANNEXURE-II Introduction-Hashing In hashed search, key through algorithmic function determines location of data Transform key into index that contains data need to locate Hashing is a key to address mapping process The implementation of hash tables is called hashing Hashing is a technique used for performing insertions, deletions and finds in constant average time (i.e.O(1))

General idea The ideal hash table structure is merely an array of some fixed size, containing the items A stored item needs to have a data member, called key, that will be used in computing the index value for the item Key could be an integer, a string, etc e.g. a name or Id that is a part of a large employee structure The size of the array is TableSize The items that are stored in the hash table are indexed by values from 0 to TableSize – 1 Each key is mapped into some number in the range 0 to TableSize – 1 The mapping is called a hash function

Hashing

Hash Tables There are two types of Hash Tables: Open-addressed Hash Tables and Separate-Chained Hash Tables An Open-addressed Hash Table is a one-dimensional array indexed by integer values that are computed by an index function called a hash function A Separate-Chained Hash Table is a one-dimensional array of linked lists indexed by integer values that are computed by an index function called a hash function Hash tables are sometimes referred to as scatter tables Typical hash table operations are: Initialization Insertion Searching Deletion

Types of Hashing There are two types of hashing : Static hashing: In static hashing, the hash function maps search-key values to a fixed set of locations Dynamic hashing: In dynamic hashing a hash table can grow to handle more items. The associated hash function must change as the table grows The load factor of a hash table is the ratio of the number of keys in the table to the size of the hash table Note: The higher the load factor, the slower the retrieval With open addressing, the load factor cannot exceed 1. With chaining, the load factor often exceeds 1

Hash Function Choice of hash function: Must be simple to compute Must distribute the keys evenly among the cells Minimal number of collisions If a hashing function groups key values together, this is called clustering of the keys A good hashing function distributes the key values uniformly throughout the range Problems: Keys may not be numeric Number of possible keys is much larger than the space available in table Different keys may map into same location Hash function is not one-to-one => collision If there are too many collisions, the performance of the hash table will suffer dramatically

Collision Resolution Collision occurs when hashing algorithm produces an address for insertion key and the address is already occupied Address produced by hash algorithm is home address Memory contains all home address is prime area When two keys collide at home address, resolve collision by placing one of keys and data in another location [0] [4] [8] [16] CAB B and A collide at 8 C and B collide at 16 1.hash(A) 2.hash(B) 3. hash (c)

Hashing Methods Hashing methods Direct Modulo division Mid squareRotation Subtraction Digit Extraction Folding Pseudorandom generation

Hashing methods Direct Method Key is the address without algorithmic manipulation Data structure contain element for possible key Example problem To analyze total monthly sales by days of month For each sale we need date and amount of sale To calculate sales record for month, we need day of month as key for array and add sales amount to accumulator daily Sales[ sale. day ] = daily Sales[ sale. day ] + sale. amount;

Direct Hashing of Employee numbers Key Address Hash [001] [002] [003] [004] [005] [006] [007] [008] [009] [099] [100] 000(Not used) 001Harry Lee 002Sarah Trapp 005Vu Nguymen 007Ray Black 100John Adams

Hashing Methods Subtraction method Direct and subtraction hash functions guarantee search effort of one with no collisions In one to one hashing method only one key hashes to each address Example Company have 100 employees, employee number starts from 1001 to 1100 Hashing function subtracts 1000 from key to determine address

ANNEXURE-III Rapid Eye Movement Exercise Imagine a huge clock in front of you Direct your focus on 12 o'clock, slowly move eyes clockwise around the clock without stopping at the reference hours. Do three complete rotations Focus straight ahead at the horizon and note changes in feelings, body sensations Repeat as many times as you feel necessary for any inner pacing

Optical Illusion What do you see in the image below?

Music Word search

Branches and Descriptions Anthology Pomology Batracology Petrology Odontology

Modulo Division Method Divides the key by array size and use remainder for address Algorithm works with any list size, but list size is a prime number produces fewer collisions address = key MODULO list Size

Modulo Division Hashing Hash [000] [001] [002] [003] [004] [005] [006] [007] [008] [305] Mary Dodd Bryan Devaux Partrick Linn Tuan Ngo Feldman [306]

Digit Extraction Method Digits are extracted from key and used as address Example Six digit employee number is used to hash three digit address ( ) Select first, third and fourth digits use them as address

Midsquare Method Key is squared and the address is selected from the middle of the squared number Example Given a key of 9452, midsquare address calculation is shown using four digit address ( ) = : address is 3403 Select first three digits and then use midsquare method : = : = : = : = : =

Folding Methods Two folding methods Fold shift Fold boundary Fold shift key value is divided into parts whose size matches size of required address Left and right parts are shifted and added with middle part In fold boundary, left and right numbers are folded on a fixed boundary between them and center number

Hash Fold examples Fold Shift Fold boundary Discarded Digits reversed

Rotation Method Rotation is used in combination with folding and pseudorandom hashing Hashing keys are identical except for last character Rotating last character to front of key and minimize the effect Example Consider case of six digit employee number that is used in large company Original Key RotationRotated Key

Pseudorandom Hashing Key is used as seed in pseudorandom number generator and the random number is scaled into possible address range using modulo-division Pseudorandom number generator generate same number of series A common random number generator is y = ax + c Example Assume a=17, c=7, x=121267,Prime number=307 y= ((17*121267) + 7) modulo 307 y= ( ) modulo 307 y= modulo 307 y= 41

Hashing Algorithm Algorithm hash (key size, maxAddr, addr) set looper to 0 set addr to 0 for each character in key if (character not space) add character to address rotate addr 12 bits right end if end loop if (addr < 0) addr = absolute (addr) end if addr = addr modulo maxAddr end hash

ANNEXURE-IV Mind Map Hashing General ideaTypes Hash Function Collision resolution Hashing Methods Hashing Algorithm

ANNEXURE-V Summary In hashed search, key through algorithmic function determines location of data Hashing functions including direct, subtraction, modulo division, digit extraction, midsquare, folding, rotation, pseudorandom generation In direct hashing, key is address without algorithmic manipulation In subtraction hashing key is transformed to address by subtracting a fixed number from it In modulo division hashing key is divided by list size and remainder plus 1 is used as address In digit extraction hashing select digits are extracted from key and used as address

Summary In midsquare hashing key is squared and address is selected from middle of result In fold shift hashing key is divided into parts whose size match size of required address. Then parts are added to obtain address In fold boundary hashing, key is divided into parts whose size match size of required address. Then left and right parts are reserved and added to middle part to obtain address In rotation hashing far right digit of key is rotated to left to determine address In pseudorandom generation hashing, key is used as seed to generate pseudorandom number. Result is scaled to obtain address