Professional Documents
Culture Documents
Data Structures - Unit - I
Data Structures - Unit - I
Year 2021-2022
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Concept of
Sequential access :
Sequential access is the way of accessing the
data. For example, if it is on a tape. It may also be
the access method of choice, for example if we
wanted to process a sequence of data elements in
order.
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
a b c
1001 4802 2466
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
int a[3];
Main()
{ 1001
1
int a[5]= {1,2,3,4,5}; 2
1003
for (i=0;i<=4; i++)
{ 1005 3
printf(“%d\n”,*(a+i)); 1007 4
}
} 1001
1009 5
S.R.Tandle
CSE Department
a
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Linear Non-linear
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Storage representation
Array
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Storage representation
Stack
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Storage representation
Queue
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Storage representation
List
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Storage representation
Tree
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Storage representation
Graph (Using array – matrix)
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Storage representation
Graph (Using linked list)
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Matrix
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Matrix
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Matrix
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Matrix
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Matrix
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Sparse Matrix
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
1. Array representation
2. Linked list representation
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Hash Table
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Hash Table
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Hashing
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Hashing
Consider one example with the following items.
0
1
12
2 91
23 3 12
55 H(f) = K % 10 + 1 4 23
68 5 74
74 H(f) = 55%10 + 1 6 55
7
91 =5+1=6 8
65 9 68
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Searching
Consider one example with the following items.
0
1
2 91
3 12
H(f) = K % 10 + 1 4 23
5 74
6 55
7
8
9 68
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Hashing functions
Characteristics of good hashing function
• The hash function should generate different hash
values for the similar string.
• The hash function should be easy to understand and
simple to compute.
• The hash function should produce the keys which will
get distributed, uniformly over an array.
• A number of collisions should be less while placing the
data in the hash table.
• The hash function is a perfect hash function when it
uses all the input data. S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Hashing functions
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Hashing functions
Midsquare hashing :
A mid-squares hash code is produced by
squaring the input and extracting an appropriate
number of middle digits or bits.
For example;
40 -> 1600 -> 60
41-> 1681 -> 68
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Hashing functions
Division hashing :
A standard technique is to use a modulo
function on the key, by selecting a
divisor which is a prime number close to the
table size, so h(K)=K mod M.
The table size is usually a power of 2. This
gives a distribution from {0,M-1}.
This gives good results over a large number
of key sets.
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Hashing functions
Digit folding method
In this method the key is divided into separate
parts and by using some simple operations these
parts are combined to produce a hash key.
Ex: consider a record of 12465512 then it will be
divided into parts i.e. 124, 655, 12. After dividing
the parts combine these parts by adding it.
H(key)=124+655+12 =791
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Perfect hashing
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Collision
Since the size of the hash table is small
comparatively to the range of keys, the perfect
hash function is practically impossible.
When more than one keys map to the
same location, is known as a collision. A good
hash function should have less number of
collisions.
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Separate chaining :
In separate chaining, we maintain a linked
chain for every index in the hash table. So
whenever there is a Collision the linked list is
extended for that particular location of the hash
table.
We can visualize the separate chaining
method with the following example,
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Separate chaining
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Linear Probing :
In linear probing, the rehashing process is
linear. Say the location found at any step
is n and n is occupied then the next
attempt will be to hash at position (n+1).
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Collision resolution techniques
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Collision resolution techniques
Quadratic Probing :
The problem of clustering can be avoided by using quadratic
probing. Here the rehashing is done like below,
rehashing(key) = (n+k2) % table size
where, k is 1,2,3, ... We wrap around from the last table
location to the first location if necessary.
Like say hashing location initially is 3 and 3 is occupied then
we will go for 3+12=4, if it’s still occupied we will go for
4+22=8. So on
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Collision resolution techniques
Quadratic Probing :
The main advantage is, we can overcome the problem
of clustering which appeared in the case of linear probing.
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
Unit-I
Introduction
Collision resolution techniques
Double hashing :
Index Keys
0 Empty
1 Empty
2 983
3 123
4 124
5 Empty
6 333
7 Empty
8 Empty
9 4679
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.
End of Unit-I
S.R.Tandle
CSE Department
M.S.Bidve Engineering College, Latur.