Lecture_9_-_Hashing_3-in-1_with_note

Lecture_9_-_Hashing_3-in-1_with_note - Hashing Readings...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Hashing 2 Readings ± Required ² [Carrano and Prichard] ch12 3 ADT table operations O(log n) O(log n) O(log n) Balanced BST O(log n) Retrieval O(n) Deletion O(n) Insertion Sorted Array Q : What is the meaning of O(1)? Hashing O(1) avg O(1) avg O(1) avg Hash Table is a data structure that support the table ADT in constant time on average. It has many applications.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 outline ± What is hashing? ± How to hash? ± What is collison? ± How to resolve collision ? ² separate chaining ² linear probing ² quadratic probing ² double hashing ± Load factor ± Primary clustering and secondary clustering. Direct Addressing Table - a simplified version of hash table Direct addressing table is a simplified version of hash table. 6 SBS bus problem ± Retrieval find(N) ² Does bus service no. N exist? ± Insertion insert(N) ² Introduce a new bus service no. N ± Deletion delete(N) ² Remove bus service no. N Consider the problem of maintaining information about SBS (and TIBS) bus services. We want to support three operations find, insert and delete.
Background image of page 2
7 SBS bus problem Note that bus numbers are integers between 0 – 999 , we can create an array with 1000 booleans If bus service N exists, just set position N to true : : false true 998 true 2 false 0 1 999 false Since bus numbers are integers between 0 – 999, we can create an array with 1000 booleans, initialized to false. If bus service N exists, just set position N to true. All find, delete, and insert can be done in O(1) time. 8 Direct addressing table If we want to maintain additional data about a bus, each slot can reference to an Object. : 998 2 0 1 2, data 998, data 999 We can extend this idea, if we want to maintain additional data about a bus. Use an array of 1000 slots, each can reference to an Object. 9 Direct addressing table We can store the record (key value and other data) directly in the table slots also. : 998, data 998 2, data 2 0 1 999 Q: What are the advantages and disadvantages of these 2 approaches?
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 Direct addressing table operations insert (key, data) a[key] = data delete (key) a[key] = null find (key) return a[key] 11 Restrictions of direct addressing table ± Keys must be integer ² What happens for key values 151A, NR10? ± Range of keys must be small ± Keys must be dense , i.e. not many gaps in the key values. This works only if keys are integers, (cannot keep track of bus no NR10, 162M) and the range for the keys must be small (if keys are phone numbers, you need an array of size 10 million). Hash Table Hash Table is a generalization of direct addressing table to remove these restrictions Hash Table is a generalization of direct addressing table, to remove these restrictions.
Background image of page 4
13 Idea ± Map large integers to smaller integers ± Map non-integer keys to integers The idea is to map any keys to small integers. We call this hashing. The function that map keys to integers are call hash function.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/02/2011 for the course CS 3211 taught by Professor Dunnowho during the Spring '11 term at National University of Singapore.

Page1 / 22

Lecture_9_-_Hashing_3-in-1_with_note - Hashing Readings...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online