SlideShare a Scribd company logo
scalescale
Search Algorithms
Technical Writing(CS1305) Assignment
Aditya Kumar
20142028
MNNIT Allahabad
August 2015
Aditya Kumar 20142028 Search Algorithms
scalescale
Introduction
In computer science, a search algorithm is an algorithm
for finding an item with specified properties among a
collection of items which are coded into a computer
program.
The program then looks for clues to give us back exactly
what we want.
Aditya Kumar 20142028 Search Algorithms
scalescale
Introduction
In computer science, a search algorithm is an algorithm
for finding an item with specified properties among a
collection of items which are coded into a computer
program.
The program then looks for clues to give us back exactly
what we want.
We are going to cover two search algoritms in this
presentation: linear and binary.
Aditya Kumar 20142028 Search Algorithms
scalescale
Linear Search
Linear search is a method for finding a particular value in
a list that checks each element in sequence until the
desired element is found or the list is exhausted
Aditya Kumar 20142028 Search Algorithms
scalescale
Linear Search
Linear search is a method for finding a particular value in
a list that checks each element in sequence until the
desired element is found or the list is exhausted
It is the simplest search algorithm
A special case of brute-force search
Average time complexity: O(n)
Aditya Kumar 20142028 Search Algorithms
scalescale
Linear Search
continued
Figure: Graphical illustration of linear search
Aditya Kumar 20142028 Search Algorithms
scalescale
Linear Search
Pseudocode
Using Iteration
Require: list a, size of list n, desired item x
for i=0 to n-1 do
if a[i]=x then
return i
end if
i=i+1
end for
if i=n then
return false
end if
Aditya Kumar 20142028 Search Algorithms
scalescale
Linear Search
Pseudocode
Using Recursion
LinearSearch(list, size, value)
if size=0 then
return false
else if first item of list=value then
return location of first item
else
return LinearSearch(list, remaining size, value)
end if
Aditya Kumar 20142028 Search Algorithms
scalescale
Linear Search
Advantages and Disadvantages
Advantages
Easiest to understand and implement
No sorting required
Suitable for small list sizes
Aditya Kumar 20142028 Search Algorithms
scalescale
Linear Search
Advantages and Disadvantages
Advantages
Easiest to understand and implement
No sorting required
Suitable for small list sizes
Disadvantages
Time inefficient as compared to other algorithms
Not suitable for large-sized lists
Aditya Kumar 20142028 Search Algorithms
scalescale
Binary Search
Binary search algorithm finds the position of a target
value within a sorted array
Aditya Kumar 20142028 Search Algorithms
scalescale
Binary Search
Binary search algorithm finds the position of a target
value within a sorted array
It can be classified as a divide-and-conquer search
algorithm
Average time complexity: O(log n)
Aditya Kumar 20142028 Search Algorithms
scalescale
Binary Search
Overview
The algorithm begins by comparing the target value to
the value of the middle element of the sorted array
Aditya Kumar 20142028 Search Algorithms
scalescale
Binary Search
Overview
The algorithm begins by comparing the target value to
the value of the middle element of the sorted array
If they are equal the middle position is returned and the
search is finished
Aditya Kumar 20142028 Search Algorithms
scalescale
Binary Search
Overview
The algorithm begins by comparing the target value to
the value of the middle element of the sorted array
If they are equal the middle position is returned and the
search is finished
If the target value is less than the middle element’s value,
then the search continues on the lower half of the array;
or if the target value is greater than the middle element’s
value, then the search continues on the upper half of the
array
Aditya Kumar 20142028 Search Algorithms
scalescale
Binary Search
Overview
The algorithm begins by comparing the target value to
the value of the middle element of the sorted array
If they are equal the middle position is returned and the
search is finished
If the target value is less than the middle element’s value,
then the search continues on the lower half of the array;
or if the target value is greater than the middle element’s
value, then the search continues on the upper half of the
array
This process continues, eliminating half of the elements
until the value is found or the array is exhausted
Aditya Kumar 20142028 Search Algorithms
scalescale
Binary Search
continued
Figure: Graphical illustration of binary search
Aditya Kumar 20142028 Search Algorithms
scalescale
Binary Search
Pseudocode (using recursion)
BinarySearch(list[], min, max, key)
if max <min then
return false
else
mid = (max+min) / 2
if list[mid] >key then
return BinarySearch(list[], min, mid-1, key)
else if list[mid] <key then
return BinarySearch(list[], mid+1, max, key)
else
return mid
end if
end if
Aditya Kumar 20142028 Search Algorithms
scalescale
Binary Search
Pseudocode (using iteration)
BinarySearch(list[], min, max, key)
while min ≤ max do
mid = (max+min) / 2
if list[mid] >key then
max = mid-1
else if list[mid] <key then
min = mid+1
else
return mid
end if
end while
return false
Aditya Kumar 20142028 Search Algorithms
scalescale
Binary Search
Performance
With each test that fails to find a match, the search is
continued with one or other of the two sub-intervals, each
at most half the size
Aditya Kumar 20142028 Search Algorithms
scalescale
Binary Search
Performance
With each test that fails to find a match, the search is
continued with one or other of the two sub-intervals, each
at most half the size
If the original number of items is N then after the first
iteration there will be at most N/2 items remaining, then
at most N/4 items, and so on
Aditya Kumar 20142028 Search Algorithms
scalescale
Binary Search
Performance
With each test that fails to find a match, the search is
continued with one or other of the two sub-intervals, each
at most half the size
If the original number of items is N then after the first
iteration there will be at most N/2 items remaining, then
at most N/4 items, and so on
In the worst case, when the value is not in the list, the
algorithm must continue iterating until the list is empty;
this take at most floor(log2 N + 1) iterations, where
floor() rounds down its argument to an integer
Aditya Kumar 20142028 Search Algorithms
scalescale
Binary Search
Performance
With each test that fails to find a match, the search is
continued with one or other of the two sub-intervals, each
at most half the size
If the original number of items is N then after the first
iteration there will be at most N/2 items remaining, then
at most N/4 items, and so on
In the worst case, when the value is not in the list, the
algorithm must continue iterating until the list is empty;
this take at most floor(log2 N + 1) iterations, where
floor() rounds down its argument to an integer
Thus binary search runs in logarithmic time
Aditya Kumar 20142028 Search Algorithms
scalescale
Binary Search
Advantages and Disadvantages
Advantages
Excellent time efficiency
Suitable for large list sizes
Aditya Kumar 20142028 Search Algorithms
scalescale
Binary Search
Advantages and Disadvantages
Advantages
Excellent time efficiency
Suitable for large list sizes
Disadvantages
Can only be implemented on a sorted array
Not suitable for small sizes, where linear search would be
faster, as sorting takes up a considerable amount of time
Aditya Kumar 20142028 Search Algorithms
scalescale
Binary Search
Language Support
Many standard libraries provide a way to do a binary search:
C provides bsearch() in its standard library
C++’s STL provides the functions binary search(),
lower bound() and upper bound()
Java offers a set of overloaded binarySearch() static
methods in the class Arrays in the standard java.util
package for performing binary searches on Java arrays
Python provides the bisect module
Aditya Kumar 20142028 Search Algorithms
scalescale
End
Thank you
Aditya Kumar 20142028 Search Algorithms

More Related Content

What's hot

searching
searchingsearching
searching
A. S. M. Shafi
 
Binary search python
Binary search pythonBinary search python
Binary search python
MaryamAnwar10
 
Searching algorithm
Searching algorithmSearching algorithm
Searching algorithm
MG Thushara Pradeesh
 
Binary search
Binary searchBinary search
Binary search
sana younas
 
Algorithm and Programming (Searching)
Algorithm and Programming (Searching)Algorithm and Programming (Searching)
Algorithm and Programming (Searching)
Adam Mukharil Bachtiar
 
Dsa – data structure and algorithms sorting
Dsa – data structure and algorithms  sortingDsa – data structure and algorithms  sorting
Dsa – data structure and algorithms sorting
sajinis3
 
Searching
SearchingSearching
Searching
Ashim Lamichhane
 
Rahat &amp; juhith
Rahat &amp; juhithRahat &amp; juhith
Rahat &amp; juhith
Rj Juhith
 
Data operatons & searching and sorting algorithms
Data operatons & searching and sorting algorithmsData operatons & searching and sorting algorithms
Data operatons & searching and sorting algorithms
Anushdika Jeganathan
 
Binary search
Binary searchBinary search
Binary search
AparnaKumari31
 
Searching linear &amp; binary search
Searching linear &amp; binary searchSearching linear &amp; binary search
Searching linear &amp; binary search
nikunjandy
 
Binary Search
Binary SearchBinary Search
Binary Search
kunj desai
 
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
 
Sequential & binary, linear search
Sequential & binary, linear searchSequential & binary, linear search
Sequential & binary, linear search
montazur420
 
Search methods
Search methodsSearch methods
Search methods
zahraa F.Muhsen
 
Standard algorithms
Standard algorithmsStandard algorithms
Standard algorithms
missstevenson01
 
Dsa – data structure and algorithms searching
Dsa – data structure and algorithms   searchingDsa – data structure and algorithms   searching
Dsa – data structure and algorithms searching
sajinis3
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 

What's hot (20)

searching
searchingsearching
searching
 
Binary search python
Binary search pythonBinary search python
Binary search python
 
Searching algorithm
Searching algorithmSearching algorithm
Searching algorithm
 
Binary search
Binary searchBinary search
Binary search
 
Algorithm and Programming (Searching)
Algorithm and Programming (Searching)Algorithm and Programming (Searching)
Algorithm and Programming (Searching)
 
Dsa – data structure and algorithms sorting
Dsa – data structure and algorithms  sortingDsa – data structure and algorithms  sorting
Dsa – data structure and algorithms sorting
 
Searching
SearchingSearching
Searching
 
Rahat &amp; juhith
Rahat &amp; juhithRahat &amp; juhith
Rahat &amp; juhith
 
Data operatons & searching and sorting algorithms
Data operatons & searching and sorting algorithmsData operatons & searching and sorting algorithms
Data operatons & searching and sorting algorithms
 
Binary search
Binary searchBinary search
Binary search
 
Searching linear &amp; binary search
Searching linear &amp; binary searchSearching linear &amp; binary search
Searching linear &amp; binary search
 
L10 sorting-searching
L10 sorting-searchingL10 sorting-searching
L10 sorting-searching
 
Binary Search
Binary SearchBinary Search
Binary Search
 
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
 
Sequential & binary, linear search
Sequential & binary, linear searchSequential & binary, linear search
Sequential & binary, linear search
 
Search methods
Search methodsSearch methods
Search methods
 
Standard algorithms
Standard algorithmsStandard algorithms
Standard algorithms
 
Dsa – data structure and algorithms searching
Dsa – data structure and algorithms   searchingDsa – data structure and algorithms   searching
Dsa – data structure and algorithms searching
 
Chap10
Chap10Chap10
Chap10
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
 

Viewers also liked

Plenary Speaker slides at the 2016 International Workshop on Biodesign Automa...
Plenary Speaker slides at the 2016 International Workshop on Biodesign Automa...Plenary Speaker slides at the 2016 International Workshop on Biodesign Automa...
Plenary Speaker slides at the 2016 International Workshop on Biodesign Automa...
Natalio Krasnogor
 
Elementary Landscape Decomposition of Combinatorial Optimization Problems
Elementary Landscape Decomposition of Combinatorial Optimization ProblemsElementary Landscape Decomposition of Combinatorial Optimization Problems
Elementary Landscape Decomposition of Combinatorial Optimization Problems
jfrchicanog
 
Paper introduction to Combinatorial Optimization on Graphs of Bounded Treewidth
Paper introduction to Combinatorial Optimization on Graphs of Bounded TreewidthPaper introduction to Combinatorial Optimization on Graphs of Bounded Treewidth
Paper introduction to Combinatorial Optimization on Graphs of Bounded Treewidth
Yu Liu
 
DENSA:An effective negative selection algorithm with flexible boundaries for ...
DENSA:An effective negative selection algorithm with flexible boundaries for ...DENSA:An effective negative selection algorithm with flexible boundaries for ...
DENSA:An effective negative selection algorithm with flexible boundaries for ...
Mario Pavone
 
Local search algorithms
Local search algorithmsLocal search algorithms
Local search algorithms
bambangsueb
 
Search algorithms for discrete optimization
Search algorithms for discrete optimizationSearch algorithms for discrete optimization
Search algorithms for discrete optimization
Sally Salem
 
Data structures question paper anna university
Data structures question paper anna universityData structures question paper anna university
Data structures question paper anna universitysangeethajames07
 
2 lectures 16 17-informed search algorithms ch 4.3
2 lectures 16 17-informed search algorithms ch 4.32 lectures 16 17-informed search algorithms ch 4.3
2 lectures 16 17-informed search algorithms ch 4.3Ravi Balout
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
Julie Iskander
 
Linear Search & Binary Search
Linear Search & Binary SearchLinear Search & Binary Search
Linear Search & Binary Search
Reem Alattas
 
Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithm
NeoClassical
 
Chemical Reactions
Chemical ReactionsChemical Reactions
Chemical Reactionsmatcol
 
Data Structure
Data StructureData Structure
Data Structure
Karthikeyan A K
 
The Search Landscape in 2017
The Search Landscape in 2017The Search Landscape in 2017
The Search Landscape in 2017
Rand Fishkin
 
Landscape Design and Principles
Landscape Design and PrinciplesLandscape Design and Principles
Landscape Design and Principles
Catherine Patterson
 

Viewers also liked (17)

DISMATH_Part2
DISMATH_Part2DISMATH_Part2
DISMATH_Part2
 
Plenary Speaker slides at the 2016 International Workshop on Biodesign Automa...
Plenary Speaker slides at the 2016 International Workshop on Biodesign Automa...Plenary Speaker slides at the 2016 International Workshop on Biodesign Automa...
Plenary Speaker slides at the 2016 International Workshop on Biodesign Automa...
 
Elementary Landscape Decomposition of Combinatorial Optimization Problems
Elementary Landscape Decomposition of Combinatorial Optimization ProblemsElementary Landscape Decomposition of Combinatorial Optimization Problems
Elementary Landscape Decomposition of Combinatorial Optimization Problems
 
Paper introduction to Combinatorial Optimization on Graphs of Bounded Treewidth
Paper introduction to Combinatorial Optimization on Graphs of Bounded TreewidthPaper introduction to Combinatorial Optimization on Graphs of Bounded Treewidth
Paper introduction to Combinatorial Optimization on Graphs of Bounded Treewidth
 
DENSA:An effective negative selection algorithm with flexible boundaries for ...
DENSA:An effective negative selection algorithm with flexible boundaries for ...DENSA:An effective negative selection algorithm with flexible boundaries for ...
DENSA:An effective negative selection algorithm with flexible boundaries for ...
 
Local search algorithms
Local search algorithmsLocal search algorithms
Local search algorithms
 
Search algorithms for discrete optimization
Search algorithms for discrete optimizationSearch algorithms for discrete optimization
Search algorithms for discrete optimization
 
DISMATH_Intro_Admin
DISMATH_Intro_AdminDISMATH_Intro_Admin
DISMATH_Intro_Admin
 
Data structures question paper anna university
Data structures question paper anna universityData structures question paper anna university
Data structures question paper anna university
 
2 lectures 16 17-informed search algorithms ch 4.3
2 lectures 16 17-informed search algorithms ch 4.32 lectures 16 17-informed search algorithms ch 4.3
2 lectures 16 17-informed search algorithms ch 4.3
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Linear Search & Binary Search
Linear Search & Binary SearchLinear Search & Binary Search
Linear Search & Binary Search
 
Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithm
 
Chemical Reactions
Chemical ReactionsChemical Reactions
Chemical Reactions
 
Data Structure
Data StructureData Structure
Data Structure
 
The Search Landscape in 2017
The Search Landscape in 2017The Search Landscape in 2017
The Search Landscape in 2017
 
Landscape Design and Principles
Landscape Design and PrinciplesLandscape Design and Principles
Landscape Design and Principles
 

Similar to Search Algprithms

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
 
Unit iv(dsc++)
Unit iv(dsc++)Unit iv(dsc++)
Unit iv(dsc++)
Durga Devi
 
Searching_Sorting.pptx
Searching_Sorting.pptxSearching_Sorting.pptx
Searching_Sorting.pptx
21BD1A058RSahithi
 
Unit 6 dsa SEARCHING AND SORTING
Unit 6 dsa SEARCHING AND SORTINGUnit 6 dsa SEARCHING AND SORTING
Data structure unit I part B
Data structure unit I part BData structure unit I part B
Data structure unit I part B
SSN College of Engineering, Kalavakkam
 
Algorithm and Data Structure - Linear Search
Algorithm and Data Structure - Linear SearchAlgorithm and Data Structure - Linear Search
Algorithm and Data Structure - Linear Search
AndiNurkholis1
 
ODD EVEN BASED BINARY SEARCH
ODD EVEN BASED BINARY SEARCHODD EVEN BASED BINARY SEARCH
ODD EVEN BASED BINARY SEARCH
IAEME Publication
 
Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms
Trupti Agrawal
 
Searching and Sorting Unit II Part I.pptx
Searching and Sorting Unit II Part I.pptxSearching and Sorting Unit II Part I.pptx
Searching and Sorting Unit II Part I.pptx
Dr. Madhuri Jawale
 
Searching and Sorting Algorithms in Data Structures
Searching and Sorting Algorithms  in Data StructuresSearching and Sorting Algorithms  in Data Structures
Searching and Sorting Algorithms in Data Structures
poongothai11
 
Searching
SearchingSearching
Searching
A. S. M. Shafi
 
DSA Lec 5+6(Search+Sort) (1).pdf
DSA Lec 5+6(Search+Sort) (1).pdfDSA Lec 5+6(Search+Sort) (1).pdf
DSA Lec 5+6(Search+Sort) (1).pdf
MustafaJutt4
 
Searching in DSA that follow a dsa searching.pptx
Searching in DSA that follow a dsa searching.pptxSearching in DSA that follow a dsa searching.pptx
Searching in DSA that follow a dsa searching.pptx
StephenRobert15
 
1 class linear and Binary search (3).ppt
1 class linear and Binary search (3).ppt1 class linear and Binary search (3).ppt
1 class linear and Binary search (3).ppt
KanchanRaut13
 
Chapter3.pptx
Chapter3.pptxChapter3.pptx
Chapter3.pptx
ASMAALWADEE2
 
Analysis of Algorithm - Binary Search.pptx
Analysis of Algorithm - Binary Search.pptxAnalysis of Algorithm - Binary Search.pptx
Analysis of Algorithm - Binary Search.pptx
Maulana Abul Kalam Azad University of Technology
 
GRID SEARCHING Novel way of Searching 2D Array
GRID SEARCHING Novel way of Searching 2D ArrayGRID SEARCHING Novel way of Searching 2D Array
GRID SEARCHING Novel way of Searching 2D Array
Editor IJCATR
 
Searching Sorting
Searching SortingSearching Sorting
Searching Sortingguest2cb109
 

Similar to Search Algprithms (20)

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
 
9 Arrays
9 Arrays9 Arrays
9 Arrays
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
 
Unit iv(dsc++)
Unit iv(dsc++)Unit iv(dsc++)
Unit iv(dsc++)
 
Searching_Sorting.pptx
Searching_Sorting.pptxSearching_Sorting.pptx
Searching_Sorting.pptx
 
Unit 6 dsa SEARCHING AND SORTING
Unit 6 dsa SEARCHING AND SORTINGUnit 6 dsa SEARCHING AND SORTING
Unit 6 dsa SEARCHING AND SORTING
 
Data structure unit I part B
Data structure unit I part BData structure unit I part B
Data structure unit I part B
 
Algorithm and Data Structure - Linear Search
Algorithm and Data Structure - Linear SearchAlgorithm and Data Structure - Linear Search
Algorithm and Data Structure - Linear Search
 
ODD EVEN BASED BINARY SEARCH
ODD EVEN BASED BINARY SEARCHODD EVEN BASED BINARY SEARCH
ODD EVEN BASED BINARY SEARCH
 
Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms
 
Searching and Sorting Unit II Part I.pptx
Searching and Sorting Unit II Part I.pptxSearching and Sorting Unit II Part I.pptx
Searching and Sorting Unit II Part I.pptx
 
Searching and Sorting Algorithms in Data Structures
Searching and Sorting Algorithms  in Data StructuresSearching and Sorting Algorithms  in Data Structures
Searching and Sorting Algorithms in Data Structures
 
Searching
SearchingSearching
Searching
 
DSA Lec 5+6(Search+Sort) (1).pdf
DSA Lec 5+6(Search+Sort) (1).pdfDSA Lec 5+6(Search+Sort) (1).pdf
DSA Lec 5+6(Search+Sort) (1).pdf
 
Searching in DSA that follow a dsa searching.pptx
Searching in DSA that follow a dsa searching.pptxSearching in DSA that follow a dsa searching.pptx
Searching in DSA that follow a dsa searching.pptx
 
1 class linear and Binary search (3).ppt
1 class linear and Binary search (3).ppt1 class linear and Binary search (3).ppt
1 class linear and Binary search (3).ppt
 
Chapter3.pptx
Chapter3.pptxChapter3.pptx
Chapter3.pptx
 
Analysis of Algorithm - Binary Search.pptx
Analysis of Algorithm - Binary Search.pptxAnalysis of Algorithm - Binary Search.pptx
Analysis of Algorithm - Binary Search.pptx
 
GRID SEARCHING Novel way of Searching 2D Array
GRID SEARCHING Novel way of Searching 2D ArrayGRID SEARCHING Novel way of Searching 2D Array
GRID SEARCHING Novel way of Searching 2D Array
 
Searching Sorting
Searching SortingSearching Sorting
Searching Sorting
 

More from Shivam Singh

Stacks
StacksStacks
Stacks
Shivam Singh
 
Trees
TreesTrees
What If Microsoft sold diapers!? MS Diapers!
What If Microsoft sold diapers!? MS Diapers!What If Microsoft sold diapers!? MS Diapers!
What If Microsoft sold diapers!? MS Diapers!
Shivam Singh
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
Shivam Singh
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
Shivam Singh
 
Linked List
Linked ListLinked List
Linked List
Shivam Singh
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
Shivam Singh
 

More from Shivam Singh (7)

Stacks
StacksStacks
Stacks
 
Trees
TreesTrees
Trees
 
What If Microsoft sold diapers!? MS Diapers!
What If Microsoft sold diapers!? MS Diapers!What If Microsoft sold diapers!? MS Diapers!
What If Microsoft sold diapers!? MS Diapers!
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Graph Theory
Graph TheoryGraph Theory
Graph Theory
 
Linked List
Linked ListLinked List
Linked List
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 

Recently uploaded

Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
Kamal Acharya
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
nooriasukmaningtyas
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
obonagu
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Sreedhar Chowdam
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
Self-Control of Emotions by Slidesgo.pptx
Self-Control of Emotions by Slidesgo.pptxSelf-Control of Emotions by Slidesgo.pptx
Self-Control of Emotions by Slidesgo.pptx
iemerc2024
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
yokeleetan1
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
Aditya Rajan Patra
 
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptxTOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
nikitacareer3
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
NidhalKahouli2
 
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.pptPROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
bhadouriyakaku
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
Divyam548318
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
aqil azizi
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
MIGUELANGEL966976
 

Recently uploaded (20)

Water billing management system project report.pdf
Water billing management system project report.pdfWater billing management system project report.pdf
Water billing management system project report.pdf
 
A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...A review on techniques and modelling methodologies used for checking electrom...
A review on techniques and modelling methodologies used for checking electrom...
 
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
原版制作(unimelb毕业证书)墨尔本大学毕业证Offer一模一样
 
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&BDesign and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
Design and Analysis of Algorithms-DP,Backtracking,Graphs,B&B
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
Self-Control of Emotions by Slidesgo.pptx
Self-Control of Emotions by Slidesgo.pptxSelf-Control of Emotions by Slidesgo.pptx
Self-Control of Emotions by Slidesgo.pptx
 
Swimming pool mechanical components design.pptx
Swimming pool  mechanical components design.pptxSwimming pool  mechanical components design.pptx
Swimming pool mechanical components design.pptx
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Recycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part IIIRecycled Concrete Aggregate in Construction Part III
Recycled Concrete Aggregate in Construction Part III
 
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptxTOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
TOP 10 B TECH COLLEGES IN JAIPUR 2024.pptx
 
basic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdfbasic-wireline-operations-course-mahmoud-f-radwan.pdf
basic-wireline-operations-course-mahmoud-f-radwan.pdf
 
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.pptPROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
PROJECT FORMAT FOR EVS AMITY UNIVERSITY GWALIOR.ppt
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
 
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdfTutorial for 16S rRNA Gene Analysis with QIIME2.pdf
Tutorial for 16S rRNA Gene Analysis with QIIME2.pdf
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdfBPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
BPV-GUI-01-Guide-for-ASME-Review-Teams-(General)-10-10-2023.pdf
 

Search Algprithms

  • 1. scalescale Search Algorithms Technical Writing(CS1305) Assignment Aditya Kumar 20142028 MNNIT Allahabad August 2015 Aditya Kumar 20142028 Search Algorithms
  • 2. scalescale Introduction In computer science, a search algorithm is an algorithm for finding an item with specified properties among a collection of items which are coded into a computer program. The program then looks for clues to give us back exactly what we want. Aditya Kumar 20142028 Search Algorithms
  • 3. scalescale Introduction In computer science, a search algorithm is an algorithm for finding an item with specified properties among a collection of items which are coded into a computer program. The program then looks for clues to give us back exactly what we want. We are going to cover two search algoritms in this presentation: linear and binary. Aditya Kumar 20142028 Search Algorithms
  • 4. scalescale Linear Search Linear search is a method for finding a particular value in a list that checks each element in sequence until the desired element is found or the list is exhausted Aditya Kumar 20142028 Search Algorithms
  • 5. scalescale Linear Search Linear search is a method for finding a particular value in a list that checks each element in sequence until the desired element is found or the list is exhausted It is the simplest search algorithm A special case of brute-force search Average time complexity: O(n) Aditya Kumar 20142028 Search Algorithms
  • 6. scalescale Linear Search continued Figure: Graphical illustration of linear search Aditya Kumar 20142028 Search Algorithms
  • 7. scalescale Linear Search Pseudocode Using Iteration Require: list a, size of list n, desired item x for i=0 to n-1 do if a[i]=x then return i end if i=i+1 end for if i=n then return false end if Aditya Kumar 20142028 Search Algorithms
  • 8. scalescale Linear Search Pseudocode Using Recursion LinearSearch(list, size, value) if size=0 then return false else if first item of list=value then return location of first item else return LinearSearch(list, remaining size, value) end if Aditya Kumar 20142028 Search Algorithms
  • 9. scalescale Linear Search Advantages and Disadvantages Advantages Easiest to understand and implement No sorting required Suitable for small list sizes Aditya Kumar 20142028 Search Algorithms
  • 10. scalescale Linear Search Advantages and Disadvantages Advantages Easiest to understand and implement No sorting required Suitable for small list sizes Disadvantages Time inefficient as compared to other algorithms Not suitable for large-sized lists Aditya Kumar 20142028 Search Algorithms
  • 11. scalescale Binary Search Binary search algorithm finds the position of a target value within a sorted array Aditya Kumar 20142028 Search Algorithms
  • 12. scalescale Binary Search Binary search algorithm finds the position of a target value within a sorted array It can be classified as a divide-and-conquer search algorithm Average time complexity: O(log n) Aditya Kumar 20142028 Search Algorithms
  • 13. scalescale Binary Search Overview The algorithm begins by comparing the target value to the value of the middle element of the sorted array Aditya Kumar 20142028 Search Algorithms
  • 14. scalescale Binary Search Overview The algorithm begins by comparing the target value to the value of the middle element of the sorted array If they are equal the middle position is returned and the search is finished Aditya Kumar 20142028 Search Algorithms
  • 15. scalescale Binary Search Overview The algorithm begins by comparing the target value to the value of the middle element of the sorted array If they are equal the middle position is returned and the search is finished If the target value is less than the middle element’s value, then the search continues on the lower half of the array; or if the target value is greater than the middle element’s value, then the search continues on the upper half of the array Aditya Kumar 20142028 Search Algorithms
  • 16. scalescale Binary Search Overview The algorithm begins by comparing the target value to the value of the middle element of the sorted array If they are equal the middle position is returned and the search is finished If the target value is less than the middle element’s value, then the search continues on the lower half of the array; or if the target value is greater than the middle element’s value, then the search continues on the upper half of the array This process continues, eliminating half of the elements until the value is found or the array is exhausted Aditya Kumar 20142028 Search Algorithms
  • 17. scalescale Binary Search continued Figure: Graphical illustration of binary search Aditya Kumar 20142028 Search Algorithms
  • 18. scalescale Binary Search Pseudocode (using recursion) BinarySearch(list[], min, max, key) if max <min then return false else mid = (max+min) / 2 if list[mid] >key then return BinarySearch(list[], min, mid-1, key) else if list[mid] <key then return BinarySearch(list[], mid+1, max, key) else return mid end if end if Aditya Kumar 20142028 Search Algorithms
  • 19. scalescale Binary Search Pseudocode (using iteration) BinarySearch(list[], min, max, key) while min ≤ max do mid = (max+min) / 2 if list[mid] >key then max = mid-1 else if list[mid] <key then min = mid+1 else return mid end if end while return false Aditya Kumar 20142028 Search Algorithms
  • 20. scalescale Binary Search Performance With each test that fails to find a match, the search is continued with one or other of the two sub-intervals, each at most half the size Aditya Kumar 20142028 Search Algorithms
  • 21. scalescale Binary Search Performance With each test that fails to find a match, the search is continued with one or other of the two sub-intervals, each at most half the size If the original number of items is N then after the first iteration there will be at most N/2 items remaining, then at most N/4 items, and so on Aditya Kumar 20142028 Search Algorithms
  • 22. scalescale Binary Search Performance With each test that fails to find a match, the search is continued with one or other of the two sub-intervals, each at most half the size If the original number of items is N then after the first iteration there will be at most N/2 items remaining, then at most N/4 items, and so on In the worst case, when the value is not in the list, the algorithm must continue iterating until the list is empty; this take at most floor(log2 N + 1) iterations, where floor() rounds down its argument to an integer Aditya Kumar 20142028 Search Algorithms
  • 23. scalescale Binary Search Performance With each test that fails to find a match, the search is continued with one or other of the two sub-intervals, each at most half the size If the original number of items is N then after the first iteration there will be at most N/2 items remaining, then at most N/4 items, and so on In the worst case, when the value is not in the list, the algorithm must continue iterating until the list is empty; this take at most floor(log2 N + 1) iterations, where floor() rounds down its argument to an integer Thus binary search runs in logarithmic time Aditya Kumar 20142028 Search Algorithms
  • 24. scalescale Binary Search Advantages and Disadvantages Advantages Excellent time efficiency Suitable for large list sizes Aditya Kumar 20142028 Search Algorithms
  • 25. scalescale Binary Search Advantages and Disadvantages Advantages Excellent time efficiency Suitable for large list sizes Disadvantages Can only be implemented on a sorted array Not suitable for small sizes, where linear search would be faster, as sorting takes up a considerable amount of time Aditya Kumar 20142028 Search Algorithms
  • 26. scalescale Binary Search Language Support Many standard libraries provide a way to do a binary search: C provides bsearch() in its standard library C++’s STL provides the functions binary search(), lower bound() and upper bound() Java offers a set of overloaded binarySearch() static methods in the class Arrays in the standard java.util package for performing binary searches on Java arrays Python provides the bisect module Aditya Kumar 20142028 Search Algorithms
  • 27. scalescale End Thank you Aditya Kumar 20142028 Search Algorithms