You are on page 1of 5

HASHING DATA STRUCTURE

What is the Hashing Data Structure?


Hashing is a technique to convert a range of key values into a range of indexes of an
array. We're going to use modulo operator to get a range of key values. Consider an example of
hash table of size 20, and the following items are to be stored. Item are in the (key, value)
format.
Explanation: So goodmorning guys and to u sir ngayong araw is ididiscuss naten ano ng
aba ang hashing data structure basically hashing is a way to convert range of keys to range of
indexes so fot this to happen gagamit tayo ng modulo operator para makuha ang halaga ng key
of values for example look at the picture below

Hash Table
Is a data structure which stores data in an associative manner. In a hash table, data is stored in
an array format, where each data value has its own unique index value. Access of data becomes very
fast if we know the index of the desired data.
Explanation:anongaba ang hash table, hash table is a data structure which stores data, sa hash
table ay maiistore mo ang mga data ng naka array format and it makes ure work more convenient if u
know what is the index ng impormasyon na gusto mo

Linear Probing
As we can see, it may happen that the hashing technique is used to create an already used index
of the array. In such a case, we can search the next empty location in the array by looking into the next
cell until we find an empty cell. This technique is called linear probing.

Explanation: if hashing is used to create and already used index ang linear probing namn ay
mahahanap mo if u look into the next location at nkakakita ka ng empty cell that’s called linear probing

Basic Operations
Following are the basic primary operations of a hash table.
 Search − Searches an element in a hash table.
Explanation:Basically ito ay ginagamit para maghanap at para mas mabilis mong makita or
makuha ang data na gusto mo
 Insert − inserts an element in a hash table.
Explanation: Insert it puts element in the hast table kunware di sapat ang isang element edi
maginsert ka ng lima problem solved
 delete − Deletes an element from a hash table.
Explanation: if u made a mistake in the hash table don’t worry coz theres an option where u can
delete it

DataItem
Define a data item having some data and key, based on which the search is to be conducted in a
hash table.
Explanation: dataltel is ito yung nagbibigay linaw or nagdedefine sa mga data na may data or
keys depende sa search na ginawa mo for example look at the pic below
struct DataItem {
int data;
int key;
};

Hash Method
Define a hashing method to compute the hash code of the key of the data item.
Explanation: kanina is yung hashing technique tinalakay naten ngayon naman is yung
hash method nmn so this is a an easy process where u can easily define a hash method and
compute it to know the key of the data item look at the pic below

int hashCode(int key){


return key % SIZE;
}

Search Operation
Whenever an element is to be searched, compute the hash code of the key passed and locate
the element using that hash code as index in the array. Use linear probing to get the element ahead if
the element is not found at the computed hash code.
Explanation: search operation can be used if u wanna find an element bali kailangan mong
icompute ang hash code ng key tapos locate and use mo itong sa index and u if u got confuse or if u cant
compute u can use the linear probing which we discussed earlier so it’s a second option look at the pic
below for an example

Example:
struct DataItem *search(int key) {
//get the hash
int hashIndex = hashCode(key);

//move in array until an empty


while(hashArray[hashIndex] != NULL) {

if(hashArray[hashIndex]->key == key)
return hashArray[hashIndex];

//go to next cell


++hashIndex;

//wrap around the table


hashIndex %= SIZE;
}

return NULL;
}

Insert Operation
Whenever an element is to be inserted, compute the hash code of the key passed and locate the
index using that hash code as an index in the array. Use linear probing for empty location, if an element
is found at the computed hash code.\
Explanation:so insert operation is same sa search operation ang pinagakaiba lang is in the search u
coumpute to search but here magcocompute ka ng hash code para maglagay ng new element sa hash
table look at the pic below

Example:
void insert(int key,int data) {
struct DataItem *item = (struct DataItem*) malloc(sizeof(struct
DataItem));
item->data = data;
item->key = key;

//get the hash


int hashIndex = hashCode(key);

//move in array until an empty or deleted cell


while(hashArray[hashIndex] != NULL && hashArray[hashIndex]->key != -1) {
//go to next cell
++hashIndex;

//wrap around the table


hashIndex %= SIZE;
}

hashArray[hashIndex] = item;
}

Delete Operation
Whenever an element is to be deleted, compute the hash code of the key passed and locate the
index using that hash code as an index in the array. Use linear probing to get the element ahead if an
element is not found at the computed hash code. When found, store a dummy item there to keep the
performance of the hash table intact.
Explanation; so it’s the same as the search and insert so lets make it short if u wanna delete an
elemet coumpte the hash code and use linear probing incase cant find and kung Nakita mona maglagay
ka ng dummy item so the performance of the table will be intact look at the pic below

Example:
struct DataItem* delete(struct DataItem* item) {
int key = item->key;

//get the hash


int hashIndex = hashCode(key);

//move in array until an empty


while(hashArray[hashIndex] !=NULL) {
if(hashArray[hashIndex]->key == key) {
struct DataItem* temp = hashArray[hashIndex];

//assign a dummy item at deleted position


hashArray[hashIndex] = dummyItem;
return temp;
}

//go to next cell


++hashIndex;

//wrap around the table


hashIndex %= SIZE;
}

return NULL;
}

Reference:
https://www.tutorialspoint.com/data_structures_algorithms/hash_data_structure.htm

GROUP 7: HASHING
MEMBERS:
KAYCELYN SAMBALES
GIAN CARLO SANTIAGO
MONICA SUNGA
EMRIEL ISIP
JOHN CHRISTOPHER GUTIERREZ

You might also like