CS301 – Data Structures
Lecture No. 43
___________________________________________________________________
Data Structures
Lecture No. 43
Reading Material
Data Structures and Algorithm Analysis in C++
Chapter. 5, 7
5.4, 5.5, 5.6, 7.1
Summary
•
Hashing Animation
•
Applications of Hashing
•
When Hashing is Suitable?
•
Sorting
•
Elementary Selection Algorithms
•
Selection Sort
Hashing Animation
In the previous lecture, we discussed about collision strategies in hashing. We studied
three solutions, Linear Probing, Quadratic Probing and Linked List chaining. Hashing is
vast research field, which covers hash functions, storage and collision issues etc. At the
moment, we will see hashing in implementation of table ADT. Operations of
insert
,
delete
and
find
are performed in constant time using this hashing strategy. Constant time
means the time does not increase with the increase in data volume. However, if collisions
start happening then the time does not remain constant. Especially if we see
linear
probing
, we had to insert the data by sorting the array sequentially. Similar was the case
with
quadratic
. In case of
linked list
, we start constructing linked list that takes time and
memory. But later we will see some situations where hashing is very useful.
Today, we will study these three strategies of hash implementation using animations.
These animations will be provided to you in a
Java
program. It is important to mention
here that all the data structures and algorithms we have studied already can be
implemented using any of the languages of
C/C++
or
Java
. However, it is an important
decision to choose the programming language because every language has its strong area,
where it has better application.
Java
has become very popular because of its facilities for
Internet
. As you already know
C++
, therefore,
Java
is easy to learn for you. The syntax
is quite similar. If we show you the java code you will say it is C++.
Let’s see the hashing animation. This animation will be shown in the browser. This is an
applet written in java language. We will see linear probing, quadratic probing and link list
chaining in it. This is an example of how do we solve collision.
Page 1 of 7
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
CS301 – Data Structures
Lecture No. 43
___________________________________________________________________
We have an array shown in four different columns. The size of the array is 100 and the
index is from 0 to 99. Each element of the array has two locations so we can store 200
elements in it. When we have first collision the program will use the 2
nd
part of the array
location. When there is a 2
nd
collision the data is stored using the linear probing. At the
top right corner we have hash function
x
and its definition is “mod 100”. That is when a
number is passed to it, it will take mod with 100 and return the result which is used as
index of the array.
In this example we are using numbers only and not dealing with the characters. We also
have a statistical table on the right side. This program will generate 100 random numbers
and using the hash function it will store these in the array. The numbers will be stored in
the array at different locations. In the bottom left we have hashing algorithms. We have
This is the end of the preview.
Sign up
to
access the rest of the document.
 Spring '10
 Dr.Naveed Malik
 Data Structures, Sort, Array, hash function

Click to edit the document details