MGM University
AURANGABAD
Jawaharlal Nehru Engineering Collage
Presentation :
DATA STRUCTURE
Topic for presentation
➢ Open address
➢ Sparse matrix
➢ Transpose of sparse matrix
Open addressing
➢ Open addressing is a collision resolution technique used in hash tables, a
fundamental data structure in computer science.
➢ Hash tables store key-value pairs and allow for efficient insertion, deletion,
and lookup operations.
➢ Collisions occur in hash tables when two or more keys hash to the same index
in the underlying array.
➢ Open addressing is one way to handle these collisions.
2
➢ In open addressing, when a collision occurs, the algorithm searches
for the next open (unoccupied) slot in the hash table and places the
collided element there. There are several strategies for open
addressing,
➢ three techniques for open addressing :
1. Linear Probing
2. Quadratic Probing
3. Double Hashing
3
Initially empty table Insert 50 Insert 700 and 76
❑ Linear probing 0 0 0 700
0
700
1 1 50 1 50
1 50
In linear probing, the algorithm
2 2 2 2 85
simply looks for the next available
slot in the hash table and places the 3 3 3 3
collided key there. If that slot is 4 4 4 4
also occupied, the algorithm 5 5 5 5
continues searching for the next 6 6 6 76 6 76
available slot until an empty slot is
found. This process is repeated Insert 85 : collision
700 occurs, insert 85 at
Insert 92,collision 0
until all collided keys have been 0 700 next free slot
stored. Linear probing has the best occurs as 50 is there 1 50 1 50
cache performance but suffers from at index 1.
Insert at next free 2 85 2 85
clustering. One more advantage of
Linear probing is easy to compute.
slot 3 92 3 92
4 4 73
5 5 101
6 6
4
76 76 Insert 73 and 101
Interval between probing
❑ Quadratic probing
In quadratic probing, the algorithm
searches for slots in a more spaced-out 0 1 2 3 4 5 6 7 8 9
manner. When a collision occurs, the
algorithm looks for the next slot using
an equation that involves the original
hash value and a quadratic function. If Quadratic
that slot is also occupied, the algorithm
increments the value of the quadratic
function and tries again. This process is
repeated until an empty slot is found. 0 1 2 3 4 5 6 7 8 9
Quadratic probing lies between the two
in terms of cache performance and
clustering.
5
❑ Double hashing probing
In double hashing, the algorithm uses a second hash function to
determine the next slot to check when a collision occurs. The
algorithm calculates a hash value using the original hash function,
then uses the second hash function to calculate an offset. The
algorithm then checks the slot that is the sum of the original hash
value and the offset. If that slot is occupied, the algorithm increments
the offset and tries again. This process is repeated until an empty slot
is found. Double hashing has poor cache performance but no
clustering. Double hashing requires more computation time as two
hash functions need to be computed.
6
Sparse Matrix
❑ If a matrix contains m rows and n column the total number of
element in such a matrix is m*n. if m equal to n then the matrix is
a square matrix .
❑ When a matrix is represented as a two dimensional array
defined as a[max_rows][max_cols].we can locate each element
quickly by writing a[i][j]where I is the index and j is the
column index
Sparse Matrix
❑ Consider the matrix given below. It contain many zero entries
such as a matrix is called a sparse matrix
Columns
15 0 0 22 0 -15
0 11 3 0 0 0
Rows 0 0 0 -6 0 0
0 0 0 0 0 0
91 0 0 0 0 0
0 0 28 0 0 0
❑ Representation of sparse matrix
TWO ways to represent a sparse matrix
Array representation linked list representation
❑ Array representation of sparse matrix
index 0 1 2 3 4
0 0 0 3 0 4 Row 0 0 1 1 3 3
1 0 0 5 7 0 Column 2 4 2 3 1 2
2 0 0 0 0 0
Value 3 4 5 7 2 6
3 0 2 6 0 0
1. Row
2. Column
3. Value
❑Linked list representation of sparse matrix
➢ Here each node has four field
1. Row : index of row ,where non-zero element is located
2. Column : index od column , where non-zero element is located
3. Value : value of non-zero element located at the index (row ,column)
4. Next Node : Address of the next node
START
0 0 3 0 4
0 0 5 7 0 0 2 3 0 4 4 1 2 5
0 0 0 0 0
0 2 6 0 0
1 3 7 3 1 2 3 2 6 NULL
Node Row Column Value Address of next
Structure node
❑ Application of Sparse Matrix
Sparse matrices have a large number of elements that are zero. Utilizing this
property can lead to significant savings in memory and computational
resources. Here are some common applications of sparse matrices across
various fields
❖ Machine Learning:
1. Recommendation Systems: Sparse matrices are employed in collaborative
filtering algorithms to represent user-item interaction data efficiently.
2. Natural Language Processing (NLP): In text analysis tasks, term-
document matrices are often sparse due to the large vocabulary. Sparse
matrices are used in techniques like Latent Semantic Analysis (LSA).
3. Clustering Algorithms: Sparse matrices are used in algorithms like k-
means clustering to handle high-dimensional sparse data efficiently.
❖ Network Analysis:
1. Social Networks: Sparse matrices can represent relationships
between users in social networks, where most users only have
connections with a small subset of others.
2. Web Link Analysis: In algorithms like PageRank, sparse matrices
are used to represent web page connections in a hyperlink graph
❖ Graph Theory:
Sparse matrices can represent graphs, and they are fundamental in
graph algorithms for tasks such as finding the shortest path or detecting
cycles.
Transpose of sparse matrix
➢ A transpose of a matrix is obtained by interchanging rows of the original
matrix with columns and vice-versa. It is very commonly used in
mathematics as well as programming
Ex: Consider matrix A
1 5 0 Transpose of matrix A T
1 0 0
0 2 0 5 2 0
0 0 3 0 0 3
❑Triplet Representation of Sparse Matrices
o The triplet representation (also known as the coordinate list (COO) format) is a simple and
efficient way to represent sparse matrices. In this format, only the non-zero elements of the
matrix are stored, along with their corresponding row and column indices
Triplet form of spare matrix :
Sparse matrix :
Elemen Row Col value
t index
col0 Col Col Col
Total 4 4 5
1 2 3
row 1 0 0 22
a[ 1] 0 0 1
0
a[ 2] 0 3 22
row 0 11 0 0
1
a[ 3] 1 1 11
row 0 0 12 0
2
a[4] 2 2 12
row 0 9 0 0
3 a[ 5] 3 1 9
❑ Steps to Find Transpose Using Triplet Representation:
Step 1:consider sparse matrix
Step 2: Create a triplet of sparse matrix in form of (row_index, column_index, value).
Step 3:Swap Row and Column Indices in ascending order
Triplet form of spare matrix : Transpose of triplet from :
Element Row Col value Row Col Valu
index e
Total 4 4 5 Total 4 4 5
a[ 1] 0 0 1 b[1] 0 0 1
a[ 2] 0 3 22 b[2] 1 1 11
a[ 3] 1 1 11 b[3] 1 3 9
a[4] 2 2 12 b[4] 2 2 12
a[ 5] 3 1 9 b[5] 3 0 22
❑ Advantages of Triplet Representation:
1. Memory Efficiency: Sparse matrices can have a large
number of zero elements. Storing only non-zero elements
along with their indices reduces memory usage significantly.
2. Simplicity: Triplet representation is straightforward and easy
to understand. Each element is explicitly represented with its
row and column indices.
3. Flexibility: Triplet format allows sparse matrices of any size
and shape to be represented without constraints on the
dimensions.
Team presentation
Renuka Harshada Mundwadkar
Kulkarni 8042
4320
Harshita wani Yugandhara Pawar
4321 4323