Linear Hashing Example

Slides:



Advertisements
Similar presentations
1 Symbol Tables. 2 Contents Introduction Introduction A Simple Compiler A Simple Compiler Scanning – Theory and Practice Scanning – Theory and Practice.
Advertisements

Dana Shapira Hash Tables
Extendible Hashing - Class Example
External Memory Hashing. Model of Computation Data stored on disk(s) Minimum transfer unit: a page = b bytes or B records (or block) N records -> N/B.
CS4432: Database Systems II Hash Indexing 1. Hash-Based Indexes Adaptation of main memory hash tables Support equality searches No range searches 2.
File Organizations Sept. 2012Yangjun Chen ACS Outline: Hashing (5.9, 5.10, 3 rd. ed.; 13.8, 4 th, 5 th ed.; 17.8, 6 th ed.) external hashing static.
1 Linear Hashing Appendix for Chapter 1. 2 Linear Hashing Allow a hash file to expand and shrink dynamically without needing a directory. Suppose the.
Hash Tables Hash function h: search key  [0…B-1]. Buckets are blocks, numbered [0…B-1]. Big idea: If a record with search key K exists, then it must be.
Lecture 6 : Dynamic Hashing Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University.
Additional notes on Hashing And notes on HW4. Selected Answers to the Last Assignment The records will hash to the following buckets: K h(K) (bucket number)
Copyright 2003Curt Hill Hash indexes Are they better or worse than a B+Tree?
Hash Tables Hash function h: search key  [0…B-1]. Buckets are blocks, numbered [0…B-1]. Big idea: If a record with search key K exists, then it must be.
Hash Table indexing and Secondary Storage Hashing.
Overflow Handling An overflow occurs when the home bucket for a new pair (key, element) is full. We may handle overflows by:  Search the hash table in.
External Memory Hashing. Hash Tables Hash function h: search key  [0…B-1]. Buckets are blocks, numbered [0…B-1]. Big idea: If a record with search key.
FALL 2004CENG 3511 Hashing Reference: Chapters: 11,12.
Chapter 13.4 Hash Tables Steve Ikeoka ID: 113 CS 257 – Spring 2008.
1 Hash-Based Indexes Chapter Introduction : Hash-based Indexes  Best for equality selections.  Cannot support range searches.  Static and dynamic.
HASH TABLES Malathi Mansanpally CS_257 ID-220. Agenda: Extensible Hash Tables Insertion Into Extensible Hash Tables Linear Hash Tables Insertion Into.
Data Structures Using C++ 2E Chapter 9 Searching and Hashing Algorithms.
Comp 335 File Structures Hashing.
Hashing and Hash-Based Index. Selection Queries Yes! Hashing  static hashing  dynamic hashing B+-tree is perfect, but.... to answer a selection query.
Lecture 5 Cost Estimation and Data Access Methods.
Insert using Linear Hashing h H level (n) = level+1 bits of nLevel = 0, next = 7 Insert 2, h 0 (2) = 0 initial 4 = 100, so h 0 (4) = 0 7 = 111,
Linear Equations in Two Variables A Linear Equation in Two Variables is any equation that can be written in the form where A and B are not both zero.
Overflow Handling An overflow occurs when the home bucket for a new pair (key, element) is full. We may handle overflows by:  Search the hash table in.
6.830 Lecture 6 9/28/2015 Cost Estimation and Indexing.
Database Management 7. course. Reminder Disk and RAM RAID Levels Disk space management Buffering Heap files Page formats Record formats.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Hash-Based Indexes Chapter 11 Modified by Donghui Zhang Jan 30, 2006.
File Organizations Jan. 2008Yangjun Chen ACS Outline: Hashing (5.9, 5.10, 3 rd. ed.; 13.8, 4 th ed.) external hashing static hashing & dynamic hashing.
Static Hashing (using overflow for collision managment e.g., h(key) mod M h key Primary bucket pages 1 0 M-1 Overflow pages(as separate link list) Overflow.
Hashing with Buckets. read = 10.
CPSC 461 Final Review I Hessam Zakerzadeh Dina Said.
Chapter 5: Hashing Collision Resolution: Open Addressing Extendible Hashing Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova,
1 Lecture 21: Hash Tables Wednesday, November 17, 2004.
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.
Database Management 7. course. Reminder Disk and RAM RAID Levels Disk space management Buffering Heap files Page formats Record formats.
Chapter 27 Hashing Jung Soo (Sue) Lim Cal State LA.
Data Structures Using C++ 2E
Dynamic Hashing (Chapter 12)
Hash Tables (Chapter 13) Part 2.
Lecture 21: Hash Tables Monday, February 28, 2005.
Are they better or worse than a B+Tree?
Hashing CENG 351.
Insert using Linear Hashing
Data Structures Using C++ 2E
Quadratic probing Double hashing Removal and open addressing Chaining
External Memory Hashing
Hash In-Class Quiz.
Introduction to Database Systems
Chapter 21 Hashing: Implementing Dictionaries and Sets
Collision Resolution Neil Tang 02/18/2010
External Memory Hashing
Double hashing Removal (open addressing) Chaining
External Memory Hashing
static hashing & dynamic hashing hash function
Hashing.
Overflow Handling An overflow occurs when the home bucket for a new pair (key, element) is full. We may handle overflows by: Search the hash table in some.
Index tuning Hash Index.
A Hash Table with Chaining
Chapter 11: Hash Tables.
Collision Resolution Neil Tang 02/21/2008
Chapter 11: Hash Tables.
CPSC-608 Database Systems
Index tuning Hash Index.
Extendable hashing M.B.Chandak.
DATA STRUCTURES-COLLISION TECHNIQUES
Extendible Hashing Example
Chapter 13 Hashing © 2011 Pearson Addison-Wesley. All rights reserved.
Collision Resolution: Open Addressing Extendible Hashing
Presentation transcript:

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( x) = x mod 4 h2( x) = x mod 8 n = 0 Two hash functions reflect this size 1 Original hash table size = 4 2 3 Initial cutoff set to 0

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( x) = x mod 4 h2( x) = x mod 8 n = 0 1 2 3

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(12) = 12 mod 4 = 0 h2( x) = x mod 8 n = 0 12 Use h1(x) as long as its >= cutoff 1 2 3

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(17) = 17 mod 4 = 1 h2( x) = x mod 8 n = 0 12 1 17 2 3

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(10) = 10 mod 4 = 2 h2( x) = x mod 8 n = 0 12 1 17 2 10 3

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 6) = 6 mod 4 = 2 h2( x) = x mod 8 n = 0 12 1 17 2 10 6 3

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(24) = 24 mod 4 = 0 h2( x) = x mod 8 n = 0 12 24 1 17 2 10 6 3

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(14) = 14 mod 4 = 2 h2( x) = x mod 8 n = 0 12 Overflow, so 24 1 17 2 10 6 3

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(14) = 14 mod 4 = 2 h2( x) = x mod 8 n = 0 12 Overflow, so 24 1) add chained block 1 17 2 10 6 14 3

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(14) = 14 mod 4 = 2 h2( x) = x mod 8 12 Overflow, so 24 n = 1 2) increment cutoff value 1 17 2 10 6 14 3

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(14) = 14 mod 4 = 2 h2( x) = x mod 8 12 Overflow, so 24 n = 1 3) split bucket 0 into two buckets 1 17 2 10 6 14 3 4

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(14) = 14 mod 4 = 2 h2( x) = x mod 8 12 Overflow, so 24 n = 1 4) rehash values in bucket 0 using h2(x) 1 17 2 10 6 14 3 4

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(14) = 14 mod 4 = 2 h2( x) = x mod 8 24 Overflow, so n = 1 4) rehash values in bucket 0 using h2(x) 1 17 2 10 6 14 3 4 12

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 5) = 5 mod 4 = 1 h2( x) = x mod 8 24 n = 1 1 17 5 2 10 6 14 3 4 12

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(20) = 20 mod 4 = 0 h2( x) = x mod 8 24 h1(20) < cutoff, so … n = 1 1 17 5 2 10 6 14 3 4 12

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(20) = 20 mod 4 = 0 h2(20) = 20 mod 8 = 4 24 h1(20) < cutoff, so use h2(20) n = 1 1 17 5 2 10 6 14 3 4 12 20

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 1) = 1 mod 4 = 1 h2( x) = x mod 8 24 Overflow, so n = 1 1) add chained block 1 17 5 1 2 10 6 14 3 4 12 20

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 1) = 1 mod 4 = 1 h2( x) = x mod 8 24 Overflow, so 2) increment cutoff value 3) split bucket 1 1 17 5 1 n = 2 2 10 6 14 3 4 12 20 5

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 1) = 1 mod 4 = 1 h2( x) = x mod 8 24 Overflow, so 4) rehash values in bucket 1 using h2(x) 1 17 5 1 n = 2 2 10 6 14 3 4 12 20 5

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 1) = 1 mod 4 = 1 h2( x) = x mod 8 24 Overflow, so 4) rehash values in bucket 1 using h2(x) 1 17 1 n = 2 2 10 6 14 3 4 12 20 5

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(13) = 13 mod 4 = 1 h2( x) = x mod 8 h1(13) < cutoff, so … 24 1 17 1 n = 2 2 10 6 14 3 4 12 20 5

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(13) = 13 mod 4 = 1 h2(13) = 13 mod 8 = 5 24 h1(13) < cutoff, so use h2(13) 1 17 1 n = 2 2 10 6 14 3 4 12 20 5 13

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 7) = 7 mod 4 = 3 h2( x) = x mod 8 24 1 17 1 n = 2 2 10 6 14 3 7 4 12 20 5 13

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 4) = 4 mod 4 = 0 h2( x) = x mod 8 24 h1(4) < cutoff, so … 1 17 1 n = 2 2 10 6 14 3 7 4 12 20 5 13

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 4) = 4 mod 4 = 0 h2( 4) = 4 mod 8 = 4 24 h1(4) < cutoff, so use h2(4) 1 17 1 n = 2 2 10 6 14 3 7 4 12 20 5 13

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 4) = 4 mod 4 = 0 h2( 4) = 4 mod 8 = 4 24 Overflow, so 1) add chained block 1 17 1 n = 2 2 10 6 14 3 7 4 12 20 4 5 13

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 4) = 4 mod 4 = 0 h2( 4) = 4 mod 8 = 4 24 Overflow, so 2) increment cutoff value 3) split bucket 2 1 17 1 2 10 6 14 n = 3 3 7 4 12 20 4 5 13 6

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 4) = 4 mod 4 = 0 h2( 4) = 4 mod 8 = 4 24 Overflow, so 4) rehash values in bucket 2 using h2(x) 1 17 1 2 10 6 14 n = 3 3 7 4 12 20 4 5 13 6

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( 4) = 4 mod 4 = 0 h2( 4) = 4 mod 8 = 4 24 Overflow, so 4) rehash values in bucket 2 using h2(x) 1 17 1 2 10 n = 3 3 7 4 12 20 4 5 13 6 14

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(22) = 22 mod 4 = 2 h2( x) = x mod 8 24 h1(22) < cutoff, so … 1 17 1 2 10 n = 3 3 7 4 12 20 4 5 13 6 14

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(22) = 22 mod 4 = 2 h2(22) = 22 mod 8 = 6 24 h1(22) < cutoff, so use h2(22) 1 17 1 2 10 n = 3 3 7 4 12 20 4 5 13 6 14

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(22) = 22 mod 4 = 2 h2(22) = 22 mod 8 = 6 24 Overflow, so 1) add chained block 1 17 1 2 10 n = 3 3 7 4 12 20 4 5 13 6 14 22

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(22) = 22 mod 4 = 2 h2(22) = 22 mod 8 = 6 24 Overflow, so 2) increment cutoff value 3) split bucket 3 1 17 1 2 10 3 7 n = 4 4 12 20 4 5 13 6 14 22 7

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(22) = 22 mod 4 = 2 h2(22) = 22 mod 8 = 6 24 Overflow, so 4) rehash values in bucket 3 using h2(x) 1 17 1 2 10 3 7 n = 4 4 12 20 4 5 13 6 14 22 7

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(22) = 22 mod 4 = 2 h2(22) = 22 mod 8 = 6 24 Overflow, so 4) rehash values in bucket 3 using h2(x) 1 17 1 2 10 3 n = 4 4 12 20 4 5 13 6 14 22 7

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1(22) = 22 mod 4 = 2 h2(22) = 22 mod 8 = 6 24 Since cutoff = original hash table size 1 17 1 2 10 3 n = 4 4 12 20 4 5 13 6 14 22 7

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( x) = x mod 8 h2( x) = x mod 16 24 Since cutoff = original hash table size 1) set table size to 8, modifying h1(x) and h2(x) 1 17 1 2 10 3 n = 4 4 12 20 4 5 13 6 14 22 7

Linear Hashing Example Values 12 17 10 6 24 14 5 20 1 13 7 4 22 h1( x) = x mod 8 h2( x) = x mod 16 n = 0 Since cutoff = original hash table size 24 2) reset cutoff to 0 1 17 1 2 10 3 4 12 20 4 5 13 6 14 22 7