Presentation is loading. Please wait.

Presentation is loading. Please wait.

Author: Takdir, S.ST. © Sekolah Tinggi Ilmu Statistik.

Similar presentations


Presentation on theme: "Author: Takdir, S.ST. © Sekolah Tinggi Ilmu Statistik."— Presentation transcript:

1 Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

2 Also called a map, a lookup table, an associative array, or a dictionary. Also called a map, a lookup table, an associative array, or a dictionary. It works like an array except that the index variable need not be an integer. It works like an array except that the index variable need not be an integer. Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

3 Save items in a key-indexed table (index is a function of the key). Save items in a key-indexed table (index is a function of the key). Hash function: Method for computing table index from key. Hash function: Method for computing table index from key. Collision resolution: Algorithm and data structure to handle two keys that hash to the same index. Collision resolution: Algorithm and data structure to handle two keys that hash to the same index.

4 Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik Every object in Java is given an intrinsic hash code, which is computed from the actual hard data stored in the object. Every object in Java is given an intrinsic hash code, which is computed from the actual hard data stored in the object. The Object.hashCode() method returns that code for each object. The Object.hashCode() method returns that code for each object. The implementation of hashCode() for an object must be consistent with equals(). The implementation of hashCode() for an object must be consistent with equals().

5 Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik Probing: when a new key collides, find next empty slot, and put it there. Probing: when a new key collides, find next empty slot, and put it there. Separate chaining: put keys that collide in a list associated with index. Separate chaining: put keys that collide in a list associated with index.

6 Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

7 f(i) = i

8 Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

9 f(i) = i 2

10 Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

11

12 Two or more keys to be inserted hash to the same index Two or more keys to be inserted hash to the same index For each of the M array indices, a linked list of the key-value pairs whose keys hash to that index For each of the M array indices, a linked list of the key-value pairs whose keys hash to that index Two-step searching process: hash to find the list that could contain the key, then sequentially search through that list for the key. Two-step searching process: hash to find the list that could contain the key, then sequentially search through that list for the key.

13 Author: Takdir, S.ST. (takdir@stis.ac.id) © Sekolah Tinggi Ilmu Statistik

14


Download ppt "Author: Takdir, S.ST. © Sekolah Tinggi Ilmu Statistik."

Similar presentations


Ads by Google