SlideShare a Scribd company logo
1 of 14
Akash A. Borse
M.Tech (ACDS)
PRN: 170847980005
17/02/2018
WHAT IS “SEARCHING” IN DATA
STRUCTURES?
 It is a process of finding/ efficient retrieval of a specific
data item from a set of data (Ordered / Un-Ordered)
 E.g. – Finding a specific record from database.
SEARCHING ALGORITHMS
 Linear Search
 Binary Search
LINEAR SEARCH
 Simplest Algorithm.
 Search item is compared with each item in data set
sequentially till match is found.
ALGORITHM FOR LINEAR SEARCH
for (each item in list)
{
compare search term to current item
if match,
save index of matching item
break
}
return index of matching item, or -1 if item not found
PERFORMANCE ANALYSIS OF LINEAR SEARCH
 Best case: Occurs when the search term is in the first
slot in the array.
 (Number of comparisons: 1)
 Worst case: Occurs when the search term is in the last
slot in the array, or is not in the array.
 (Number of comparisons: N)
 Average case: Occurs when the search term will be
somewhere in the middle of the array.
 (Number of comparisons: Approximately N/2)
BINARY SEARCH
 Finds position of target data within a sorted list of data.
 It compares search item with mid item in data set, if it is
small then it looks in left subset otherwise in right
subset. It is repeated until subset reduces to 0.
ALGORITHM FOR BINARY SEARCH
set first = 1, last = N, mid = N/2
while (item not found and first < last)
{
compare search term to item at mid
if match
save index
break
else if search term is less than item at mid,
set last = mid-1
else
set first = mid+1
set mid = (first+last)/2
}
return index of matching item, or -1 if not found
PERFORMANCE ANALYSIS OF BINARY SEARCH
 Best case: Occurs when the search term is in the middle
slot in the array.
 (Number of comparisons: 1)
 Worst case: Occurs when the search term is in the
first/last slot in the array, or away from middle slot or is
not in the array.
 (Number of comparisons: Log N)
 Average case: Occurs when the search term will be
anywhere in the array.
 (Number of comparisons: Almost same as Worst case i.e. Log
N)
Example
Analysis of Various Searching &
Sorting Algorithms
Source: Hackerearth.com
Conclusion
• Binary Search requires input data to be sorted,
Linear Search doesn’t.
• Binary Search has complexity O(Log N); Linear
Search has complexity O(N).
• Binary Search Requires Random access of
data; Linear Search requires Sequential access
of data.
References
•Searching and Sorting Algorithms
(By Amy Csizmar Dalal)
•Searching Techniques: Binary Search
(By Nor Bahiah Hj Ahmad & Dayang Norhayati A. Jawawi)
Searching Techniques and Analysis

More Related Content

What's hot

SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSGokul Hari
 
Rahat &amp; juhith
Rahat &amp; juhithRahat &amp; juhith
Rahat &amp; juhithRj Juhith
 
Sequential & binary, linear search
Sequential & binary, linear searchSequential & binary, linear search
Sequential & binary, linear searchmontazur420
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data StructureMeghaj Mallick
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...Umesh Kumar
 
Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithmNeoClassical
 
Algorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsAlgorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsMohamed Loey
 
trees in data structure
trees in data structure trees in data structure
trees in data structure shameen khan
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data StructuresSHAKOOR AB
 
Dsa – data structure and algorithms searching
Dsa – data structure and algorithms   searchingDsa – data structure and algorithms   searching
Dsa – data structure and algorithms searchingsajinis3
 
Linear Search Data Structure
Linear Search Data StructureLinear Search Data Structure
Linear Search Data StructureTalha Shaikh
 
Bubble Sort Algorithm Presentation
Bubble Sort Algorithm Presentation Bubble Sort Algorithm Presentation
Bubble Sort Algorithm Presentation AhmedAlbutty
 
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 JYOTHISowmya Jyothi
 

What's hot (20)

Binary search
Binary searchBinary search
Binary search
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMSSEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
 
Rahat &amp; juhith
Rahat &amp; juhithRahat &amp; juhith
Rahat &amp; juhith
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Sequential & binary, linear search
Sequential & binary, linear searchSequential & binary, linear search
Sequential & binary, linear search
 
Binary Tree in Data Structure
Binary Tree in Data StructureBinary Tree in Data Structure
Binary Tree in Data Structure
 
Searching
SearchingSearching
Searching
 
Heap sort
Heap sortHeap sort
Heap sort
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
 
Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithm
 
Algorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching AlgorithmsAlgorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching Algorithms
 
Binary search
Binary searchBinary search
Binary search
 
trees in data structure
trees in data structure trees in data structure
trees in data structure
 
Red black tree
Red black treeRed black tree
Red black tree
 
Hashing Technique In Data Structures
Hashing Technique In Data StructuresHashing Technique In Data Structures
Hashing Technique In Data Structures
 
Dsa – data structure and algorithms searching
Dsa – data structure and algorithms   searchingDsa – data structure and algorithms   searching
Dsa – data structure and algorithms searching
 
Linear Search Data Structure
Linear Search Data StructureLinear Search Data Structure
Linear Search Data Structure
 
Bubble Sort Algorithm Presentation
Bubble Sort Algorithm Presentation Bubble Sort Algorithm Presentation
Bubble Sort Algorithm Presentation
 
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
 

Similar to Searching Techniques and Analysis

Similar to Searching Techniques and Analysis (20)

Algorithm 8th lecture linear & binary search(2).pptx
Algorithm 8th lecture linear & binary search(2).pptxAlgorithm 8th lecture linear & binary search(2).pptx
Algorithm 8th lecture linear & binary search(2).pptx
 
DS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptx
 
Data Structures_ Sorting & Searching
Data Structures_ Sorting & SearchingData Structures_ Sorting & Searching
Data Structures_ Sorting & Searching
 
4.1 sequentioal search
4.1 sequentioal search4.1 sequentioal search
4.1 sequentioal search
 
Binary search in ds
Binary search in dsBinary search in ds
Binary search in ds
 
Analysis of Algorithm - Binary Search.pptx
Analysis of Algorithm - Binary Search.pptxAnalysis of Algorithm - Binary Search.pptx
Analysis of Algorithm - Binary Search.pptx
 
SEARCHING
SEARCHINGSEARCHING
SEARCHING
 
Searching,sorting
Searching,sortingSearching,sorting
Searching,sorting
 
Searching algorithms
Searching algorithmsSearching algorithms
Searching algorithms
 
advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdf
 
Binary Search
Binary SearchBinary Search
Binary Search
 
27631722026_T._TAJESWAR_RAO_PCC-CS301_CSE(CS).pptx
27631722026_T._TAJESWAR_RAO_PCC-CS301_CSE(CS).pptx27631722026_T._TAJESWAR_RAO_PCC-CS301_CSE(CS).pptx
27631722026_T._TAJESWAR_RAO_PCC-CS301_CSE(CS).pptx
 
Linear Search
Linear SearchLinear Search
Linear Search
 
searching
searchingsearching
searching
 
Searching_Sorting.pptx
Searching_Sorting.pptxSearching_Sorting.pptx
Searching_Sorting.pptx
 
Searching techniques
Searching techniquesSearching techniques
Searching techniques
 
Searching and sorting by B kirron Reddi
Searching and sorting by B kirron ReddiSearching and sorting by B kirron Reddi
Searching and sorting by B kirron Reddi
 
Data Structures 8
Data Structures 8Data Structures 8
Data Structures 8
 
Unit v data structure-converted
Unit  v data structure-convertedUnit  v data structure-converted
Unit v data structure-converted
 
Data structure unit I part B
Data structure unit I part BData structure unit I part B
Data structure unit I part B
 

More from AkashBorse2

Underwater Cloud Storage
Underwater Cloud StorageUnderwater Cloud Storage
Underwater Cloud StorageAkashBorse2
 
Dynamic Data Visualization with Tableau
Dynamic Data Visualization with TableauDynamic Data Visualization with Tableau
Dynamic Data Visualization with TableauAkashBorse2
 
Association Rules in Machine Learning
Association Rules in Machine LearningAssociation Rules in Machine Learning
Association Rules in Machine LearningAkashBorse2
 
Application of Geographical concepts and Spatial Technology to the “Internet ...
Application of Geographical concepts and Spatial Technology to the “Internet ...Application of Geographical concepts and Spatial Technology to the “Internet ...
Application of Geographical concepts and Spatial Technology to the “Internet ...AkashBorse2
 
Presentation on Business Intelligence (BI)
Presentation on Business Intelligence (BI)Presentation on Business Intelligence (BI)
Presentation on Business Intelligence (BI)AkashBorse2
 
Seminar on Big data: A Big Tale of Facebook
Seminar on Big data: A Big Tale of FacebookSeminar on Big data: A Big Tale of Facebook
Seminar on Big data: A Big Tale of FacebookAkashBorse2
 
Advanced Databases: Introduction to NoSQL, Big Data and Google's Big Table
Advanced Databases: Introduction to NoSQL, Big Data and Google's Big TableAdvanced Databases: Introduction to NoSQL, Big Data and Google's Big Table
Advanced Databases: Introduction to NoSQL, Big Data and Google's Big TableAkashBorse2
 

More from AkashBorse2 (7)

Underwater Cloud Storage
Underwater Cloud StorageUnderwater Cloud Storage
Underwater Cloud Storage
 
Dynamic Data Visualization with Tableau
Dynamic Data Visualization with TableauDynamic Data Visualization with Tableau
Dynamic Data Visualization with Tableau
 
Association Rules in Machine Learning
Association Rules in Machine LearningAssociation Rules in Machine Learning
Association Rules in Machine Learning
 
Application of Geographical concepts and Spatial Technology to the “Internet ...
Application of Geographical concepts and Spatial Technology to the “Internet ...Application of Geographical concepts and Spatial Technology to the “Internet ...
Application of Geographical concepts and Spatial Technology to the “Internet ...
 
Presentation on Business Intelligence (BI)
Presentation on Business Intelligence (BI)Presentation on Business Intelligence (BI)
Presentation on Business Intelligence (BI)
 
Seminar on Big data: A Big Tale of Facebook
Seminar on Big data: A Big Tale of FacebookSeminar on Big data: A Big Tale of Facebook
Seminar on Big data: A Big Tale of Facebook
 
Advanced Databases: Introduction to NoSQL, Big Data and Google's Big Table
Advanced Databases: Introduction to NoSQL, Big Data and Google's Big TableAdvanced Databases: Introduction to NoSQL, Big Data and Google's Big Table
Advanced Databases: Introduction to NoSQL, Big Data and Google's Big Table
 

Recently uploaded

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIShubhangi Sonawane
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesShubhangi Sonawane
 

Recently uploaded (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-IIFood Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
Food Chain and Food Web (Ecosystem) EVS, B. Pharmacy 1st Year, Sem-II
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 

Searching Techniques and Analysis

  • 1. Akash A. Borse M.Tech (ACDS) PRN: 170847980005 17/02/2018
  • 2. WHAT IS “SEARCHING” IN DATA STRUCTURES?  It is a process of finding/ efficient retrieval of a specific data item from a set of data (Ordered / Un-Ordered)  E.g. – Finding a specific record from database.
  • 3. SEARCHING ALGORITHMS  Linear Search  Binary Search
  • 4. LINEAR SEARCH  Simplest Algorithm.  Search item is compared with each item in data set sequentially till match is found.
  • 5. ALGORITHM FOR LINEAR SEARCH for (each item in list) { compare search term to current item if match, save index of matching item break } return index of matching item, or -1 if item not found
  • 6. PERFORMANCE ANALYSIS OF LINEAR SEARCH  Best case: Occurs when the search term is in the first slot in the array.  (Number of comparisons: 1)  Worst case: Occurs when the search term is in the last slot in the array, or is not in the array.  (Number of comparisons: N)  Average case: Occurs when the search term will be somewhere in the middle of the array.  (Number of comparisons: Approximately N/2)
  • 7. BINARY SEARCH  Finds position of target data within a sorted list of data.  It compares search item with mid item in data set, if it is small then it looks in left subset otherwise in right subset. It is repeated until subset reduces to 0.
  • 8. ALGORITHM FOR BINARY SEARCH set first = 1, last = N, mid = N/2 while (item not found and first < last) { compare search term to item at mid if match save index break else if search term is less than item at mid, set last = mid-1 else set first = mid+1 set mid = (first+last)/2 } return index of matching item, or -1 if not found
  • 9. PERFORMANCE ANALYSIS OF BINARY SEARCH  Best case: Occurs when the search term is in the middle slot in the array.  (Number of comparisons: 1)  Worst case: Occurs when the search term is in the first/last slot in the array, or away from middle slot or is not in the array.  (Number of comparisons: Log N)  Average case: Occurs when the search term will be anywhere in the array.  (Number of comparisons: Almost same as Worst case i.e. Log N)
  • 11. Analysis of Various Searching & Sorting Algorithms Source: Hackerearth.com
  • 12. Conclusion • Binary Search requires input data to be sorted, Linear Search doesn’t. • Binary Search has complexity O(Log N); Linear Search has complexity O(N). • Binary Search Requires Random access of data; Linear Search requires Sequential access of data.
  • 13. References •Searching and Sorting Algorithms (By Amy Csizmar Dalal) •Searching Techniques: Binary Search (By Nor Bahiah Hj Ahmad & Dayang Norhayati A. Jawawi)