You are on page 1of 5

Hashing

Here are some possible questions that could be asked from the topics of
Symbol Table Abstract Data Types, Hash Tables, Hashing Functions, and Hash
Collision Resolution Techniques in C for the end semester of a university:

**Symbol Table Abstract Data Types**

* What is a symbol table?


* What are the basic operations that can be performed on a symbol table?
* What are the different ways to implement a symbol table ADT?
* What are the advantages and disadvantages of different symbol table
implementations?
A **Symbol Table** is a data structure used by a compiler to keep track of
semantics of variables. It stores information about the scope and binding
information about names, information about instances of various entities such
as variable and function names, classes, objects, etc¹²³⁴⁵.

The basic operations that can be performed on a symbol table include:


- Insertion of an item in the symbol table.
- Deletion of any item from the symbol table.
- Searching of desired item from symbol table¹.

A symbol table ADT can be implemented in several ways⁸¹²⁹:


- Linear (sorted or unsorted) list
- Hash table
- Binary search tree
- Self-organizing List
Each implementation has its own advantages and disadvantages⁸¹⁶:
- **Array (Sorted)**: Efficient lookup time (O(log n)) but slower insertion time
(O(n)).
- **Linked List**: Both insertion and lookup require traversing the list (O(n)).
- **Unordered List**: Insertion can be done at the beginning or end, but
lookup requires searching the entire list (O(n)).
- **Self-organizing List**: Insertion is quick (O(1)), but lookup can be slow if
less frequently used elements are searched (O(n)).
- **Search Trees (Balanced)**: Both insertion and lookup are efficient
(O(logkn)), but the tree always has to be kept balanced.
- **Hashing**: Both insertion and lookup are usually quick (O(1)), but
performance can degrade when there are too many collisions (O(n)).

**Hash Tables**

* What is a hash table?


- A **Hash Table** is a data structure that maps keys to values. It uses a hash
function to compute an index into an array of buckets or slots, from which the
desired value can be found²¹.
* How does a hash table work?
- A hash table works by taking a key, passing it through a hash function to get
an index, and then storing the value at that index in the array⁴⁵.

* What are the advantages and disadvantages of using hash tables?


- Advantages of using hash tables include fast access time, easy insertion and
deletion, and efficient use of storage space. However, they can have collisions
where multiple keys map to the same index, they don't store elements in a
specific order, and if not managed well, they can take up a lot of memory⁸.
* What are the different ways to implement a hash table in C?
- Hash tables can be implemented in C in several ways, such as using arrays,
linked lists, or even writing your own hash function¹⁵¹⁴. Each method has its
own trade-offs in terms of speed, memory usage, and complexity.

**Hashing Functions**

* What is a hashing function?


- A **Hashing Function** is a mathematical function that converts any digital
data into an output string with a fixed number of characters⁵. It's used to map
a large number or string to a small integer that can be used as the index in a
hash table¹².
* What are the properties of a good hashing function?
- A good hashing function should be efficiently computable, uniformly
distribute the keys, and depend on every bit of the key⁶³.
* What are the different types of hashing functions?
- Different types of hashing functions include the Division Method, Mid Square
Method, Folding Method, and Multiplication Method[^10^]².
* How can a hashing function be implemented in C?
- A hashing function can be implemented in C by creating a function that takes
a key as input and returns an index. This index is then used to store the value
in the hash table¹¹¹²¹⁴.

**Hash Collision Resolution Techniques**


* What is a hash collision?
A hash collision occurs when two or more different keys have the same hash
value. This can happen when the hash function is not perfect and two keys
map to the same bucket in the hash table.
* What are the different hash collision resolution techniques?
Different hash collision resolution techniques include Open Hashing (Separate
chaining), Closed Hashing (Open Addressing), Linear Probing, Quadratic
probing, and Double hashing.

**Linear Probing**
* What is linear probing?
Linear Probing is a technique used in hash tables to resolve collisions. When a
new key maps to a cell that is already occupied by another key, linear probing
searches the table for the closest following free location and inserts the new
key there.
* How does linear probing work?
Here’s how it works:

1.Calculate the hash key, i.e., key = data % size.


2.Check if hashTable[key] is empty.
3.If the location is already occupied, then check the next location
sequentially3.
4.This process continues until an empty location is found4.
5.If the end of the hash table is reached and no empty location is found, the
search proceeds to the first location of the array.
* What are the advantages and disadvantages of using linear probing?
The advantages of linear probing are:
 It requires very less memory.
 It is less complex and simpler to implement.
The disadvantages of linear probing are:

 It causes a scenario called “primary clustering” in which there are large


blocks of occupied cells within the hash table.
 The values in linear probing tend to cluster which makes the probe
sequence longer and lengthier.

You might also like