SlideShare a Scribd company logo
UNIT V
SORTING AND HASHING
TECHNIQUES
Sorting
• Sorting refers to arranging data in a particular
format. Sorting algorithm specifies the way to
arrange data in a particular order. Most
common orders are in numerical or
lexicographical order.
• The importance of sorting lies in the fact that
data searching can be optimized to a very high
level, if data is stored in a sorted manner.
Merge sort
• Merge sort is defined as a sorting algorithm
that works by dividing an array into smaller
subarrays, sorting each subarray, and then
merging the sorted subarrays back together to
form the final sorted array.
GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL
MERGE_SORT(arr, beg, end)
if beg < end
set mid = (beg + end)/2
MERGE_SORT(arr, beg, mid)
MERGE_SORT(arr, mid + 1, end)
MERGE (arr, beg, mid, end)
end of if
END MERGE_SORT
Quicksort
• Quicksort is the widely used sorting algorithm that
makes n log n comparisons in average case for
sorting an array of n elements. It is a faster and
highly efficient sorting algorithm.
• This algorithm follows the divide and conquer
approach. Divide and conquer is a technique of
breaking down the algorithms into subproblems,
then solving the subproblems, and combining the
results back together to solve the original problem.
• Divide: In Divide, first pick a pivot element.
After that, partition or rearrange the array into
two sub-arrays such that each element in the
left sub-array is less than or equal to the pivot
element and each element in the right sub-
array is larger than the pivot element.
• Conquer: Recursively, sort two subarrays with
Quicksort.
• Combine: Combine the already sorted array.
GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL
Algorithm
QUICKSORT (array A, start, end)
{
if (start < end)
{
p = partition(A, start, end)
QUICKSORT (A, start, p - 1)
QUICKSORT (A, p + 1, end)
}
}
Insertion sort
• Insertion sort is a simple sorting algorithm
that works similar to the way you sort playing
cards in your hands. The array is virtually split
into a sorted and an unsorted part. Values
from the unsorted part are picked and placed
at the correct position in the sorted part.
GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL
Shell Sort
• Shell sort is mainly a variation of Insertion Sort.
In insertion sort, we move elements only one
position ahead.
• The idea of ShellSort is to allow the exchange of
far items. In Shell sort, we make the array h-
sorted for a large value of h.
• We keep reducing the value of h until it
becomes 1. An array is said to be h-sorted if all
sublists of every h’th element are sorted.
• PROCEDURE SHELL_SORT(ARRAY, N)
WHILE GAP < LENGTH(ARRAY) /3 :
GAP = ( INTERVAL * 3 ) + 1
END WHILE LOOP
WHILE GAP > 0 :
FOR (OUTER = GAP; OUTER < LENGTH(ARRAY); OUTER++):
INSERTION_VALUE = ARRAY[OUTER]
INNER = OUTER;
WHILE INNER > GAP-1 AND ARRAY[INNER – GAP] >=
INSERTION_VALUE:
ARRAY[INNER] = ARRAY[INNER – GAP]
INNER = INNER – GAP
END WHILE LOOP
ARRAY[INNER] = INSERTION_VALUE
END FOR LOOP
GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL
Radix sort
• Radix Sort is a linear sorting algorithm that
sorts elements by processing them digit by
digit. It is an efficient sorting algorithm for
integers or strings with fixed-size keys.
• Radix Sort distributes the elements into
buckets based on each digit’s value.
GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL
• Hashing is the process of generating a value from a
text or a list of numbers using a mathematical function
known as a hash function.
• A Hash Function is a function that converts a given
numeric or alphanumeric key to a small practical
integer value. The mapped integer value is used as an
index in the hash table. In simple terms, a hash
function maps a significant number or string to a small
integer that can be used as the index in the hash table.
• The pair is of the form (key, value), where for a given key, one can find a
value using some kind of a “function” that maps keys to values.
• A good hash function should have the following properties:
• Efficiently computable.
• Should uniformly distribute the keys (Each table position is equally likely
for each.
• Should minimize collisions.
• Should have a low load factor(number of items in the table divided by the
size of the table).
• Complexity of calculating hash value using the hash function
• Time complexity: O(n)
• Space complexity: O(1)
GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL
Collision
• Collision in Hashing
• In this, the hash function is used to find the
index of the array. The hash value is used to
create an index for the key in the hash table.
The hash function may return the same hash
value for two or more keys. When two or more
keys have the same hash value, a collision
happens. To handle this collision, we use
collision resolution techniques.
Collision Resolution Techniques
• There are two types of collision resolution techniques.
• Separate chaining (open hashing)
• Open addressing (closed hashing)
• Separate chaining: This method involves making a linked list out of
the slot where the collision happened, then adding the new key to
the list. Separate chaining is the term used to describe how this
connected list of slots resembles a chain. It is more frequently
utilized when we are unsure of the number of keys to add or
remove.
• Time complexity
• Its worst-case complexity for searching is o(n).
• Its worst-case complexity for deletion is o(n).
• Open addressing: To prevent collisions in the hashing
table open, addressing is employed as a collision-
resolution technique. No key is kept anywhere else
besides the hash table. As a result, the hash table’s size
is never equal to or less than the number of keys.
Additionally known as closed hashing.
• The following techniques are used in open addressing:
• Linear probing
• Quadratic probing
• Double hashing
Linear Probing
• In linear probing, the hash table is searched
sequentially that starts from the original
location of the hash. If in case the location
that we get is already occupied, then we check
for the next location.
• The function used for rehashing is as follows:
rehash(key) = (n+1)%table-size.
GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL
Applications
• Symbol tables: Linear probing is commonly used in symbol tables,
which are used in compilers and interpreters to store variables and
their associated values. Since symbol tables can grow dynamically,
linear probing can be used to handle collisions and ensure that
variables are stored efficiently.
• Caching: Linear probing can be used in caching systems to store
frequently accessed data in memory. When a cache miss occurs, the
data can be loaded into the cache using linear probing, and when a
collision occurs, the next available slot in the cache can be used to
store the data.
• Databases: Linear probing can be used in databases to store records
and their associated keys. When a collision occurs, linear probing
can be used to find the next available slot to store the record.
Separate Chaining
• The idea behind separate chaining is to implement
the array as a linked list called a chain. Separate
chaining is one of the most popular and commonly
used techniques in order to handle collisions.
• The linked list data structure is used to implement
this technique. So what happens is, when multiple
elements are hashed into the same slot index,
then these elements are inserted into a singly-
linked list which is known as a chain.
GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL
Open Addressing
• In Open Addressing, all elements are stored in
the hash table itself. So at any point, the size
of the table must be greater than or equal to
the total number of keys.
• This approach is also known as closed
hashing. This entire procedure is based upon
probing. We will understand the types of
probing ahead:
• Insert(k): Keep probing until an empty slot is
found. Once an empty slot is found, insert k.
• Search(k): Keep probing until the slot’s key
doesn’t become equal to k or an empty slot is
reached.
• Delete(k): Delete operation is interesting. If
we simply delete a key, then the search may
fail. So slots of deleted keys are marked
specially as “deleted”.
Rehashing
• Rehashing is the process of recalculating the
hashcode of previously-stored entries (Key-
Value pairs) in order to shift them to a larger
size hashmap when the threshold is
reached/crossed,
• When the number of elements in a hash map
reaches the maximum threshold value, it is
rehashed.
GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL
How Rehashing is done?
Rehashing can be done as follows:
• For each addition of a new entry to the map, check the
load factor.
• If it’s greater than its pre-defined value (or default
value of 0.75 if not given), then Rehash.
• For Rehash, make a new array of double the previous
size and make it the new bucketarray.
• Then traverse to each element in the old bucketArray
and call the insert() for each so as to insert it into the
new larger bucket array.
Extendible Hashing
• Extendible Hashing is a dynamic hashing method wherein
directories, and buckets are used to hash data. It is an
aggressively flexible method in which the hash function
also experiences dynamic changes.
• Main features of Extendible Hashing: The main features
in this hashing technique are:
• Directories: The directories store addresses of the buckets
in pointers. An id is assigned to each directory which may
change each time when Directory Expansion takes place.
• Buckets: The buckets are used to hash the actual data.
GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL

More Related Content

Similar to GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL (20)

Working with python Nice PPT must try very good
Working with python Nice PPT must try very goodWorking with python Nice PPT must try very good
Working with python Nice PPT must try very good
MuhammadChala
 
hashing.pdf
hashing.pdfhashing.pdf
hashing.pdf
Yuvraj919347
 
Hashing techniques, Hashing function,Collision detection techniques
Hashing techniques, Hashing function,Collision detection techniquesHashing techniques, Hashing function,Collision detection techniques
Hashing techniques, Hashing function,Collision detection techniques
ssuserec8a711
 
Lec12-Hash-Tables-27122022-125641pm.pptx
Lec12-Hash-Tables-27122022-125641pm.pptxLec12-Hash-Tables-27122022-125641pm.pptx
Lec12-Hash-Tables-27122022-125641pm.pptx
IqraHanif27
 
unit 3 Divide and Conquer Rule and Sorting.pptx
unit 3 Divide and Conquer Rule and Sorting.pptxunit 3 Divide and Conquer Rule and Sorting.pptx
unit 3 Divide and Conquer Rule and Sorting.pptx
JayashreeCSENMIT
 
Hash table
Hash tableHash table
Hash table
Vu Tran
 
Data Structures-Topic-Hashing, Collision
Data Structures-Topic-Hashing, CollisionData Structures-Topic-Hashing, Collision
Data Structures-Topic-Hashing, Collision
sailaja156145
 
Hashing_Unit4.pptx Data Structures and Algos
Hashing_Unit4.pptx Data Structures and AlgosHashing_Unit4.pptx Data Structures and Algos
Hashing_Unit4.pptx Data Structures and Algos
snehalkulkarni78
 
session 15 hashing.pptx
session 15   hashing.pptxsession 15   hashing.pptx
session 15 hashing.pptx
rajneeshsingh46738
 
Sorting and hashing concepts
Sorting and hashing conceptsSorting and hashing concepts
Sorting and hashing concepts
LJ Projects
 
Sorting and hashing concepts
Sorting and hashing conceptsSorting and hashing concepts
Sorting and hashing concepts
LJ Projects
 
Hashing and Binary Search Tree powerp.pptx
Hashing and Binary Search Tree powerp.pptxHashing and Binary Search Tree powerp.pptx
Hashing and Binary Search Tree powerp.pptx
lemerdzsison3
 
Unit 8 searching and hashing
Unit   8 searching and hashingUnit   8 searching and hashing
Unit 8 searching and hashing
Dabbal Singh Mahara
 
VCE Unit 04vv.pptx
VCE Unit 04vv.pptxVCE Unit 04vv.pptx
VCE Unit 04vv.pptx
skilljiolms
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
SHAKOOR AB
 
Data structure and algorithms
Data structure and algorithmsData structure and algorithms
Data structure and algorithms
technologygyan
 
Hash based inventory system
Hash based inventory systemHash based inventory system
Hash based inventory system
DADITIRUMALATARUN
 
introduction to trees,graphs,hashing
introduction to trees,graphs,hashingintroduction to trees,graphs,hashing
introduction to trees,graphs,hashing
Akhil Prem
 
Hashing
HashingHashing
Hashing
VARSHAKUMARI49
 
Hashing algorithms and its uses
Hashing algorithms and its usesHashing algorithms and its uses
Hashing algorithms and its uses
Jawad Khan
 
Working with python Nice PPT must try very good
Working with python Nice PPT must try very goodWorking with python Nice PPT must try very good
Working with python Nice PPT must try very good
MuhammadChala
 
Hashing techniques, Hashing function,Collision detection techniques
Hashing techniques, Hashing function,Collision detection techniquesHashing techniques, Hashing function,Collision detection techniques
Hashing techniques, Hashing function,Collision detection techniques
ssuserec8a711
 
Lec12-Hash-Tables-27122022-125641pm.pptx
Lec12-Hash-Tables-27122022-125641pm.pptxLec12-Hash-Tables-27122022-125641pm.pptx
Lec12-Hash-Tables-27122022-125641pm.pptx
IqraHanif27
 
unit 3 Divide and Conquer Rule and Sorting.pptx
unit 3 Divide and Conquer Rule and Sorting.pptxunit 3 Divide and Conquer Rule and Sorting.pptx
unit 3 Divide and Conquer Rule and Sorting.pptx
JayashreeCSENMIT
 
Hash table
Hash tableHash table
Hash table
Vu Tran
 
Data Structures-Topic-Hashing, Collision
Data Structures-Topic-Hashing, CollisionData Structures-Topic-Hashing, Collision
Data Structures-Topic-Hashing, Collision
sailaja156145
 
Hashing_Unit4.pptx Data Structures and Algos
Hashing_Unit4.pptx Data Structures and AlgosHashing_Unit4.pptx Data Structures and Algos
Hashing_Unit4.pptx Data Structures and Algos
snehalkulkarni78
 
Sorting and hashing concepts
Sorting and hashing conceptsSorting and hashing concepts
Sorting and hashing concepts
LJ Projects
 
Sorting and hashing concepts
Sorting and hashing conceptsSorting and hashing concepts
Sorting and hashing concepts
LJ Projects
 
Hashing and Binary Search Tree powerp.pptx
Hashing and Binary Search Tree powerp.pptxHashing and Binary Search Tree powerp.pptx
Hashing and Binary Search Tree powerp.pptx
lemerdzsison3
 
VCE Unit 04vv.pptx
VCE Unit 04vv.pptxVCE Unit 04vv.pptx
VCE Unit 04vv.pptx
skilljiolms
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
SHAKOOR AB
 
Data structure and algorithms
Data structure and algorithmsData structure and algorithms
Data structure and algorithms
technologygyan
 
introduction to trees,graphs,hashing
introduction to trees,graphs,hashingintroduction to trees,graphs,hashing
introduction to trees,graphs,hashing
Akhil Prem
 
Hashing algorithms and its uses
Hashing algorithms and its usesHashing algorithms and its uses
Hashing algorithms and its uses
Jawad Khan
 

More from mohanrajm63 (19)

METHOD OVERLOADING AND INHERITANCE INTERFACE
METHOD OVERLOADING AND INHERITANCE INTERFACEMETHOD OVERLOADING AND INHERITANCE INTERFACE
METHOD OVERLOADING AND INHERITANCE INTERFACE
mohanrajm63
 
EVENT DRIVEN PROGRAMMING SWING APPLET AWT
EVENT DRIVEN PROGRAMMING SWING APPLET AWTEVENT DRIVEN PROGRAMMING SWING APPLET AWT
EVENT DRIVEN PROGRAMMING SWING APPLET AWT
mohanrajm63
 
MULTITHREADING PROGRAMMING AND I/O THREAD
MULTITHREADING PROGRAMMING AND I/O THREADMULTITHREADING PROGRAMMING AND I/O THREAD
MULTITHREADING PROGRAMMING AND I/O THREAD
mohanrajm63
 
PACKAGES, INTERFACES AND EXCEPTION HANDLING
PACKAGES, INTERFACES AND EXCEPTION HANDLINGPACKAGES, INTERFACES AND EXCEPTION HANDLING
PACKAGES, INTERFACES AND EXCEPTION HANDLING
mohanrajm63
 
UNIT I OOP AND JAVA FUNDAMENTALS CONSTRUCTOR
UNIT I 	OOP AND JAVA FUNDAMENTALS CONSTRUCTORUNIT I 	OOP AND JAVA FUNDAMENTALS CONSTRUCTOR
UNIT I OOP AND JAVA FUNDAMENTALS CONSTRUCTOR
mohanrajm63
 
UNIT - 5 INTERFACE APPLIATIONS GROUP WARE SYSTEMS
UNIT - 5 INTERFACE APPLIATIONS GROUP WARE SYSTEMSUNIT - 5 INTERFACE APPLIATIONS GROUP WARE SYSTEMS
UNIT - 5 INTERFACE APPLIATIONS GROUP WARE SYSTEMS
mohanrajm63
 
MODELS AND EVALUATION FRAMEWORK GOALS AND TASK
MODELS AND EVALUATION FRAMEWORK GOALS AND TASKMODELS AND EVALUATION FRAMEWORK GOALS AND TASK
MODELS AND EVALUATION FRAMEWORK GOALS AND TASK
mohanrajm63
 
DESIGN RULES , PROCESS OF DESIGN, USER FOCUS
DESIGN RULES , PROCESS OF DESIGN, USER FOCUSDESIGN RULES , PROCESS OF DESIGN, USER FOCUS
DESIGN RULES , PROCESS OF DESIGN, USER FOCUS
mohanrajm63
 
INTERACTION AND INTERFACES MODEL OF THE INTERACTION
INTERACTION AND INTERFACES MODEL OF THE INTERACTIONINTERACTION AND INTERFACES MODEL OF THE INTERACTION
INTERACTION AND INTERFACES MODEL OF THE INTERACTION
mohanrajm63
 
THE INTRODUCTION - HUMAN AND COMPUTER BASICS
THE INTRODUCTION - HUMAN AND COMPUTER BASICSTHE INTRODUCTION - HUMAN AND COMPUTER BASICS
THE INTRODUCTION - HUMAN AND COMPUTER BASICS
mohanrajm63
 
OBJECT ORIENTED PROGRAMMING , S3 CLASS, S4 CLASS
OBJECT ORIENTED PROGRAMMING , S3 CLASS, S4 CLASSOBJECT ORIENTED PROGRAMMING , S3 CLASS, S4 CLASS
OBJECT ORIENTED PROGRAMMING , S3 CLASS, S4 CLASS
mohanrajm63
 
FACTORS AND TABLES, MINIMUM AND MAXIMA, DISTRIBUTIONS
FACTORS AND TABLES, MINIMUM AND MAXIMA, DISTRIBUTIONSFACTORS AND TABLES, MINIMUM AND MAXIMA, DISTRIBUTIONS
FACTORS AND TABLES, MINIMUM AND MAXIMA, DISTRIBUTIONS
mohanrajm63
 
LISTS, CREATING LIST, ACCESSING LIST AND INDEX
LISTS, CREATING LIST, ACCESSING LIST AND INDEXLISTS, CREATING LIST, ACCESSING LIST AND INDEX
LISTS, CREATING LIST, ACCESSING LIST AND INDEX
mohanrajm63
 
CONTROL STRUCTURES, DATA TYPES AND OBJECTS
CONTROL STRUCTURES, DATA TYPES AND OBJECTSCONTROL STRUCTURES, DATA TYPES AND OBJECTS
CONTROL STRUCTURES, DATA TYPES AND OBJECTS
mohanrajm63
 
R PROGRAMMING INTRODUCTION AND FEATURES,
R PROGRAMMING INTRODUCTION AND FEATURES,R PROGRAMMING INTRODUCTION AND FEATURES,
R PROGRAMMING INTRODUCTION AND FEATURES,
mohanrajm63
 
TREE ADT, TREE TRAVERSALS, BINARY TREE ADT
TREE ADT, TREE TRAVERSALS, BINARY TREE ADTTREE ADT, TREE TRAVERSALS, BINARY TREE ADT
TREE ADT, TREE TRAVERSALS, BINARY TREE ADT
mohanrajm63
 
SEARCHING AND SORTING ALGORITHMS, TYPES OF SORTING
SEARCHING AND SORTING ALGORITHMS, TYPES OF SORTINGSEARCHING AND SORTING ALGORITHMS, TYPES OF SORTING
SEARCHING AND SORTING ALGORITHMS, TYPES OF SORTING
mohanrajm63
 
STACK AND QUEUES APPLICATIONS, INFIX TO POST FIX
STACK AND QUEUES APPLICATIONS, INFIX TO POST FIXSTACK AND QUEUES APPLICATIONS, INFIX TO POST FIX
STACK AND QUEUES APPLICATIONS, INFIX TO POST FIX
mohanrajm63
 
ALGORITHM ANALYSIS AND LISTS ABSTACTS DT
ALGORITHM ANALYSIS AND LISTS ABSTACTS DTALGORITHM ANALYSIS AND LISTS ABSTACTS DT
ALGORITHM ANALYSIS AND LISTS ABSTACTS DT
mohanrajm63
 
METHOD OVERLOADING AND INHERITANCE INTERFACE
METHOD OVERLOADING AND INHERITANCE INTERFACEMETHOD OVERLOADING AND INHERITANCE INTERFACE
METHOD OVERLOADING AND INHERITANCE INTERFACE
mohanrajm63
 
EVENT DRIVEN PROGRAMMING SWING APPLET AWT
EVENT DRIVEN PROGRAMMING SWING APPLET AWTEVENT DRIVEN PROGRAMMING SWING APPLET AWT
EVENT DRIVEN PROGRAMMING SWING APPLET AWT
mohanrajm63
 
MULTITHREADING PROGRAMMING AND I/O THREAD
MULTITHREADING PROGRAMMING AND I/O THREADMULTITHREADING PROGRAMMING AND I/O THREAD
MULTITHREADING PROGRAMMING AND I/O THREAD
mohanrajm63
 
PACKAGES, INTERFACES AND EXCEPTION HANDLING
PACKAGES, INTERFACES AND EXCEPTION HANDLINGPACKAGES, INTERFACES AND EXCEPTION HANDLING
PACKAGES, INTERFACES AND EXCEPTION HANDLING
mohanrajm63
 
UNIT I OOP AND JAVA FUNDAMENTALS CONSTRUCTOR
UNIT I 	OOP AND JAVA FUNDAMENTALS CONSTRUCTORUNIT I 	OOP AND JAVA FUNDAMENTALS CONSTRUCTOR
UNIT I OOP AND JAVA FUNDAMENTALS CONSTRUCTOR
mohanrajm63
 
UNIT - 5 INTERFACE APPLIATIONS GROUP WARE SYSTEMS
UNIT - 5 INTERFACE APPLIATIONS GROUP WARE SYSTEMSUNIT - 5 INTERFACE APPLIATIONS GROUP WARE SYSTEMS
UNIT - 5 INTERFACE APPLIATIONS GROUP WARE SYSTEMS
mohanrajm63
 
MODELS AND EVALUATION FRAMEWORK GOALS AND TASK
MODELS AND EVALUATION FRAMEWORK GOALS AND TASKMODELS AND EVALUATION FRAMEWORK GOALS AND TASK
MODELS AND EVALUATION FRAMEWORK GOALS AND TASK
mohanrajm63
 
DESIGN RULES , PROCESS OF DESIGN, USER FOCUS
DESIGN RULES , PROCESS OF DESIGN, USER FOCUSDESIGN RULES , PROCESS OF DESIGN, USER FOCUS
DESIGN RULES , PROCESS OF DESIGN, USER FOCUS
mohanrajm63
 
INTERACTION AND INTERFACES MODEL OF THE INTERACTION
INTERACTION AND INTERFACES MODEL OF THE INTERACTIONINTERACTION AND INTERFACES MODEL OF THE INTERACTION
INTERACTION AND INTERFACES MODEL OF THE INTERACTION
mohanrajm63
 
THE INTRODUCTION - HUMAN AND COMPUTER BASICS
THE INTRODUCTION - HUMAN AND COMPUTER BASICSTHE INTRODUCTION - HUMAN AND COMPUTER BASICS
THE INTRODUCTION - HUMAN AND COMPUTER BASICS
mohanrajm63
 
OBJECT ORIENTED PROGRAMMING , S3 CLASS, S4 CLASS
OBJECT ORIENTED PROGRAMMING , S3 CLASS, S4 CLASSOBJECT ORIENTED PROGRAMMING , S3 CLASS, S4 CLASS
OBJECT ORIENTED PROGRAMMING , S3 CLASS, S4 CLASS
mohanrajm63
 
FACTORS AND TABLES, MINIMUM AND MAXIMA, DISTRIBUTIONS
FACTORS AND TABLES, MINIMUM AND MAXIMA, DISTRIBUTIONSFACTORS AND TABLES, MINIMUM AND MAXIMA, DISTRIBUTIONS
FACTORS AND TABLES, MINIMUM AND MAXIMA, DISTRIBUTIONS
mohanrajm63
 
LISTS, CREATING LIST, ACCESSING LIST AND INDEX
LISTS, CREATING LIST, ACCESSING LIST AND INDEXLISTS, CREATING LIST, ACCESSING LIST AND INDEX
LISTS, CREATING LIST, ACCESSING LIST AND INDEX
mohanrajm63
 
CONTROL STRUCTURES, DATA TYPES AND OBJECTS
CONTROL STRUCTURES, DATA TYPES AND OBJECTSCONTROL STRUCTURES, DATA TYPES AND OBJECTS
CONTROL STRUCTURES, DATA TYPES AND OBJECTS
mohanrajm63
 
R PROGRAMMING INTRODUCTION AND FEATURES,
R PROGRAMMING INTRODUCTION AND FEATURES,R PROGRAMMING INTRODUCTION AND FEATURES,
R PROGRAMMING INTRODUCTION AND FEATURES,
mohanrajm63
 
TREE ADT, TREE TRAVERSALS, BINARY TREE ADT
TREE ADT, TREE TRAVERSALS, BINARY TREE ADTTREE ADT, TREE TRAVERSALS, BINARY TREE ADT
TREE ADT, TREE TRAVERSALS, BINARY TREE ADT
mohanrajm63
 
SEARCHING AND SORTING ALGORITHMS, TYPES OF SORTING
SEARCHING AND SORTING ALGORITHMS, TYPES OF SORTINGSEARCHING AND SORTING ALGORITHMS, TYPES OF SORTING
SEARCHING AND SORTING ALGORITHMS, TYPES OF SORTING
mohanrajm63
 
STACK AND QUEUES APPLICATIONS, INFIX TO POST FIX
STACK AND QUEUES APPLICATIONS, INFIX TO POST FIXSTACK AND QUEUES APPLICATIONS, INFIX TO POST FIX
STACK AND QUEUES APPLICATIONS, INFIX TO POST FIX
mohanrajm63
 
ALGORITHM ANALYSIS AND LISTS ABSTACTS DT
ALGORITHM ANALYSIS AND LISTS ABSTACTS DTALGORITHM ANALYSIS AND LISTS ABSTACTS DT
ALGORITHM ANALYSIS AND LISTS ABSTACTS DT
mohanrajm63
 

Recently uploaded (20)

ENERGY STORING DEVICES-Primary Battery.pdf
ENERGY STORING DEVICES-Primary Battery.pdfENERGY STORING DEVICES-Primary Battery.pdf
ENERGY STORING DEVICES-Primary Battery.pdf
TAMILISAI R
 
ISO 4020-6.1- Filter Cleanliness Test Rig Catalogue.pdf
ISO 4020-6.1- Filter Cleanliness Test Rig Catalogue.pdfISO 4020-6.1- Filter Cleanliness Test Rig Catalogue.pdf
ISO 4020-6.1- Filter Cleanliness Test Rig Catalogue.pdf
FILTRATION ENGINEERING & CUNSULTANT
 
Highway Engineering - Pavement materials
Highway Engineering - Pavement materialsHighway Engineering - Pavement materials
Highway Engineering - Pavement materials
AmrutaBhosale9
 
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning ModelEnhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
IRJET Journal
 
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
IRJET Journal
 
ISO 4548-9 Oil Filter Anti Drain Catalogue.pdf
ISO 4548-9 Oil Filter Anti Drain Catalogue.pdfISO 4548-9 Oil Filter Anti Drain Catalogue.pdf
ISO 4548-9 Oil Filter Anti Drain Catalogue.pdf
FILTRATION ENGINEERING & CUNSULTANT
 
Video Games and Artificial-Realities.pptx
Video Games and Artificial-Realities.pptxVideo Games and Artificial-Realities.pptx
Video Games and Artificial-Realities.pptx
HadiBadri1
 
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 / HIFLUX Co., Ltd.
 
Electrical and Electronics Engineering: An International Journal (ELELIJ)
Electrical and Electronics Engineering: An International Journal (ELELIJ)Electrical and Electronics Engineering: An International Journal (ELELIJ)
Electrical and Electronics Engineering: An International Journal (ELELIJ)
elelijjournal653
 
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
BeHappy728244
 
ISO 5011 Air Filter Catalogues .pdf
ISO 5011 Air Filter Catalogues      .pdfISO 5011 Air Filter Catalogues      .pdf
ISO 5011 Air Filter Catalogues .pdf
FILTRATION ENGINEERING & CUNSULTANT
 
ISO 10121-Flat Sheet Media-Catalouge-Final.pdf
ISO 10121-Flat Sheet Media-Catalouge-Final.pdfISO 10121-Flat Sheet Media-Catalouge-Final.pdf
ISO 10121-Flat Sheet Media-Catalouge-Final.pdf
FILTRATION ENGINEERING & CUNSULTANT
 
Introduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptxIntroduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptx
gunjalsachin
 
Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...
Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...
Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...
ManiMaran230751
 
Axial Capacity Estimation of FRP-strengthened Corroded Concrete Columns
Axial Capacity Estimation of FRP-strengthened Corroded Concrete ColumnsAxial Capacity Estimation of FRP-strengthened Corroded Concrete Columns
Axial Capacity Estimation of FRP-strengthened Corroded Concrete Columns
Journal of Soft Computing in Civil Engineering
 
world subdivision.pdf...................
world subdivision.pdf...................world subdivision.pdf...................
world subdivision.pdf...................
bmmederos10
 
Webinar On Steel Melting IIF of steel for rdso
Webinar  On Steel  Melting IIF of steel for rdsoWebinar  On Steel  Melting IIF of steel for rdso
Webinar On Steel Melting IIF of steel for rdso
KapilParyani3
 
world subdivision.pdf...................
world subdivision.pdf...................world subdivision.pdf...................
world subdivision.pdf...................
bmmederos12
 
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDINGMODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
Dr. BASWESHWAR JIRWANKAR
 
Air Filter Flat Sheet Media-Catalouge-Final.pdf
Air Filter Flat Sheet Media-Catalouge-Final.pdfAir Filter Flat Sheet Media-Catalouge-Final.pdf
Air Filter Flat Sheet Media-Catalouge-Final.pdf
FILTRATION ENGINEERING & CUNSULTANT
 
ENERGY STORING DEVICES-Primary Battery.pdf
ENERGY STORING DEVICES-Primary Battery.pdfENERGY STORING DEVICES-Primary Battery.pdf
ENERGY STORING DEVICES-Primary Battery.pdf
TAMILISAI R
 
Highway Engineering - Pavement materials
Highway Engineering - Pavement materialsHighway Engineering - Pavement materials
Highway Engineering - Pavement materials
AmrutaBhosale9
 
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning ModelEnhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
Enhanced heart disease prediction using SKNDGR ensemble Machine Learning Model
IRJET Journal
 
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
Utilizing Biomedical Waste for Sustainable Brick Manufacturing: A Novel Appro...
IRJET Journal
 
Video Games and Artificial-Realities.pptx
Video Games and Artificial-Realities.pptxVideo Games and Artificial-Realities.pptx
Video Games and Artificial-Realities.pptx
HadiBadri1
 
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 락피팅 카달로그 2025 (Lok Fitting Catalog 2025)
하이플럭스 / HIFLUX Co., Ltd.
 
Electrical and Electronics Engineering: An International Journal (ELELIJ)
Electrical and Electronics Engineering: An International Journal (ELELIJ)Electrical and Electronics Engineering: An International Journal (ELELIJ)
Electrical and Electronics Engineering: An International Journal (ELELIJ)
elelijjournal653
 
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
Direct Current circuitsDirect Current circuitsDirect Current circuitsDirect C...
BeHappy728244
 
Introduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptxIntroduction of Structural Audit and Health Montoring.pptx
Introduction of Structural Audit and Health Montoring.pptx
gunjalsachin
 
Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...
Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...
Digital Crime – Substantive Criminal Law – General Conditions – Offenses – In...
ManiMaran230751
 
world subdivision.pdf...................
world subdivision.pdf...................world subdivision.pdf...................
world subdivision.pdf...................
bmmederos10
 
Webinar On Steel Melting IIF of steel for rdso
Webinar  On Steel  Melting IIF of steel for rdsoWebinar  On Steel  Melting IIF of steel for rdso
Webinar On Steel Melting IIF of steel for rdso
KapilParyani3
 
world subdivision.pdf...................
world subdivision.pdf...................world subdivision.pdf...................
world subdivision.pdf...................
bmmederos12
 
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDINGMODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
MODULE 4 BUILDING PLANNING AND DESIGN SY BTECH HVAC SYSTEM IN BUILDING
Dr. BASWESHWAR JIRWANKAR
 

GRAPHS, BREADTH FIRST TRAVERSAL AND DEPTH FIRST TRAVERSAL

  • 1. UNIT V SORTING AND HASHING TECHNIQUES
  • 2. Sorting • Sorting refers to arranging data in a particular format. Sorting algorithm specifies the way to arrange data in a particular order. Most common orders are in numerical or lexicographical order. • The importance of sorting lies in the fact that data searching can be optimized to a very high level, if data is stored in a sorted manner.
  • 3. Merge sort • Merge sort is defined as a sorting algorithm that works by dividing an array into smaller subarrays, sorting each subarray, and then merging the sorted subarrays back together to form the final sorted array.
  • 5. MERGE_SORT(arr, beg, end) if beg < end set mid = (beg + end)/2 MERGE_SORT(arr, beg, mid) MERGE_SORT(arr, mid + 1, end) MERGE (arr, beg, mid, end) end of if END MERGE_SORT
  • 6. Quicksort • Quicksort is the widely used sorting algorithm that makes n log n comparisons in average case for sorting an array of n elements. It is a faster and highly efficient sorting algorithm. • This algorithm follows the divide and conquer approach. Divide and conquer is a technique of breaking down the algorithms into subproblems, then solving the subproblems, and combining the results back together to solve the original problem.
  • 7. • Divide: In Divide, first pick a pivot element. After that, partition or rearrange the array into two sub-arrays such that each element in the left sub-array is less than or equal to the pivot element and each element in the right sub- array is larger than the pivot element. • Conquer: Recursively, sort two subarrays with Quicksort. • Combine: Combine the already sorted array.
  • 9. Algorithm QUICKSORT (array A, start, end) { if (start < end) { p = partition(A, start, end) QUICKSORT (A, start, p - 1) QUICKSORT (A, p + 1, end) } }
  • 10. Insertion sort • Insertion sort is a simple sorting algorithm that works similar to the way you sort playing cards in your hands. The array is virtually split into a sorted and an unsorted part. Values from the unsorted part are picked and placed at the correct position in the sorted part.
  • 12. Shell Sort • Shell sort is mainly a variation of Insertion Sort. In insertion sort, we move elements only one position ahead. • The idea of ShellSort is to allow the exchange of far items. In Shell sort, we make the array h- sorted for a large value of h. • We keep reducing the value of h until it becomes 1. An array is said to be h-sorted if all sublists of every h’th element are sorted.
  • 13. • PROCEDURE SHELL_SORT(ARRAY, N) WHILE GAP < LENGTH(ARRAY) /3 : GAP = ( INTERVAL * 3 ) + 1 END WHILE LOOP WHILE GAP > 0 : FOR (OUTER = GAP; OUTER < LENGTH(ARRAY); OUTER++): INSERTION_VALUE = ARRAY[OUTER] INNER = OUTER; WHILE INNER > GAP-1 AND ARRAY[INNER – GAP] >= INSERTION_VALUE: ARRAY[INNER] = ARRAY[INNER – GAP] INNER = INNER – GAP END WHILE LOOP ARRAY[INNER] = INSERTION_VALUE END FOR LOOP
  • 15. Radix sort • Radix Sort is a linear sorting algorithm that sorts elements by processing them digit by digit. It is an efficient sorting algorithm for integers or strings with fixed-size keys. • Radix Sort distributes the elements into buckets based on each digit’s value.
  • 17. • Hashing is the process of generating a value from a text or a list of numbers using a mathematical function known as a hash function. • A Hash Function is a function that converts a given numeric or alphanumeric key to a small practical integer value. The mapped integer value is used as an index in the hash table. In simple terms, a hash function maps a significant number or string to a small integer that can be used as the index in the hash table.
  • 18. • The pair is of the form (key, value), where for a given key, one can find a value using some kind of a “function” that maps keys to values. • A good hash function should have the following properties: • Efficiently computable. • Should uniformly distribute the keys (Each table position is equally likely for each. • Should minimize collisions. • Should have a low load factor(number of items in the table divided by the size of the table). • Complexity of calculating hash value using the hash function • Time complexity: O(n) • Space complexity: O(1)
  • 20. Collision • Collision in Hashing • In this, the hash function is used to find the index of the array. The hash value is used to create an index for the key in the hash table. The hash function may return the same hash value for two or more keys. When two or more keys have the same hash value, a collision happens. To handle this collision, we use collision resolution techniques.
  • 21. Collision Resolution Techniques • There are two types of collision resolution techniques. • Separate chaining (open hashing) • Open addressing (closed hashing) • Separate chaining: This method involves making a linked list out of the slot where the collision happened, then adding the new key to the list. Separate chaining is the term used to describe how this connected list of slots resembles a chain. It is more frequently utilized when we are unsure of the number of keys to add or remove. • Time complexity • Its worst-case complexity for searching is o(n). • Its worst-case complexity for deletion is o(n).
  • 22. • Open addressing: To prevent collisions in the hashing table open, addressing is employed as a collision- resolution technique. No key is kept anywhere else besides the hash table. As a result, the hash table’s size is never equal to or less than the number of keys. Additionally known as closed hashing. • The following techniques are used in open addressing: • Linear probing • Quadratic probing • Double hashing
  • 23. Linear Probing • In linear probing, the hash table is searched sequentially that starts from the original location of the hash. If in case the location that we get is already occupied, then we check for the next location. • The function used for rehashing is as follows: rehash(key) = (n+1)%table-size.
  • 25. Applications • Symbol tables: Linear probing is commonly used in symbol tables, which are used in compilers and interpreters to store variables and their associated values. Since symbol tables can grow dynamically, linear probing can be used to handle collisions and ensure that variables are stored efficiently. • Caching: Linear probing can be used in caching systems to store frequently accessed data in memory. When a cache miss occurs, the data can be loaded into the cache using linear probing, and when a collision occurs, the next available slot in the cache can be used to store the data. • Databases: Linear probing can be used in databases to store records and their associated keys. When a collision occurs, linear probing can be used to find the next available slot to store the record.
  • 26. Separate Chaining • The idea behind separate chaining is to implement the array as a linked list called a chain. Separate chaining is one of the most popular and commonly used techniques in order to handle collisions. • The linked list data structure is used to implement this technique. So what happens is, when multiple elements are hashed into the same slot index, then these elements are inserted into a singly- linked list which is known as a chain.
  • 28. Open Addressing • In Open Addressing, all elements are stored in the hash table itself. So at any point, the size of the table must be greater than or equal to the total number of keys. • This approach is also known as closed hashing. This entire procedure is based upon probing. We will understand the types of probing ahead:
  • 29. • Insert(k): Keep probing until an empty slot is found. Once an empty slot is found, insert k. • Search(k): Keep probing until the slot’s key doesn’t become equal to k or an empty slot is reached. • Delete(k): Delete operation is interesting. If we simply delete a key, then the search may fail. So slots of deleted keys are marked specially as “deleted”.
  • 30. Rehashing • Rehashing is the process of recalculating the hashcode of previously-stored entries (Key- Value pairs) in order to shift them to a larger size hashmap when the threshold is reached/crossed, • When the number of elements in a hash map reaches the maximum threshold value, it is rehashed.
  • 32. How Rehashing is done? Rehashing can be done as follows: • For each addition of a new entry to the map, check the load factor. • If it’s greater than its pre-defined value (or default value of 0.75 if not given), then Rehash. • For Rehash, make a new array of double the previous size and make it the new bucketarray. • Then traverse to each element in the old bucketArray and call the insert() for each so as to insert it into the new larger bucket array.
  • 33. Extendible Hashing • Extendible Hashing is a dynamic hashing method wherein directories, and buckets are used to hash data. It is an aggressively flexible method in which the hash function also experiences dynamic changes. • Main features of Extendible Hashing: The main features in this hashing technique are: • Directories: The directories store addresses of the buckets in pointers. An id is assigned to each directory which may change each time when Directory Expansion takes place. • Buckets: The buckets are used to hash the actual data.