0% found this document useful (0 votes)
15 views

Unit5 Lect5 Hashing

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Unit5 Lect5 Hashing

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Data Structure and Algorithms using Java

Programming

BTEXPE506C 3 Credits
Course Objectives:

• To assess how the choice of data structures and algorithm design methods impacts the performance of
programs.
· To choose the appropriate data structure and algorithm design method for a specified application.
· To solve problems using data structures such as linear lists, stacks, queues, binary trees, binary search trees,
and graphs and writing programs for these solutions.
 To study the systematic way of solving problems, various methods of organizing large amounts of data.
 To employ the different data structures to find the solutions for specific problems
Course Outcomes:

On completion of the course, student will be able to:


1. To impart the basic concepts of data structures and algorithms.
2. To understand basic concepts about linear data structure stacks, queues, Linked lists.
3. To understand basic concepts about non linear data structure trees and graphs.
4. Describe how arrays, records, linked structures are represented in memory and use them in algorithms.
5. To enable them to write algorithms for solving problems with the help of fundamental of data structure.
6. To understand concepts about searching and sorting techniques.

JAVA Information
https://www.javatpoint.com/features-of-java
UNIT – 1
Introduction
• Basic Terminologies: Elementary Data Organizations, Data Structure Operations: insertion, deletion, traversal
etc.; Analysis of an Algorithm, Asymptotic Notations, Time-Space trade off. Searching: Linear Search and
Binary Search Techniques and their complexity analysis.
UNIT – 2
Stacks and Queues
• ADT Stack and its operations: Algorithms and their complexity analysis,
• Applications of Stacks: Expression Conversion and evaluation – corresponding algorithms and complexity
analysis.
• ADT queue, Types of Queue: Simple Queue, Circular Queue, Priority Queue; Operations on each type of
Queues: Algorithms and their analysis.
UNIT – 3
Linked Lists
• Singly linked lists: Representation in memory, Algorithms of several operations: Traversing, Searching,
Insertion into, Deletion from linked list; Linked representation of Stack and Queue, Header nodes,
• doubly linked list: operations on it and algorithmic analysis;
• Circular Linked Lists: all operations their algorithms and the complexity analysis.
UNIT – 4
Trees
• Basic Tree Terminologies, Different types of Trees: Binary Tree, Threaded Binary Tree, Binary Search Tree,
AVL Tree; Tree operations on each of the trees and their algorithms with complexity analysis.
• Applications of Binary Trees, B Tree, B+ Tree: definitions, algorithms and analysis.
UNIT – 5
Sorting and Hashing
• Objective and properties of different sorting algorithms: Selection Sort, Bubble Sort,
• Insertion Sort, Quick Sort, Merge Sort, Heap Sort; Performance and Comparison among all the methods,
Hashing.
UNIT – 6
Graph
• Basic Terminologies and Representations, Graph search and traversal algorithms and complexity analysis.
• TEXT/REFERENCE BOOKS
1. “How to Solve it by Computer”, 2nd Impression by R. G. Dromey, Pearson Education.
2. Ellis Horowitz, Sartaj Sahni, “Fundamentals of Data Structures”, Galgotia Books Source. ISBN 10:
0716782928
3. Java: The Complete Reference, Seventh Edition, Herbert Schildt, McGraw Hill
4. Richard F. Gilberg & Behrouz A. Forouzan, Data Structures: A Pseudocode Approach with C, Cengage
Learning, second edition. ISBN-10: 0534390803.
5. Seymour Lipschutz, Data Structure with C, Schaum‟s Outlines, Tata Mc Graw Hill. ISBN-10: 1259029964.
6.John Hubbard Anita Huray, “ Data Structures with JAVA”, Person Education
UNIT – 5

Sorting and Hashing


• Objective and properties of different sorting algorithms: Selection Sort,
Bubble Sort,
• Insertion Sort, Quick Sort, Merge Sort, Heap Sort; Performance and
Comparison among all the methods, Hashing.
Contain
• Hashing
• Types of hashing

https://www.youtube.com/watch?v=j612Fj-mgCY

https://www.youtube.com/watch?v=zeMa9sg-VJM
What is Hashing in Data
Structure?
• Hashing in the data structure is a technique of mapping a
large chunk of data into small tables using a hashing function.
It is also known as the message digest function. It is a
technique that uniquely identifies a specific item from a
collection of similar items.
• It uses hash tables to store the data in an array format. Each
value in the array has assigned a unique index number. Hash
tables use a technique to generate these unique index
numbers for each value stored in an array format. This
technique is called the hash technique.
• Hashing in a data structure is a two-step process.
1.The hash function converts the item into a small
integer or hash value. This integer is used as an index
to store the original data.
2.It stores the data in a hash table. You can use a hash
key to locate data quickly.
Hash Function

• The hash function in a data structure maps arbitrary size of


data to fixed-sized data. It returns the following values: a
small integer value (also known as hash value), hash codes,
and hash sums.
• hash = hashfunc(key)
• index = hash % array_size
• The has function must satisfy the following requirements:
• A good hash function is easy to compute.
• A good hash function never gets stuck in clustering and
distributes keys evenly across the hash table.
• A good hash function avoids collision when two elements or
items get assigned to the same hash value.
• Hash Table
• Hashing in data structure uses hash tables to store
the key-value pairs. The hash table then uses the hash
function to generate an index. Hashing uses this unique
index to perform insert, update, and search operations.
How does Hashing in Data Structure Works?

• In hashing, the hashing function maps strings or numbers to a


small integer value. Hash tables retrieve the item from the list
using a hashing function. The objective of hashing technique is
to distribute the data evenly across an array. Hashing assigns
all the elements a unique key. The hash table uses this key to
access the data in the list.
• Hash table stores the data in a key-value pair. The key acts as
an input to the hashing function. Hashing function then
generates a unique index number for each value stored. The
index number keeps the value that corresponds to that key.
The hash function returns a small integer value as an output.
The output of the hashing function is called the hash value.
Let us understand hashing in a data structure with an example. Imagine you need to store some items
(arranged in a key-value pair) inside a hash table with 30 cells.
The values are: (3,21) (1,72) (40,36) (5,30) (11,44) (15,33) (18,12) (16,80) (38,99)
Collision Resolution Techniques

• Hashing in data structure falls into a collision if two keys


are assigned the same index number in the hash table. The
collision creates a problem because each index in a hash
table is supposed to store only one value. Hashing in
data structure uses several collision resolution
techniques to manage the performance of a hash table.
• Linear Probing
• Hashing in data structure results in an array index that
is already occupied to store a value. In such a case,
hashing performs a search operation and probes linearly
for the next empty cell.
Linear Probing Example

• Imagine you have been asked to store some items


inside a hash table of size 30. The items are already
sorted in a key-value pair format. The values given are:
(3,21) (1,72) (63,36) (5,30) (11,44) (15,33) (18,12)
(16,80) (46,99).
• The hash(n) is the index computed using a hash
function and T is the table size. If slot index = ( hash(n)
% T) is full, then we look for the next slot index by
adding 1 ((hash(n) + 1) % T). If (hash(n) + 1) % T is also
full, then we try (hash(n) + 2) % T. If (hash(n) + 2) % T
is also full, then we try (hash(n) + 3) % T.
Linear Probing Example
Implementing hashing using a hashtable

import java.util.*;
public class Hashing1 {
public static void main(String args[]) {
Hashtable<Integer, String> hm = new
Hashtable<Integer, String>(); hm.put(1,
"App"); hm.put(12, "Dividend"); hm.put(15,
"Best place to learn"); hm.put(3, "Java");
System.out.println(hm); }
}
Best Time
Algorithm Approach
Complexity
Split the array into smaller subarrays till pairs of
Merge Sort elements are achieved, and then combine them in O(n log (n))
such a way that they are in order.
Build a max (or min) heap and extract the first
element of the heap (or root), and then send it to the
Heap Sort O(n log (n))
end of the heap. Decrement the size of the heap and
repeat till the heap has only one node.
In every run, compare it with the predecessor. If the
current element is not in the correct location, keep
Insertion Sort O (n)
shifting the predecessor subarray till the correct
index for the element is found.
Find the minimum element in each run of the array
Selection Sort and swap it with the element at the current index is O(n^2)
compared.

Keep swapping elements that are not in their right


Bubble Sort O (n)
location till the array is sorted.

You might also like