Some Hashing Techniques (used to randomize the relative addresses) 1Prepared by Perla P. Cosme.

Slides:



Advertisements
Similar presentations
DATA REPRESENTATION CONVERSION.
Advertisements

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
NCUE CSIE Wireless Communications and Networking Laboratory CHAPTER 8 Hashing 1.
File Processing - Indirect Address Translation MVNC1 Hashing Indirect Address Translation Chapter 11.
When collision occur, how do we resolve the problem????
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.
Log Files. O(n) Data Structure Exercises 16.1.
Hashing Techniques.
Congruence class arithmetic. Definitions: a ≡ b mod m iff a mod m = b mod m. a  [b] iff a ≡ b mod m.
Introduction to Hashing & Hashing Techniques
2010/3/81 Lecture 8 on Physical Database DBMS has a view of the database as a collection of stored records, and that view is supported by the file manager.
FALL 2004CENG 3511 Hashing Reference: Chapters: 11,12.
On the Cryptographic Value of the q th Root Problem Cheryl Beaver Peter Gemmell Anna Johnston William Neumann.
CS Data Structures Chapter 8 Hashing (Concentrating on Static Hashing)
Hashing General idea: Get a large array
Data Structures Using C++ 2E Chapter 9 Searching and Hashing Algorithms.
Mental Math Computation. Multiply Mentally 84 × 25 What strategy did you use? Why did we choose 84 × 25 instead of 85 × 25?
November 2013 Network Team Institute
Number Systems - Part II
I am a two-digit number I am between 10 and 20 I am a multiple of 3
Data Structures Using C++1 Chapter 9 Search Algorithms.
1 Chapter 5 Hashing General ideas Methods of implementing the hash table Comparison among these methods Applications of hashing Compare hash tables with.
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.
ECE 250 Algorithms and Data Structures Douglas Wilhelm Harder, M.Math. LEL Department of Electrical and Computer Engineering University of Waterloo Waterloo,
Number Systems. Why binary numbers? Digital systems process information in binary form. That is using 0s and 1s (LOW and HIGH, 0v and 5v). Digital designer.
Computer Arithmetic and the Arithmetic Unit Lesson 2 - Ioan Despi.
Section 4.4: The RSA Cryptosystem Practice HW Handwritten and Maple Exercises p at end of class notes.
CPS120: Introduction to Computer Science Computer Math: Converting to Decimal.
Comp 335 File Structures Hashing.
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.
File Processing - Hash File Considerations MVNC1 Hash File Considerations.
Hashing – Part I CS 367 – Introduction to Data Structures.
Data Structures and Algorithms Hashing First Year M. B. Fayek CUFE 2010.
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.
Been-Chian Chien, Wei-Pang Yang, and Wen-Yang Lin 8-1 Chapter 8 Hashing Introduction to Data Structure CHAPTER 8 HASHING 8.1 Symbol Table Abstract Data.
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.
Hashing Basis Ideas A data structure that allows insertion, deletion and search in O(1) in average. A data structure that allows insertion, deletion and.
CHAPTER 8 SEARCHING CSEB324 DATA STRUCTURES & ALGORITHM.
Chinese Remainder Theorem Dec 29 Picture from ………………………
COSC 2007 Data Structures II Chapter 13 Advanced Implementation of Tables IV.
Hashing, Hashing Tables Chapter 8. Class Hierarchy.
Hashtables. An Abstract data type that supports the following operations: –Insert –Find –Remove Search trees can be used for the same operations but require.
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 CSCD 326 Data Structures I Hashing. 2 Hashing Background Goal: provide a constant time complexity method of searching for stored data The best traditional.
Data Structures Using C++
Chapter 9 Hashing Dr. Youssef Harrath
CS6045: Advanced Algorithms Data Structures. Hashing Tables Motivation: symbol tables –A compiler uses a symbol table to relate symbols to associated.
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 1 Lec# 12 Presented by Halla Abdel Hameed.
Data Structures Chapter 8: Hashing 8-1. Performance Comparison of Arrays and Trees Is it possible to perform these operations in O(1) ? ArrayTree Sorted.
Prepared By: Norakmar Binti Mohd Nadzari CHAPTER 2 ARITHMETIC AND LOGIC UNIT.
Congruence class arithmetic
LEARNING OBJECTIVES O(1), O(N) and O(LogN) access times. Hashing:
ITE102 – Computer Programming (C++)
Location in course textbook
Number System conversions
Hash Table.
Hash Table.
CSCE 3110 Data Structures & Algorithm Analysis
Digital Logic Design (CSNB163)
Data Structures – Week #7
What we learn with pleasure we never forget. Alfred Mercier
DATA STRUCTURES-COLLISION TECHNIQUES
DATA STRUCTURES-COLLISION TECHNIQUES
Presentation transcript:

Some Hashing Techniques (used to randomize the relative addresses) 1Prepared by Perla P. Cosme

Some Hashing Techniques 1.Prime Number Division Remainder Method 2.Digit Extraction 3.Folding 4.Radix Conversion 5.Mid-Square Prepared by Perla P. Cosme2

Some Hashing Techniques 1.Prime Number Division Remainder Method 2.Digit Extraction 3.Folding 4.Radix Conversion 5.Mid-Square Prepared by Perla P. Cosme3

Prime Number Division Remainder Method Similar with % (modulo or mod) function or the integer division remainder method The key of the record is used to apply the hash function where x = primary key of the record % = mod function PN = prime number Prepared by Perla P. Cosme4 h(x) = x % PN

Some notes to ponder 1.Why do we use the modulo function when we can choose any user-defined function? 2.Why would we choose a prime number when we can choose any positive integer no.? 3.Is the hash function given as h(x) = x % PN, the only function we can use? Prepared by Perla P. Cosme5

Prime Number Division Remainder Method Notes: 1.Choose PN such that it is the largest among the prime numbers based from the relative positions. Why? 2.Relative positions are pre-defined by the operating system (OS). But for purposes of illustration, we shall adopt in our class that our relative position could be any of the form 0..(N-1) positions. Prepared by Perla P. Cosme6

Just a simple mental exercise... Question: If the relative positions are labelled as 1..10, what would be the best choice for a prime number? Justify your answer. Prepared by Perla P. Cosme7

Another simple mental exercise... Question: If the relative positions are labelled as 1..99, what would be the best choice for a prime number? Justify your answer. Prepared by Perla P. Cosme8

Let’s try this... Assuming that there are 100 relative positions labeled as 0..99, and suppose we have the following key values: 24964, 25936, 32179, 39652, 40851, 53455, 53758, 54603, 63388, Questions: 1.Find the relative positions of these records using the hashing strategy called prime number division remainder method. 2.Determine the number of synonyms, if any. Prepared by Perla P. Cosme9

Answer Key ValuesRelative Positions No. of Synonyms0 Prepared by Perla P. Cosme10

Some Hashing Techniques 1.Prime Number Division Remainder Method 2.Digit Extraction 3.Folding 4.Radix Conversion 5.Mid-Square Prepared by Perla P. Cosme11

Digit Extraction This technique is advisable to use if and only if you have a prior knowledge in the distribution or placement of digits within the record’s primary key. Why? Prepared by Perla P. Cosme12

Digit Extraction Algorithm: 1.Lay all the primary keys of all records to be placed within the relative positions. 2.By cross examination, choose the positions or columns of digits to be extracted. 3.The relative position of the record is the concatenated digits from the chosen columns. Prepared by Perla P. Cosme13

Let’s try this... Assuming that there are 100 relative positions labeled as 0..99, and suppose we have the following key values: 24964, 25936, 32179, 39652, 40851, 53455, 53758, 54603, 63388, Questions: 1.Find the relative positions of these records using the hashing strategy called digit extraction. Let us choose the positions of the chosen digits as the 5 th and 3 rd. 2.Determine the number of synonyms, if any. Prepared by Perla P. Cosme14

Answer Key ValuesRelative Positions No. of Synonyms0 Prepared by Perla P. Cosme15

Some Hashing Techniques 1.Prime Number Division Remainder Method 2.Digit Extraction 3.Folding 4.Radix Conversion 5.Mid-Square Prepared by Perla P. Cosme16

Folding Algo: 1.Consider the key values as a sequence of digits. 2.By “folding” the sequence of digits, we end up as if we divide the digits into 2. 3.Add up the digits such that the first half of the digits becomes the first addend while the second half is composed of the digits belonging to the other half. Prepared by Perla P. Cosme17

Let’s try this... Assuming that there are 100 relative positions labeled as 0..99, and suppose we have the following key values: 24964, 25936, 32179, 39652, 40851, 53455, 53758, 54603, 63388, Questions: 1.Find the relative positions of these records using the hashing strategies called folding. Let us assume that the demarcation line (or where the folding is made) is after the 3 rd digit. 2.Determine the number of synonyms, if any. Prepared by Perla P. Cosme18

Answer Key ValuesRelative Positions No. of Synonyms1 Prepared by Perla P. Cosme19

Some Hashing Techniques 1.Prime Number Division Remainder Method 2.Digit Extraction 3.Folding 4.Radix Conversion 5.Mid-Square Prepared by Perla P. Cosme20

Radix Conversion Algorithm: (similar with conversion from one number system to another number system) 1.With each digit in the primary key, multiply each digit by powers of the chosen base number (or radix). The exponent must start from 0, and it increases as the number of digits increases. 2.Take the sum of all the products. 3.The last 2 digits of the computed sum is the relative address. Prepared by Perla P. Cosme21

Example Assume that our radix is 8. The octal number 12345, when converted to its base 10 will be computed as follows: = __________ 10 Prepared by Perla P. Cosme22

Let’s try this... Assuming that there are 100 relative positions labeled as 0..99, and suppose we have the following key values: 24964, 25936, 32179, 39652, 40851, 53455, 53758, 54603, 63388, Questions: 1.Find the relative positions of these records using the hashing strategies called radix conversion. Let us assume that the radix is base Determine the number of synonyms, if any. Prepared by Perla P. Cosme23

Answer Key ValuesRelative Positions No. of Synonyms0 Prepared by Perla P. Cosme24

Some Hashing Techniques 1.Prime Number Division Remainder Method 2.Digit Extraction 3.Folding 4.Radix Conversion 5.Mid-Square Prepared by Perla P. Cosme25

Mid-Square Algorithm: As the name implies, the randomization is done by taking the middle digits, then, square the middle values. The result is the relative address of the record. Prepared by Perla P. Cosme26

Point of Order If the relative positions ranges from 0..99, then take the last 2 digits of the result as the relative address of the record. Questions: 1.Why do we take the last 2 digits of the result as the relative address of the record – why not the first 2 digits or the middle digits, etc.? 2.If the relative positions are labelled as , which digits of the result (of mid-square operation) is considered as the relative address? Why? Prepared by Perla P. Cosme27

Notes to Ponder 1.It is not advisable to get only one digit as the middle number. Why? 2.If the number of digits in the key value is even, which digit positions are considered as the middle digits? Why? Prepared by Perla P. Cosme28

Let’s try this... Assuming that there are 100 relative positions labeled as 0..99, and suppose we have the following key values: 24964, 25936, 32179, 39652, 40851, 53455, 53758, 54603, 63388, Questions: 1.Find the relative positions of these records using the hashing strategies called mid-square. Let us take the 2 nd up to 4 th digits as our middle values. 2.Determine the number of synonyms, if any. Prepared by Perla P. Cosme29

Answer Key ValuesRelative Positions No. of Synonyms 3 Prepared by Perla P. Cosme30

That ends our discussion on the different hashing techniques. Are there questions????? Coming up next … rehashing techniques Prepared by Perla P. Cosme31