Скачать презентацию

Идет загрузка презентации. Пожалуйста, подождите

Презентация была опубликована 2 года назад пользователемАлина Ефремова

1 Hashing Lesson Plan - 8

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

3 ANNEXURE-I Evocation

4 Objective To study the basic concept of hashing techniques and algorithm

5 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))

6 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

7 Hashing

8 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

9 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

10 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

11 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)

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

13 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;

14 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

15 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

16 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

17 Optical Illusion What do you see in the image below?

18 Music Word search

19 Branches and Descriptions Anthology Pomology Batracology Petrology Odontology

20 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

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

22 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

23 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 : = : = : = : = : =

24 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

25 Hash Fold examples Fold Shift Fold boundary Discarded Digits reversed

26 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

27 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

28 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

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

30 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

31 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

Еще похожие презентации в нашем архиве:

Готово:

UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort.

UNIT-III SORTING Lesson Plan-1 Insertion Sort, Selection Sort.

© 2017 MyShared Inc.

All rights reserved.