SlideShare a Scribd company logo
Data Structure And
Algorithms
UNIT-5
Searching, hashing and sorting
25/4/2020
1
Submitted by
Bhanupratap Singh Hirwani
Searching
• The process of locating target data is known as searching.
• Searching is the process of finding the location of the target
among a list of object.
• The two basic search techniques are the followings:
-sequential search
-binary search
25/4/2020
2
Linear Search
• The linear search is a sequential search which uses a loop to step
through an array, starting with the first element.
• It compares each element with the value being searched for, and
stops when either the value is found or the end of the array is
encountered.
• A search will be unsuccessful if all the elements are read and
desired element is not found
25/4/2020
3
Linear Search Algorithm
• Linear Search( Array A, Values X)
• Step 1: set i to 1
• Step 2: if i > n then go to step 7
• Step 3: if A[i] = X then go to step 6
• Step 4: set i to i+1
• Step 5: go to step 2
• Step 6: print element x found at index i and go to step 8
• Step 7: print element not found
• Step 8: exit
25/4/2020
4
Advantages and Disadvantages
• The linear search is a simple- it is very easy to understand and
implement
• It does not require the data in the array to be stored in any
particular order
• DISADVANTAGES
• It has very poor efficiency because it takes lots of comparisons to
find a particular record in big files
• Linear search is slower than other searching algorithms
25/4/2020
5
Binary Search
What is Binary Search?
• Binary search is an extremely
efficient algorithm when it is
compared to linear search.
• It searches data in minimum possible
comparisons.
• Binary search use sorted array by
repeatedly dividing the search
interval in half.
Algorithm
• Step 1: compare x with the middle
element.
• Step 2:If x matches with middle
element, we return the mid index.
• Step 3: Else if x is greater than the
mid element, search on right half.
• Step 4: Else if x is smaller than the
mid element, search on left half
25/4/2020
6
Example
• Assume the following array
• Search for 40
• Compare X=40
25/4/2020
7
Hashing
• Hashing is a technique where we can compute the location of the
desired record in order to retrieve it in a single access (or
comparison) .
• Hashing involves less key comparison and searching can
performed in constant time.
• The goal of hashed search is to find the target data in only one
test i.e. O(1)(best complexity).
• Hashing is an efficient method to store and retrieve elements.
• In hashing function the keys are stored in array which is called
hash table.
25/4/2020
8
Hashing function
• The basic idea of hash function Is the transformation of the key into the
corresponding location in the hash table.
• A Hash function H can be defined as a function as a function that takes key as
input and transforms it into a hash table index.
• The values returned by hash function are called hash values , hash codes, hash
sums, or simply hashes.
• Hash function are two types: 1) distribution –independent function ,2)
distribution-dependent function.
• The distribution independent hash functions are : a) division method, b) mid
square method, c) digit folding method.
25/4/2020
9
Hash Collision
• When an element is inserted, if it hashes to the same value as an
already inserted element, then we have a collision.
• A situation in which the hash function returns the same hash key
for more then one record , it is called as collision.
25/4/2020
10
Collision resolution technique
• If there is a problem of collision occurs then it can be handled by apply
some technique.these techniques are called as collision resolution
techniques.
• If the element to be inserted is mapped to the same location, where an
element is already inserted then we have a collision and it must be
resolved.
• There are several strategies for collision resolution. The most commonly
used are:
1) separate chaining- it used with open hashing.
2) open addressing- it used with closed hashing.
25/4/2020
11
Separate Chaining(open hashing)
• Separate chaining based on collision avoidance.
• The idea is to keep a list of all elements that hash to the same value.
-the array elements are pointers to the first nodes of the lists.
-A new item is inserted to the front of the list.
• Advantages:
- batter space utilization for large items.
-simple collision handling : searching link list.
-deletion is quick and easy : deletion from the linked list.
25/4/2020
12
Examples:
25/4/2020
13
Sorting
• Sorting is the operation of arranging the records of a table according to the key
value of each record, or it can be defined as the process of converting an
unordered set of elements to an ordered set of elements.
• Sorting is a process of organizing data in a certain order to help retrieve it more
efficiently.
• Sorting techniques can be divided into two categories. These are:
1) Internal sorting , 2) external sorting.
• Any sort algorithm that uses main memory exclusively during the sorting is
called as internal sort algorithm
• Any sort algorithm that uses external memory, such as tape or disk, during the
sorting is called as external sorting.
• Internal sorting is faster then external sorting. 25/4/2020
14
Internal Sorting |External Sorting
• The various internal sorting techniques are
the following:
1. Bubble sort
2. Selection sort
3. Insertion sort
4. Quick sort
5. Shell sort
6. Heap sort
7. Radix sort
8. Bucket sort
• Merge sort is used in external
sorting
25/4/2020
15
Bubble Sort
What is bubble sort?
• Bubble sort is simple algorithm
which is used to sort a given set of n
elements provided in form of an
array with n number of elements.
• Bubble sort compares all the
element one by one and sort them
based on their values.
• The bubble sort derives its name
from the fact that the smallest data
item bubbles up to the top of the
sorted array.
Algorithm for bubble sort
1. Starting with the first element(index=0),
compare the current element with the
next element of the array.
2. If the current element is greater than the
next element of the array, swap them.
3. If the current element is less than the
next element, move to the next element.
Repeat step 1
25/4/2020
16
Selection Sort
What is selection sort?
• Selection sort is a simple sorting algorithm.
• In this technique, the smallest element is
interchanged with the first element of the array.
• Then the next smallest element is interchanged with
the second element of the array.
• This process of searching the next smallest element
and placing it in its proper position continues until
all records have been sorted in ascending order.
Algorithm
For i<-1 to n-1 do
min<-i
for j<-i+1 to n do
if A[j]<A[i] then
min<-j
if min!=i then
temp<-A[i]
A[i]<-A[min]
A[min]<-temp
25/4/2020
17
Radix sort
• Radix sort algorithm different than other sorting algorithms .
• It does not use key comparisons to sort an array.
• The radix sort treats each data items as a character string.
• First it groups data items according to their rightmost character and put
these groups into order with respect to this right most character.
• Then combine these groups.
• We repeat these groupings and combining operation for all other
character positions in the data items from the right most to the left
most character position.
• At the end, the sort operation will be completed
25/4/2020
18
Heap Sort
• Heap is a special tree based data structure, that satisfies the
following special heap properties: 1)shape property , 2)heap
property
• Heap sort is the one of the fastest sorting algorithm, which
achieves the speed as that of quick sort and merge sort.
• The advantages of heap sort are as follows:
• It dose not use recursion, and it is efficient for any data order.
• It achieves the worst-case bounds better than those of quick sort.
• And for the list, it is better than merge sort since it needs only a
small and constant of space apart from the list being sorted
25/4/2020
19
Merge Sort(external sort)
• The most common algorithm used in external sorting is the merge sort.
• Merging is the process of combining two or more sorted files into the third
sorted file.
• The merge sort algorithm is base on the classical divide-and-conquer paradigm.
• Divide-and-conquer algorithm works in three steps:
1. Divide the problem into multiple small problems.
2. Conquer the subproblems by solving them. The idea is to break down the
problem into atomic subproblems, where they are actually solved.
3. Combine the solutions of the subproblems to find the solution of the actual
problem.
25/4/2020
20

More Related Content

What's hot

Hashing
HashingHashing
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm
03446940736
 
Dsa – data structure and algorithms sorting
Dsa – data structure and algorithms  sortingDsa – data structure and algorithms  sorting
Dsa – data structure and algorithms sorting
sajinis3
 
linear search and binary search
linear search and binary searchlinear search and binary search
linear search and binary search
Zia Ush Shamszaman
 
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHIBCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
Sowmya Jyothi
 
Data Structures 7
Data Structures 7Data Structures 7
Data Structures 7
Dr.Umadevi V
 
Binary search python
Binary search pythonBinary search python
Binary search python
MaryamAnwar10
 
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHIBCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
ADS Introduction
ADS IntroductionADS Introduction
ADS Introduction
NagendraK18
 
Data Structures 8
Data Structures 8Data Structures 8
Data Structures 8
Dr.Umadevi V
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGEST
Swapnil Mishra
 
Data Structures 6
Data Structures 6Data Structures 6
Data Structures 6
Dr.Umadevi V
 
Lecture 07 Data Structures - Basic Sorting
Lecture 07 Data Structures - Basic SortingLecture 07 Data Structures - Basic Sorting
Lecture 07 Data Structures - Basic Sorting
Haitham El-Ghareeb
 
Week 2 - Data Structures and Algorithms
Week 2 - Data Structures and AlgorithmsWeek 2 - Data Structures and Algorithms
Week 2 - Data Structures and Algorithms
Ferdin Joe John Joseph PhD
 
Unit 2 linear data structures
Unit 2   linear data structuresUnit 2   linear data structures
Unit 2 linear data structures
Senthil Murugan
 
11. Hashing - Data Structures using C++ by Varsha Patil
11. Hashing - Data Structures using C++ by Varsha Patil11. Hashing - Data Structures using C++ by Varsha Patil
11. Hashing - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
IRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching AlgorithmsIRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching Algorithms
IRJET Journal
 
Sequential & binary, linear search
Sequential & binary, linear searchSequential & binary, linear search
Sequential & binary, linear search
montazur420
 
Non-Uniform Gap Distribution Library Sort
Non-Uniform Gap Distribution Library SortNon-Uniform Gap Distribution Library Sort
Non-Uniform Gap Distribution Library Sort
IJCSIS Research Publications
 
9. Searching & Sorting - Data Structures using C++ by Varsha Patil
9. Searching & Sorting - Data Structures using C++ by Varsha Patil9. Searching & Sorting - Data Structures using C++ by Varsha Patil
9. Searching & Sorting - Data Structures using C++ by Varsha Patil
widespreadpromotion
 

What's hot (20)

Hashing
HashingHashing
Hashing
 
Searching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And AlgorithmSearching techniques in Data Structure And Algorithm
Searching techniques in Data Structure And Algorithm
 
Dsa – data structure and algorithms sorting
Dsa – data structure and algorithms  sortingDsa – data structure and algorithms  sorting
Dsa – data structure and algorithms sorting
 
linear search and binary search
linear search and binary searchlinear search and binary search
linear search and binary search
 
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHIBCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
BCA DATA STRUCTURES INTRODUCTION AND OVERVIEW SOWMYA JYOTHI
 
Data Structures 7
Data Structures 7Data Structures 7
Data Structures 7
 
Binary search python
Binary search pythonBinary search python
Binary search python
 
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHIBCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
 
ADS Introduction
ADS IntroductionADS Introduction
ADS Introduction
 
Data Structures 8
Data Structures 8Data Structures 8
Data Structures 8
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGEST
 
Data Structures 6
Data Structures 6Data Structures 6
Data Structures 6
 
Lecture 07 Data Structures - Basic Sorting
Lecture 07 Data Structures - Basic SortingLecture 07 Data Structures - Basic Sorting
Lecture 07 Data Structures - Basic Sorting
 
Week 2 - Data Structures and Algorithms
Week 2 - Data Structures and AlgorithmsWeek 2 - Data Structures and Algorithms
Week 2 - Data Structures and Algorithms
 
Unit 2 linear data structures
Unit 2   linear data structuresUnit 2   linear data structures
Unit 2 linear data structures
 
11. Hashing - Data Structures using C++ by Varsha Patil
11. Hashing - Data Structures using C++ by Varsha Patil11. Hashing - Data Structures using C++ by Varsha Patil
11. Hashing - Data Structures using C++ by Varsha Patil
 
IRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching AlgorithmsIRJET- A Survey on Different Searching Algorithms
IRJET- A Survey on Different Searching Algorithms
 
Sequential & binary, linear search
Sequential & binary, linear searchSequential & binary, linear search
Sequential & binary, linear search
 
Non-Uniform Gap Distribution Library Sort
Non-Uniform Gap Distribution Library SortNon-Uniform Gap Distribution Library Sort
Non-Uniform Gap Distribution Library Sort
 
9. Searching & Sorting - Data Structures using C++ by Varsha Patil
9. Searching & Sorting - Data Structures using C++ by Varsha Patil9. Searching & Sorting - Data Structures using C++ by Varsha Patil
9. Searching & Sorting - Data Structures using C++ by Varsha Patil
 

Similar to Data structure and algorithms

SORTING techniques.pptx
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptx
Dr.Shweta
 
Searching, Sorting and Hashing Techniques
Searching, Sorting and Hashing TechniquesSearching, Sorting and Hashing Techniques
Searching, Sorting and Hashing Techniques
Selvaraj Seerangan
 
searching techniques.pptx
searching techniques.pptxsearching techniques.pptx
searching techniques.pptx
Dr.Shweta
 
data_structure_Chapter two_computer.pptx
data_structure_Chapter two_computer.pptxdata_structure_Chapter two_computer.pptx
data_structure_Chapter two_computer.pptx
Mohammed472103
 
Data Structure & Algorithms - Operations
Data Structure & Algorithms - OperationsData Structure & Algorithms - Operations
Data Structure & Algorithms - Operations
babuk110
 
programming in C
programming in Cprogramming in C
programming in C
ADITHYAM19
 
Sorting
SortingSorting
Sorting
FahadSaeed39
 
Rahat &amp; juhith
Rahat &amp; juhithRahat &amp; juhith
Rahat &amp; juhith
Rj Juhith
 
cs702 ppt.ppt
cs702 ppt.pptcs702 ppt.ppt
cs702 ppt.ppt
JavedIqbal398171
 
DS Module1 (1).pptx
DS Module1 (1).pptxDS Module1 (1).pptx
DS Module1 (1).pptx
AnuJoseph95
 
Data Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingData Structures_ Sorting & Searching
Data Structures_ Sorting & Searching
ThenmozhiK5
 
DS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptx
prakashvs7
 
Chapter 4.pptx
Chapter 4.pptxChapter 4.pptx
Chapter 4.pptx
Tekle12
 
Searching Algorithms for students of CS and IT using C++
Searching Algorithms for students of CS and IT using C++Searching Algorithms for students of CS and IT using C++
Searching Algorithms for students of CS and IT using C++
shahidameer8
 
DS PPT - ( 1 )SORTING lgoritham techniques with bast example
DS PPT - ( 1 )SORTING lgoritham techniques with bast exampleDS PPT - ( 1 )SORTING lgoritham techniques with bast example
DS PPT - ( 1 )SORTING lgoritham techniques with bast example
Vivek487417
 
Searching,sorting
Searching,sortingSearching,sorting
Searching,sorting
LavanyaJ28
 
21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptx21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptx
reddy19841
 
Binary search algorithm.pptx
Binary search  algorithm.pptxBinary search  algorithm.pptx
Binary search algorithm.pptx
bhuvansaachi18
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
lecture 02.2.ppt
lecture 02.2.pptlecture 02.2.ppt
lecture 02.2.ppt
NathanielAdika
 

Similar to Data structure and algorithms (20)

SORTING techniques.pptx
SORTING techniques.pptxSORTING techniques.pptx
SORTING techniques.pptx
 
Searching, Sorting and Hashing Techniques
Searching, Sorting and Hashing TechniquesSearching, Sorting and Hashing Techniques
Searching, Sorting and Hashing Techniques
 
searching techniques.pptx
searching techniques.pptxsearching techniques.pptx
searching techniques.pptx
 
data_structure_Chapter two_computer.pptx
data_structure_Chapter two_computer.pptxdata_structure_Chapter two_computer.pptx
data_structure_Chapter two_computer.pptx
 
Data Structure & Algorithms - Operations
Data Structure & Algorithms - OperationsData Structure & Algorithms - Operations
Data Structure & Algorithms - Operations
 
programming in C
programming in Cprogramming in C
programming in C
 
Sorting
SortingSorting
Sorting
 
Rahat &amp; juhith
Rahat &amp; juhithRahat &amp; juhith
Rahat &amp; juhith
 
cs702 ppt.ppt
cs702 ppt.pptcs702 ppt.ppt
cs702 ppt.ppt
 
DS Module1 (1).pptx
DS Module1 (1).pptxDS Module1 (1).pptx
DS Module1 (1).pptx
 
Data Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingData Structures_ Sorting & Searching
Data Structures_ Sorting & Searching
 
DS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptx
 
Chapter 4.pptx
Chapter 4.pptxChapter 4.pptx
Chapter 4.pptx
 
Searching Algorithms for students of CS and IT using C++
Searching Algorithms for students of CS and IT using C++Searching Algorithms for students of CS and IT using C++
Searching Algorithms for students of CS and IT using C++
 
DS PPT - ( 1 )SORTING lgoritham techniques with bast example
DS PPT - ( 1 )SORTING lgoritham techniques with bast exampleDS PPT - ( 1 )SORTING lgoritham techniques with bast example
DS PPT - ( 1 )SORTING lgoritham techniques with bast example
 
Searching,sorting
Searching,sortingSearching,sorting
Searching,sorting
 
21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptx21CS32 DS Module 1 PPT.pptx
21CS32 DS Module 1 PPT.pptx
 
Binary search algorithm.pptx
Binary search  algorithm.pptxBinary search  algorithm.pptx
Binary search algorithm.pptx
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
lecture 02.2.ppt
lecture 02.2.pptlecture 02.2.ppt
lecture 02.2.ppt
 

Recently uploaded

aziz sancar nobel prize winner: from mardin to nobel
aziz sancar nobel prize winner: from mardin to nobelaziz sancar nobel prize winner: from mardin to nobel
aziz sancar nobel prize winner: from mardin to nobel
İsa Badur
 
Sharlene Leurig - Enabling Onsite Water Use with Net Zero Water
Sharlene Leurig - Enabling Onsite Water Use with Net Zero WaterSharlene Leurig - Enabling Onsite Water Use with Net Zero Water
Sharlene Leurig - Enabling Onsite Water Use with Net Zero Water
Texas Alliance of Groundwater Districts
 
原版制作(carleton毕业证书)卡尔顿大学毕业证硕士文凭原版一模一样
原版制作(carleton毕业证书)卡尔顿大学毕业证硕士文凭原版一模一样原版制作(carleton毕业证书)卡尔顿大学毕业证硕士文凭原版一模一样
原版制作(carleton毕业证书)卡尔顿大学毕业证硕士文凭原版一模一样
yqqaatn0
 
Shallowest Oil Discovery of Turkiye.pptx
Shallowest Oil Discovery of Turkiye.pptxShallowest Oil Discovery of Turkiye.pptx
Shallowest Oil Discovery of Turkiye.pptx
Gokturk Mehmet Dilci
 
Cytokines and their role in immune regulation.pptx
Cytokines and their role in immune regulation.pptxCytokines and their role in immune regulation.pptx
Cytokines and their role in immune regulation.pptx
Hitesh Sikarwar
 
BREEDING METHODS FOR DISEASE RESISTANCE.pptx
BREEDING METHODS FOR DISEASE RESISTANCE.pptxBREEDING METHODS FOR DISEASE RESISTANCE.pptx
BREEDING METHODS FOR DISEASE RESISTANCE.pptx
RASHMI M G
 
Bob Reedy - Nitrate in Texas Groundwater.pdf
Bob Reedy - Nitrate in Texas Groundwater.pdfBob Reedy - Nitrate in Texas Groundwater.pdf
Bob Reedy - Nitrate in Texas Groundwater.pdf
Texas Alliance of Groundwater Districts
 
Equivariant neural networks and representation theory
Equivariant neural networks and representation theoryEquivariant neural networks and representation theory
Equivariant neural networks and representation theory
Daniel Tubbenhauer
 
Chapter 12 - climate change and the energy crisis
Chapter 12 - climate change and the energy crisisChapter 12 - climate change and the energy crisis
Chapter 12 - climate change and the energy crisis
tonzsalvador2222
 
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
University of Maribor
 
Nucleophilic Addition of carbonyl compounds.pptx
Nucleophilic Addition of carbonyl  compounds.pptxNucleophilic Addition of carbonyl  compounds.pptx
Nucleophilic Addition of carbonyl compounds.pptx
SSR02
 
Applied Science: Thermodynamics, Laws & Methodology.pdf
Applied Science: Thermodynamics, Laws & Methodology.pdfApplied Science: Thermodynamics, Laws & Methodology.pdf
Applied Science: Thermodynamics, Laws & Methodology.pdf
University of Hertfordshire
 
Thornton ESPP slides UK WW Network 4_6_24.pdf
Thornton ESPP slides UK WW Network 4_6_24.pdfThornton ESPP slides UK WW Network 4_6_24.pdf
Thornton ESPP slides UK WW Network 4_6_24.pdf
European Sustainable Phosphorus Platform
 
Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...
Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...
Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...
AbdullaAlAsif1
 
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptxThe use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
MAGOTI ERNEST
 
8.Isolation of pure cultures and preservation of cultures.pdf
8.Isolation of pure cultures and preservation of cultures.pdf8.Isolation of pure cultures and preservation of cultures.pdf
8.Isolation of pure cultures and preservation of cultures.pdf
by6843629
 
molar-distalization in orthodontics-seminar.pptx
molar-distalization in orthodontics-seminar.pptxmolar-distalization in orthodontics-seminar.pptx
molar-distalization in orthodontics-seminar.pptx
Anagha Prasad
 
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Ana Luísa Pinho
 
20240520 Planning a Circuit Simulator in JavaScript.pptx
20240520 Planning a Circuit Simulator in JavaScript.pptx20240520 Planning a Circuit Simulator in JavaScript.pptx
20240520 Planning a Circuit Simulator in JavaScript.pptx
Sharon Liu
 
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
yqqaatn0
 

Recently uploaded (20)

aziz sancar nobel prize winner: from mardin to nobel
aziz sancar nobel prize winner: from mardin to nobelaziz sancar nobel prize winner: from mardin to nobel
aziz sancar nobel prize winner: from mardin to nobel
 
Sharlene Leurig - Enabling Onsite Water Use with Net Zero Water
Sharlene Leurig - Enabling Onsite Water Use with Net Zero WaterSharlene Leurig - Enabling Onsite Water Use with Net Zero Water
Sharlene Leurig - Enabling Onsite Water Use with Net Zero Water
 
原版制作(carleton毕业证书)卡尔顿大学毕业证硕士文凭原版一模一样
原版制作(carleton毕业证书)卡尔顿大学毕业证硕士文凭原版一模一样原版制作(carleton毕业证书)卡尔顿大学毕业证硕士文凭原版一模一样
原版制作(carleton毕业证书)卡尔顿大学毕业证硕士文凭原版一模一样
 
Shallowest Oil Discovery of Turkiye.pptx
Shallowest Oil Discovery of Turkiye.pptxShallowest Oil Discovery of Turkiye.pptx
Shallowest Oil Discovery of Turkiye.pptx
 
Cytokines and their role in immune regulation.pptx
Cytokines and their role in immune regulation.pptxCytokines and their role in immune regulation.pptx
Cytokines and their role in immune regulation.pptx
 
BREEDING METHODS FOR DISEASE RESISTANCE.pptx
BREEDING METHODS FOR DISEASE RESISTANCE.pptxBREEDING METHODS FOR DISEASE RESISTANCE.pptx
BREEDING METHODS FOR DISEASE RESISTANCE.pptx
 
Bob Reedy - Nitrate in Texas Groundwater.pdf
Bob Reedy - Nitrate in Texas Groundwater.pdfBob Reedy - Nitrate in Texas Groundwater.pdf
Bob Reedy - Nitrate in Texas Groundwater.pdf
 
Equivariant neural networks and representation theory
Equivariant neural networks and representation theoryEquivariant neural networks and representation theory
Equivariant neural networks and representation theory
 
Chapter 12 - climate change and the energy crisis
Chapter 12 - climate change and the energy crisisChapter 12 - climate change and the energy crisis
Chapter 12 - climate change and the energy crisis
 
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
Comparing Evolved Extractive Text Summary Scores of Bidirectional Encoder Rep...
 
Nucleophilic Addition of carbonyl compounds.pptx
Nucleophilic Addition of carbonyl  compounds.pptxNucleophilic Addition of carbonyl  compounds.pptx
Nucleophilic Addition of carbonyl compounds.pptx
 
Applied Science: Thermodynamics, Laws & Methodology.pdf
Applied Science: Thermodynamics, Laws & Methodology.pdfApplied Science: Thermodynamics, Laws & Methodology.pdf
Applied Science: Thermodynamics, Laws & Methodology.pdf
 
Thornton ESPP slides UK WW Network 4_6_24.pdf
Thornton ESPP slides UK WW Network 4_6_24.pdfThornton ESPP slides UK WW Network 4_6_24.pdf
Thornton ESPP slides UK WW Network 4_6_24.pdf
 
Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...
Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...
Unlocking the mysteries of reproduction: Exploring fecundity and gonadosomati...
 
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptxThe use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
The use of Nauplii and metanauplii artemia in aquaculture (brine shrimp).pptx
 
8.Isolation of pure cultures and preservation of cultures.pdf
8.Isolation of pure cultures and preservation of cultures.pdf8.Isolation of pure cultures and preservation of cultures.pdf
8.Isolation of pure cultures and preservation of cultures.pdf
 
molar-distalization in orthodontics-seminar.pptx
molar-distalization in orthodontics-seminar.pptxmolar-distalization in orthodontics-seminar.pptx
molar-distalization in orthodontics-seminar.pptx
 
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
Deep Behavioral Phenotyping in Systems Neuroscience for Functional Atlasing a...
 
20240520 Planning a Circuit Simulator in JavaScript.pptx
20240520 Planning a Circuit Simulator in JavaScript.pptx20240520 Planning a Circuit Simulator in JavaScript.pptx
20240520 Planning a Circuit Simulator in JavaScript.pptx
 
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
如何办理(uvic毕业证书)维多利亚大学毕业证本科学位证书原版一模一样
 

Data structure and algorithms

  • 1. Data Structure And Algorithms UNIT-5 Searching, hashing and sorting 25/4/2020 1 Submitted by Bhanupratap Singh Hirwani
  • 2. Searching • The process of locating target data is known as searching. • Searching is the process of finding the location of the target among a list of object. • The two basic search techniques are the followings: -sequential search -binary search 25/4/2020 2
  • 3. Linear Search • The linear search is a sequential search which uses a loop to step through an array, starting with the first element. • It compares each element with the value being searched for, and stops when either the value is found or the end of the array is encountered. • A search will be unsuccessful if all the elements are read and desired element is not found 25/4/2020 3
  • 4. Linear Search Algorithm • Linear Search( Array A, Values X) • Step 1: set i to 1 • Step 2: if i > n then go to step 7 • Step 3: if A[i] = X then go to step 6 • Step 4: set i to i+1 • Step 5: go to step 2 • Step 6: print element x found at index i and go to step 8 • Step 7: print element not found • Step 8: exit 25/4/2020 4
  • 5. Advantages and Disadvantages • The linear search is a simple- it is very easy to understand and implement • It does not require the data in the array to be stored in any particular order • DISADVANTAGES • It has very poor efficiency because it takes lots of comparisons to find a particular record in big files • Linear search is slower than other searching algorithms 25/4/2020 5
  • 6. Binary Search What is Binary Search? • Binary search is an extremely efficient algorithm when it is compared to linear search. • It searches data in minimum possible comparisons. • Binary search use sorted array by repeatedly dividing the search interval in half. Algorithm • Step 1: compare x with the middle element. • Step 2:If x matches with middle element, we return the mid index. • Step 3: Else if x is greater than the mid element, search on right half. • Step 4: Else if x is smaller than the mid element, search on left half 25/4/2020 6
  • 7. Example • Assume the following array • Search for 40 • Compare X=40 25/4/2020 7
  • 8. Hashing • Hashing is a technique where we can compute the location of the desired record in order to retrieve it in a single access (or comparison) . • Hashing involves less key comparison and searching can performed in constant time. • The goal of hashed search is to find the target data in only one test i.e. O(1)(best complexity). • Hashing is an efficient method to store and retrieve elements. • In hashing function the keys are stored in array which is called hash table. 25/4/2020 8
  • 9. Hashing function • The basic idea of hash function Is the transformation of the key into the corresponding location in the hash table. • A Hash function H can be defined as a function as a function that takes key as input and transforms it into a hash table index. • The values returned by hash function are called hash values , hash codes, hash sums, or simply hashes. • Hash function are two types: 1) distribution –independent function ,2) distribution-dependent function. • The distribution independent hash functions are : a) division method, b) mid square method, c) digit folding method. 25/4/2020 9
  • 10. Hash Collision • When an element is inserted, if it hashes to the same value as an already inserted element, then we have a collision. • A situation in which the hash function returns the same hash key for more then one record , it is called as collision. 25/4/2020 10
  • 11. Collision resolution technique • If there is a problem of collision occurs then it can be handled by apply some technique.these techniques are called as collision resolution techniques. • If the element to be inserted is mapped to the same location, where an element is already inserted then we have a collision and it must be resolved. • There are several strategies for collision resolution. The most commonly used are: 1) separate chaining- it used with open hashing. 2) open addressing- it used with closed hashing. 25/4/2020 11
  • 12. Separate Chaining(open hashing) • Separate chaining based on collision avoidance. • The idea is to keep a list of all elements that hash to the same value. -the array elements are pointers to the first nodes of the lists. -A new item is inserted to the front of the list. • Advantages: - batter space utilization for large items. -simple collision handling : searching link list. -deletion is quick and easy : deletion from the linked list. 25/4/2020 12
  • 14. Sorting • Sorting is the operation of arranging the records of a table according to the key value of each record, or it can be defined as the process of converting an unordered set of elements to an ordered set of elements. • Sorting is a process of organizing data in a certain order to help retrieve it more efficiently. • Sorting techniques can be divided into two categories. These are: 1) Internal sorting , 2) external sorting. • Any sort algorithm that uses main memory exclusively during the sorting is called as internal sort algorithm • Any sort algorithm that uses external memory, such as tape or disk, during the sorting is called as external sorting. • Internal sorting is faster then external sorting. 25/4/2020 14
  • 15. Internal Sorting |External Sorting • The various internal sorting techniques are the following: 1. Bubble sort 2. Selection sort 3. Insertion sort 4. Quick sort 5. Shell sort 6. Heap sort 7. Radix sort 8. Bucket sort • Merge sort is used in external sorting 25/4/2020 15
  • 16. Bubble Sort What is bubble sort? • Bubble sort is simple algorithm which is used to sort a given set of n elements provided in form of an array with n number of elements. • Bubble sort compares all the element one by one and sort them based on their values. • The bubble sort derives its name from the fact that the smallest data item bubbles up to the top of the sorted array. Algorithm for bubble sort 1. Starting with the first element(index=0), compare the current element with the next element of the array. 2. If the current element is greater than the next element of the array, swap them. 3. If the current element is less than the next element, move to the next element. Repeat step 1 25/4/2020 16
  • 17. Selection Sort What is selection sort? • Selection sort is a simple sorting algorithm. • In this technique, the smallest element is interchanged with the first element of the array. • Then the next smallest element is interchanged with the second element of the array. • This process of searching the next smallest element and placing it in its proper position continues until all records have been sorted in ascending order. Algorithm For i<-1 to n-1 do min<-i for j<-i+1 to n do if A[j]<A[i] then min<-j if min!=i then temp<-A[i] A[i]<-A[min] A[min]<-temp 25/4/2020 17
  • 18. Radix sort • Radix sort algorithm different than other sorting algorithms . • It does not use key comparisons to sort an array. • The radix sort treats each data items as a character string. • First it groups data items according to their rightmost character and put these groups into order with respect to this right most character. • Then combine these groups. • We repeat these groupings and combining operation for all other character positions in the data items from the right most to the left most character position. • At the end, the sort operation will be completed 25/4/2020 18
  • 19. Heap Sort • Heap is a special tree based data structure, that satisfies the following special heap properties: 1)shape property , 2)heap property • Heap sort is the one of the fastest sorting algorithm, which achieves the speed as that of quick sort and merge sort. • The advantages of heap sort are as follows: • It dose not use recursion, and it is efficient for any data order. • It achieves the worst-case bounds better than those of quick sort. • And for the list, it is better than merge sort since it needs only a small and constant of space apart from the list being sorted 25/4/2020 19
  • 20. Merge Sort(external sort) • The most common algorithm used in external sorting is the merge sort. • Merging is the process of combining two or more sorted files into the third sorted file. • The merge sort algorithm is base on the classical divide-and-conquer paradigm. • Divide-and-conquer algorithm works in three steps: 1. Divide the problem into multiple small problems. 2. Conquer the subproblems by solving them. The idea is to break down the problem into atomic subproblems, where they are actually solved. 3. Combine the solutions of the subproblems to find the solution of the actual problem. 25/4/2020 20