Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Data structure (module 5)

Rating
-
Sold
-
Pages
16
Uploaded on
30-01-2025
Written in
2024/2025

These are class notes, easy to study in short time.

Institution
Course

Content preview

MODULE V
1. What is Hashing? Discuss the properties of a good hash function. Explain the following
hash function with proper example(10)
a. Division
b. Midsquare
c. Folding
2. Explain static and dynamic hashing in detail(8)
3. What is chained hashing? Discuss its pros and cons. Construct the hash table to insert the
keys: 7, 24, 18, 52, 36, 54, 11, 23 in a chained hash table of 9 memory locations. Use h(k)
= k mod m(8)
4. What is dynamic hashing? Explain the following techniques with examples: (8)
i) Dynamic hashing using directories ii) Directory less dynamic hashing
5. Consider a hash table of size 10. Using linear probing, insert the keys 72, 27, 36, 24, 63,
81, 92, and 101 into the table (10)
6. Consider a hash table of size 10. Using quadratic probing, insert the keys 72, 27, 36, 24,
63, 81, and 101 into the table. Take c1 = 1 and c2 = 3 (10)
7. Define the leftist tree. Give its declaration in C. Check whether the given binary tree is a
leftist tree or not. Explain your answer(5)




8. Define min Leftist tree. Meld the given min leftist trees(5)




9. Define double ended priority queue and min-max heap. Explain Insertion and Deletion in
a min-max heap with example(8)
10. What is Optimal Binary Search Tree? Write a c function to find an Optimal Binary
Search Tree.

, 1. What is Hashing? Discuss the properties of a good hash function. Explain the
following hash function with proper example(8)
a. Division Method
b. Midsquare Method
c. Folding Method
Hashing
• Hashing is a technique to convert a range of key values into a range of indexes of an array.
In general we use modulo operator to get a range of key values. Hashing technique use a
special function called the Hash function which is used to map a given value with a
particular key for faster access of elements.
• Each Item can be located in a Bin/Bucket/Shelf according to its key value (number)
• Most simple Hash Method/Function
int hash(int key)
{
return key % SIZE;
}
Hash Function
• A hash function is any function that can be used to map a data set of an arbitrary size to a
data set of a fixed size, which falls into the hash table. The values returned by a hash
function are called hash values, hash codes, hash sums, or simply hashes. There are many
hash functions that use numeric or alphanumeric keys.
Properties of good Hash Function
• Hash function should be simple to compute
• Number of collision should be less
• The hash function uses all the input data
• The hash function "uniformly" distributes the data across the entire set of possible hash
values
• The hash function generates very different hash values for similar strings
Types of Hash functions
o Division Method
o Mid Square Method
o Folding Method
i) Modular method /Division Method :
• It is the most simple method of hashing an integer x. This method divides x by size of
hash table M and then uses the remainder obtained. In this case, the hash function can
be given as
h(x) = x mod M
• Example: To calculate the hash values of keys 1234 and 5462. Solution Setting M =
97, hash values can be calculated as:
h(1234) = 1234 % 97 = 70
h(5642) = 5642 % 97 = 16
• Mid-square Method
o The mid-square method is a good hash function which works in two steps:
o Step 1: Square the value of the key. That is, find k2.
o Step 2: Extract the middle r digits of the result obtained in Step 1.
o In the mid-square method, the same r digits must be chosen from all the keys.

, o Therefore, the hash function can be given as:
▪ h(k) = s where s is obtained by selecting r digits from k2.
o Example: To calculate the hash value for keys 1234 and 5642 using the mid-square
method:
▪ The hash table has 100 memory locations.
▪ Solution: Note that the hash table has 100 memory locations whose indices
vary from 0 to 99.
▪ This means that only two digits are needed to map the key to a location in
the hash table, so r = 2.
• When k = 1234, k2 = 1522756, h (1234) = 27
• When k = 5642, k2 = 31832164, h (5642) = 21
• Folding Method:
o The folding method works in the following two steps:
o Step 1: Divide the key value into a number of parts. That is, divide k into parts k1,
k2, ..., kn, where each part has the same number of digits except the last part which
may have lesser digits than the other parts.
o Step 2: Add the individual parts. That is, obtain the sum of k1 + k2 + ... + kn. The
hash value is produced by ignoring the last carry, if any. Note that the number of
digits in each part of the key will vary depending upon the size of the hash table. .
o Example: Given a hash table of 100 locations, calculate the hash value using
folding method for keys 5678 and 34567
o Solution: Since there are 100 memory locations to address, we will break the key
into parts where each part (except the last) will contain two digits. The hash values
can be obtained as shown below: Key: 34567, Parts: 34,56 and 7, Sum:97 so, Hash
value: 97 Key: 5678, Parts: 56 and 78, Sum:134 Hash value: 34 (ignore carry)

2. Explain static and dynamic hashing in detail(8)

Static Hashing
• In static hashing, the identifiers are stored in a fixed size table called a hash table
• When a search key is given hash function always computes the same address
• Hashing technique in which the table(bucket) size remains the same (Fixed during
compilation time) is called static hashing
• A static hashing scheme is one where the size of the hash table is fixed
• Various techniques of static hashing are linear probing and chaining
• As the size is fixed, this type of hashing consist handling overflow of elements
(Collision)efficiently
• Example of hash functions: h(k) = k MOD m (k is key & m is size of hash table)

Written for

Institution
Course

Document information

Uploaded on
January 30, 2025
Number of pages
16
Written in
2024/2025
Type
Class notes
Professor(s)
Santosh
Contains
Data structure

Subjects

$8.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
supriyadhonedhone

Get to know the seller

Seller avatar
supriyadhonedhone Guru nanak dev engineering College,bidar
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
5
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions