SlideShare a Scribd company logo
2
Most read
5
Most read
6
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)

PPT
Binary Search
kunj desai
 
PDF
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
PPTX
Queue ppt
SouravKumar328
 
PPTX
Priority Queue in Data Structure
Meghaj Mallick
 
PPT
Queue data structure
anooppjoseph
 
PPTX
Binary search
AparnaKumari31
 
PPTX
Complexity analysis in Algorithms
Daffodil International University
 
PPTX
heap Sort Algorithm
Lemia Algmri
 
PDF
Strings in python
Prabhakaran V M
 
PPTX
Stack and Queue
Apurbo Datta
 
PPTX
Doubly Linked List
Ninad Mankar
 
PDF
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 
PDF
Python tuple
Mohammed Sikander
 
PPTX
Tree Traversal
Md. Israil Fakir
 
PPTX
Linked list
akshat360
 
PPTX
Queue in Data Structure
Janki Shah
 
PPTX
Binary search in data structure
Meherul1234
 
PPSX
Data Structure (Queue)
Adam Mukharil Bachtiar
 
PPTX
Tree - Data Structure
Ashim Lamichhane
 
PPT
Arrays searching-sorting
Ajharul Abedeen
 
Binary Search
kunj desai
 
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
Queue ppt
SouravKumar328
 
Priority Queue in Data Structure
Meghaj Mallick
 
Queue data structure
anooppjoseph
 
Binary search
AparnaKumari31
 
Complexity analysis in Algorithms
Daffodil International University
 
heap Sort Algorithm
Lemia Algmri
 
Strings in python
Prabhakaran V M
 
Stack and Queue
Apurbo Datta
 
Doubly Linked List
Ninad Mankar
 
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 
Python tuple
Mohammed Sikander
 
Tree Traversal
Md. Israil Fakir
 
Linked list
akshat360
 
Queue in Data Structure
Janki Shah
 
Binary search in data structure
Meherul1234
 
Data Structure (Queue)
Adam Mukharil Bachtiar
 
Tree - Data Structure
Ashim Lamichhane
 
Arrays searching-sorting
Ajharul Abedeen
 

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

PPTX
seaching internal 2 ppt
SubhrasisBiswal1
 
PPTX
Searching techniques
Archana Burujwale
 
PDF
programming in C
ADITHYAM19
 
PPTX
Analysis of Algorithm - Binary Search.pptx
Maulana Abul Kalam Azad University of Technology
 
PPTX
Dsa – data structure and algorithms searching
sajinis3
 
PPTX
Lecture_Oct26.pptx
SylrizcinMarieManzo3
 
PPTX
Data Structures_ Sorting & Searching
ThenmozhiK5
 
PPTX
DS - Unit 2 FINAL (2).pptx
prakashvs7
 
PPT
Binary search in ds
chauhankapil
 
PDF
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
PPTX
Data structure Unit - II Searching and Sorting.pptx
gavanisanjana
 
PDF
Binary search
Ramkrishna bhagat
 
PDF
advanced searching and sorting.pdf
haramaya university
 
PPTX
Chapter 3 - Data Structure and Algorithms.pptx
tarrebulehora
 
PPT
Linear search in ds
chauhankapil
 
PPTX
Searching,sorting
LavanyaJ28
 
PPTX
Data Structures Unit 2 FINAL presentation.pptx
dilipd20
 
PPTX
Presentation on Searching and Sorting in C language.pptx
Krishnanandmishra15
 
PPT
4.1 sequentioal search
Krish_ver2
 
PPTX
Searching_Sorting.pptx
21BD1A058RSahithi
 
seaching internal 2 ppt
SubhrasisBiswal1
 
Searching techniques
Archana Burujwale
 
programming in C
ADITHYAM19
 
Analysis of Algorithm - Binary Search.pptx
Maulana Abul Kalam Azad University of Technology
 
Dsa – data structure and algorithms searching
sajinis3
 
Lecture_Oct26.pptx
SylrizcinMarieManzo3
 
Data Structures_ Sorting & Searching
ThenmozhiK5
 
DS - Unit 2 FINAL (2).pptx
prakashvs7
 
Binary search in ds
chauhankapil
 
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
Data structure Unit - II Searching and Sorting.pptx
gavanisanjana
 
Binary search
Ramkrishna bhagat
 
advanced searching and sorting.pdf
haramaya university
 
Chapter 3 - Data Structure and Algorithms.pptx
tarrebulehora
 
Linear search in ds
chauhankapil
 
Searching,sorting
LavanyaJ28
 
Data Structures Unit 2 FINAL presentation.pptx
dilipd20
 
Presentation on Searching and Sorting in C language.pptx
Krishnanandmishra15
 
4.1 sequentioal search
Krish_ver2
 
Searching_Sorting.pptx
21BD1A058RSahithi
 
Ad

Recently uploaded (20)

PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
PPTX
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPTX
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
PPTX
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
PPTX
How to Handle Salesperson Commision in Odoo 18 Sales
Celine George
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
How to Set Up Tags in Odoo 18 - Odoo Slides
Celine George
 
QUARTER 1 WEEK 2 PLOT, POV AND CONFLICTS
KynaParas
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
HUMAN RESOURCE MANAGEMENT: RECRUITMENT, SELECTION, PLACEMENT, DEPLOYMENT, TRA...
PRADEEP ABOTHU
 
Dimensions of Societal Planning in Commonism
StefanMz
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
Post Dated Cheque(PDC) Management in Odoo 18
Celine George
 
Stereochemistry-Optical Isomerism in organic compoundsptx
Tarannum Nadaf-Mansuri
 
How to Handle Salesperson Commision in Odoo 18 Sales
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.