SlideShare a Scribd company logo
2
What is searching?
 Searching is an operation or a technique that
helps finds the place of a given element or
value in the list. Any search is said to be
successful or unsuccessful depending upon
whether the element that is being searched is
found or not.
Most read
5
Linear Search Algorithm
 Linear Search ( Array A, Value 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
Most read
6
Binary search
Binary search is a fast search algorithm with run-time complexity of Ο(log n).
This search
algorithm works on the principle of divide and conquer. For this algorithm to
work properly,
the data collection should be in the sorted form.
Binary search looks for a particular item by comparing the middle most item of
the
collection. If a match occurs, then the index of item is returned. If the middle
item is
greater than the item, then the item is searched in the sub-array to the right of
the middle
item. Otherwise, the item is searched for in the sub-array to the left of the
middle item.
This process continues on the sub-array as well until the size of the subarray
reduces to
zero.
Most read
SEARCHING TECHNIQUES
DATA STRUCTURE AND
ANALYSIS
Instructor
Pir Syed M Ayaz Farid Shah
What is searching?
 Searching is an operation or a technique that
helps finds the place of a given element or
value in the list. Any search is said to be
successful or unsuccessful depending upon
whether the element that is being searched is
found or not.
Searching Techniques
There are tow types of searching in data
structure and analysis
 Linear Search
 Binary Search
 Interpolation Search
Linear Search
Linear search is a very simple search algorithm.
In this type of search, a sequential search
is made over all items one by one. Every item is
checked and if a match is found then that
particular item is returned, otherwise the search
continues till the end of the data
collection.
Linear Search Algorithm
 Linear Search ( Array A, Value 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
Binary search
Binary search is a fast search algorithm with run-time complexity of Ο(log n).
This search
algorithm works on the principle of divide and conquer. For this algorithm to
work properly,
the data collection should be in the sorted form.
Binary search looks for a particular item by comparing the middle most item of
the
collection. If a match occurs, then the index of item is returned. If the middle
item is
greater than the item, then the item is searched in the sub-array to the right of
the middle
item. Otherwise, the item is searched for in the sub-array to the left of the
middle item.
This process continues on the sub-array as well until the size of the subarray
reduces to
zero.
Binary Search Algorithm
 Compare x with the middle element.
 If x matches with middle element, we return
the mid index.
 Else If x is greater than the mid element, then
x can only lie in right half subarray after the
mid element. So we recur for right half.
 Else (x is smaller) recur for the left half.
Binary vs. Linear Search
•Input data needs to be sorted in Binary Search and not in Linear Search
•Linear search does the sequential access whereas Binary search access
data randomly.
•Time complexity of linear search -O(n) , Binary search has time complexity
O(log n).
• Linear search performs equality comparisons and Binary search performs
ordering comparisons
Interpolation Search
Interpolation search is an improved variant of binary
search. This search algorithm works on the probing
position of the required value. For this algorithm to work
properly, the data collection should be in a sorted form
and equally distributed.
Binary search has a huge advantage of time complexity
over linear search. Linear search has worst-case
complexity of Ο(n) whereas binary search has Ο(log n).
There are cases where the location of target data may
be known in advance. For example, in case of a
telephone directory, if we want to search the telephone
number of Morphius. Here, linear search and even
binary search will seem slow as we can directly jump to
memory space where the names start from 'M' are
stored.
Interpolation Search Algorithm
Step 1 − Start searching data from middle of the list.
Step 2 − If it is a match, return the index of the item, and exit.
Step 3 − If it is not a match, probe position.
Step 4 − Divide the list using probing formula and find the new midle.
Step 5 − If data is greater than middle, search in higher sub-list.
Step 6 − If data is smaller than middle, search in lower sub-list.
Step 7 − Repeat until match.
Binary vs. Interpolation Search
 Positioning in Binary Search
 Position Probing in Interpolation Search
???

More Related Content

What's hot (20)

Binary search
Binary searchBinary search
Binary search
AparnaKumari31
 
Bubble sort
Bubble sortBubble sort
Bubble sort
Manek Ar
 
Binary search in data structure
Binary search in data structureBinary search in data structure
Binary search in data structure
Meherul1234
 
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
 
Binary Search
Binary SearchBinary Search
Binary Search
kunj desai
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
Adam Mukharil Bachtiar
 
Selection sorting
Selection sortingSelection sorting
Selection sorting
Himanshu Kesharwani
 
Linear search-and-binary-search
Linear search-and-binary-searchLinear search-and-binary-search
Linear search-and-binary-search
International Islamic University
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
anooppjoseph
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
somendra kumar
 
Searching
SearchingSearching
Searching
Ashim Lamichhane
 
Searching and sorting
Searching  and sortingSearching  and sorting
Searching and sorting
PoojithaBollikonda
 
Data Structures : hashing (1)
Data Structures : hashing (1)Data Structures : hashing (1)
Data Structures : hashing (1)
Home
 
Linear Search Presentation
Linear Search PresentationLinear Search Presentation
Linear Search Presentation
Markajul Hasnain Alif
 
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
 
Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms I
Mohamed Loey
 
Linked list
Linked listLinked list
Linked list
KalaivaniKS1
 
Sorting
SortingSorting
Sorting
Ashim Lamichhane
 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
Poojith Chowdhary
 
Bubble sort
Bubble sortBubble sort
Bubble sort
Manek Ar
 
Binary search in data structure
Binary search in data structureBinary search in data structure
Binary search in data structure
Meherul1234
 
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
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
anooppjoseph
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
somendra kumar
 
Data Structures : hashing (1)
Data Structures : hashing (1)Data Structures : hashing (1)
Data Structures : hashing (1)
Home
 
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
 
Algorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms IAlgorithms Lecture 4: Sorting Algorithms I
Algorithms Lecture 4: Sorting Algorithms I
Mohamed Loey
 

Similar to Searching techniques in Data Structure And Algorithm (20)

seaching internal 2 ppt
seaching internal 2 pptseaching internal 2 ppt
seaching internal 2 ppt
SubhrasisBiswal1
 
Searching techniques
Searching techniquesSearching techniques
Searching techniques
Archana Burujwale
 
programming in C
programming in Cprogramming in C
programming in C
ADITHYAM19
 
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
 
Dsa – data structure and algorithms searching
Dsa – data structure and algorithms   searchingDsa – data structure and algorithms   searching
Dsa – data structure and algorithms searching
sajinis3
 
Lecture_Oct26.pptx
Lecture_Oct26.pptxLecture_Oct26.pptx
Lecture_Oct26.pptx
SylrizcinMarieManzo3
 
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
 
Binary search in ds
Binary search in dsBinary search in ds
Binary search in ds
chauhankapil
 
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
 
Data structure Unit - II Searching and Sorting.pptx
Data structure Unit - II Searching and Sorting.pptxData structure Unit - II Searching and Sorting.pptx
Data structure Unit - II Searching and Sorting.pptx
gavanisanjana
 
Binary search
Binary search Binary search
Binary search
Ramkrishna bhagat
 
advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdf
haramaya university
 
Linear search in ds
Linear search in dsLinear search in ds
Linear search in ds
chauhankapil
 
Searching,sorting
Searching,sortingSearching,sorting
Searching,sorting
LavanyaJ28
 
Data Structures Unit 2 FINAL presentation.pptx
Data Structures   Unit 2 FINAL presentation.pptxData Structures   Unit 2 FINAL presentation.pptx
Data Structures Unit 2 FINAL presentation.pptx
dilipd20
 
Presentation on Searching and Sorting in C language.pptx
Presentation on Searching and Sorting in C language.pptxPresentation on Searching and Sorting in C language.pptx
Presentation on Searching and Sorting in C language.pptx
Krishnanandmishra15
 
4.1 sequentioal search
4.1 sequentioal search4.1 sequentioal search
4.1 sequentioal search
Krish_ver2
 
Searching_Sorting.pptx
Searching_Sorting.pptxSearching_Sorting.pptx
Searching_Sorting.pptx
21BD1A058RSahithi
 
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
Aftabali702240
 
programming in C
programming in Cprogramming in C
programming in C
ADITHYAM19
 
Dsa – data structure and algorithms searching
Dsa – data structure and algorithms   searchingDsa – data structure and algorithms   searching
Dsa – data structure and algorithms searching
sajinis3
 
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
 
Binary search in ds
Binary search in dsBinary search in ds
Binary search in ds
chauhankapil
 
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
 
Data structure Unit - II Searching and Sorting.pptx
Data structure Unit - II Searching and Sorting.pptxData structure Unit - II Searching and Sorting.pptx
Data structure Unit - II Searching and Sorting.pptx
gavanisanjana
 
advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdf
haramaya university
 
Linear search in ds
Linear search in dsLinear search in ds
Linear search in ds
chauhankapil
 
Searching,sorting
Searching,sortingSearching,sorting
Searching,sorting
LavanyaJ28
 
Data Structures Unit 2 FINAL presentation.pptx
Data Structures   Unit 2 FINAL presentation.pptxData Structures   Unit 2 FINAL presentation.pptx
Data Structures Unit 2 FINAL presentation.pptx
dilipd20
 
Presentation on Searching and Sorting in C language.pptx
Presentation on Searching and Sorting in C language.pptxPresentation on Searching and Sorting in C language.pptx
Presentation on Searching and Sorting in C language.pptx
Krishnanandmishra15
 
4.1 sequentioal search
4.1 sequentioal search4.1 sequentioal search
4.1 sequentioal search
Krish_ver2
 
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
Aftabali702240
 
Ad

Recently uploaded (20)

Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptxRai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 
How to Manage Allocations in Odoo 18 Time Off
How to Manage Allocations in Odoo 18 Time OffHow to Manage Allocations in Odoo 18 Time Off
How to Manage Allocations in Odoo 18 Time Off
Celine George
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
State institute of educational technology
State institute of educational technologyState institute of educational technology
State institute of educational technology
vp5806484
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
National Information Standards Organization (NISO)
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
la storia dell'Inghilterra, letteratura inglese
la storia dell'Inghilterra, letteratura inglesela storia dell'Inghilterra, letteratura inglese
la storia dell'Inghilterra, letteratura inglese
LetiziaLucente
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
How to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 SalesHow to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 Sales
Celine George
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
Coleoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptxColeoptera: The Largest Insect Order.pptx
Coleoptera: The Largest Insect Order.pptx
Arshad Shaikh
 
How to Manage Allocations in Odoo 18 Time Off
How to Manage Allocations in Odoo 18 Time OffHow to Manage Allocations in Odoo 18 Time Off
How to Manage Allocations in Odoo 18 Time Off
Celine George
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
State institute of educational technology
State institute of educational technologyState institute of educational technology
State institute of educational technology
vp5806484
 
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad LevelLDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDMMIA Reiki Yoga S8 Free Workshop Grad Level
LDM & Mia eStudios
 
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
Module 4 Presentation - Enhancing Competencies and Engagement Strategies in Y...
GeorgeDiamandis11
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
la storia dell'Inghilterra, letteratura inglese
la storia dell'Inghilterra, letteratura inglesela storia dell'Inghilterra, letteratura inglese
la storia dell'Inghilterra, letteratura inglese
LetiziaLucente
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
How to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 SalesHow to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 Sales
Celine George
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
Ad

Searching techniques in Data Structure And Algorithm

  • 1. SEARCHING TECHNIQUES DATA STRUCTURE AND ANALYSIS Instructor Pir Syed M Ayaz Farid Shah
  • 2. What is searching?  Searching is an operation or a technique that helps finds the place of a given element or value in the list. Any search is said to be successful or unsuccessful depending upon whether the element that is being searched is found or not.
  • 3. Searching Techniques There are tow types of searching in data structure and analysis  Linear Search  Binary Search  Interpolation Search
  • 4. Linear Search Linear search is a very simple search algorithm. In this type of search, a sequential search is made over all items one by one. Every item is checked and if a match is found then that particular item is returned, otherwise the search continues till the end of the data collection.
  • 5. Linear Search Algorithm  Linear Search ( Array A, Value 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
  • 6. Binary search Binary search is a fast search algorithm with run-time complexity of Ο(log n). This search algorithm works on the principle of divide and conquer. For this algorithm to work properly, the data collection should be in the sorted form. Binary search looks for a particular item by comparing the middle most item of the collection. If a match occurs, then the index of item is returned. If the middle item is greater than the item, then the item is searched in the sub-array to the right of the middle item. Otherwise, the item is searched for in the sub-array to the left of the middle item. This process continues on the sub-array as well until the size of the subarray reduces to zero.
  • 7. Binary Search Algorithm  Compare x with the middle element.  If x matches with middle element, we return the mid index.  Else If x is greater than the mid element, then x can only lie in right half subarray after the mid element. So we recur for right half.  Else (x is smaller) recur for the left half.
  • 8. Binary vs. Linear Search •Input data needs to be sorted in Binary Search and not in Linear Search •Linear search does the sequential access whereas Binary search access data randomly. •Time complexity of linear search -O(n) , Binary search has time complexity O(log n). • Linear search performs equality comparisons and Binary search performs ordering comparisons
  • 9. Interpolation Search Interpolation search is an improved variant of binary search. This search algorithm works on the probing position of the required value. For this algorithm to work properly, the data collection should be in a sorted form and equally distributed. Binary search has a huge advantage of time complexity over linear search. Linear search has worst-case complexity of Ο(n) whereas binary search has Ο(log n). There are cases where the location of target data may be known in advance. For example, in case of a telephone directory, if we want to search the telephone number of Morphius. Here, linear search and even binary search will seem slow as we can directly jump to memory space where the names start from 'M' are stored.
  • 10. Interpolation Search Algorithm Step 1 − Start searching data from middle of the list. Step 2 − If it is a match, return the index of the item, and exit. Step 3 − If it is not a match, probe position. Step 4 − Divide the list using probing formula and find the new midle. Step 5 − If data is greater than middle, search in higher sub-list. Step 6 − If data is smaller than middle, search in lower sub-list. Step 7 − Repeat until match.
  • 11. Binary vs. Interpolation Search  Positioning in Binary Search  Position Probing in Interpolation Search
  • 12. ???

Editor's Notes

  • #4: Beginning course details and/or books/materials needed for a class/project.
  • #5: A schedule design for optional periods of time/objectives.
  • #7: Objectives for instruction and expected results and/or skills developed from learning.
  • #8: Relative vocabulary list.
  • #9: A list of procedures and steps, or a lecture slide with media.
  • #10: Example graph/chart.
  • #11: Conclusion to course, lecture, et al.
  • #12: Example graph/chart.