Presentation is loading. Please wait.

Presentation is loading. Please wait.

Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 10.

Similar presentations


Presentation on theme: "Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 10."— Presentation transcript:

1 Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 10

2  Analogy of Hash Tables  Definition of Hash Table  Visualization of Hash Table  Problem in Hash Table  Chaining Keys in Hash Table  Compress Function Design

3  Word and Definition  Word is a key that addresses the definition  Number of keys: ▪ 26×26=676  Map the word to a list of integer will increase the searching process

4 Public Class Word { public static final int LETTER=26; public static final int WORDS= LETTER* LETTER; private String word; public int hashCode() { return LETTERS*(word.charAt(0)-’a’)+ (word.charAt(1)-’a’); }

5 Public Class Dictonary { private Definition[] defTable = new Definition[Word.WORDS]; public void insert(Word w, Definition d) { defTable[w.hashCode()]=d; } public Definition find(Word w) { return defTable[w.hashCode()]; } If Maximum length of words is 45 characters, we need length to store the keys

6  A hash table or hash map is a data structure that uses a hash function to efficiently map certain identifiers or keys to associated values.

7  n: number of keys(words) stored  Table of N buckets: N is a bit larger than n  A hash table maps huge set of possible keys into N buckets by applying a compression function to each hash code …… Buckets N …… n

8  Redundant buckets  If the compress function is not well designed, there may be many redundant buckets in the table  Collision  In order to decrease the size of the table, the compress function may lead several keys hash to a same bucket  Solution: Chaining Keys

9 0123456789 Compress Function 111634 8 6

10  How to design a good compress function?

11


Download ppt "Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 10."

Similar presentations


Ads by Google