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
???
Ad

Recommended

sorting and its types
sorting and its types
SIVASHANKARIRAJAN
 
Algorithms Lecture 6: Searching Algorithms
Algorithms Lecture 6: Searching Algorithms
Mohamed Loey
 
SEARCHING AND SORTING ALGORITHMS
SEARCHING AND SORTING ALGORITHMS
Gokul Hari
 
Introduction to data structures and Algorithm
Introduction to data structures and Algorithm
Dhaval Kaneria
 
Unit I - Evaluation of expression
Unit I - Evaluation of expression
DrkhanchanaR
 
Tree - Data Structure
Tree - Data Structure
Ashim Lamichhane
 
Introduction to data structure ppt
Introduction to data structure ppt
NalinNishant3
 
Introduction to Web Programming
Introduction to Web Programming
Ynon Perek
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 
linear search and binary search
linear search and binary search
Zia Ush Shamszaman
 
Binary Search
Binary Search
kunj desai
 
Linear search-and-binary-search
Linear search-and-binary-search
International Islamic University
 
Searching
Searching
Ashim Lamichhane
 
Binary search
Binary search
AparnaKumari31
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
Priority queue in DSA
Priority queue in DSA
junnubabu
 
Quick Sort , Merge Sort , Heap Sort
Quick Sort , Merge Sort , Heap Sort
Mohammed Hussein
 
Data structures using c
Data structures using c
Prof. Dr. K. Adisesha
 
Array data structure
Array data structure
maamir farooq
 
Applications of stack
Applications of stack
eShikshak
 
Insertion sort
Insertion sort
almaqboli
 
Priority Queue in Data Structure
Priority Queue in Data Structure
Meghaj Mallick
 
Binary Search Tree in Data Structure
Binary Search Tree in Data Structure
Dharita Chokshi
 
Linked lists
Linked lists
SARITHA REDDY
 
Circular link list.ppt
Circular link list.ppt
Tirthika Bandi
 
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 Presentation
Linear Search Presentation
Markajul Hasnain Alif
 
searching
searching
A. S. M. Shafi
 
Analysis of Algorithm - Binary Search.pptx
Analysis of Algorithm - Binary Search.pptx
Maulana Abul Kalam Azad University of Technology
 

More Related Content

What's hot (20)

Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 
linear search and binary search
linear search and binary search
Zia Ush Shamszaman
 
Binary Search
Binary Search
kunj desai
 
Linear search-and-binary-search
Linear search-and-binary-search
International Islamic University
 
Searching
Searching
Ashim Lamichhane
 
Binary search
Binary search
AparnaKumari31
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
Priority queue in DSA
Priority queue in DSA
junnubabu
 
Quick Sort , Merge Sort , Heap Sort
Quick Sort , Merge Sort , Heap Sort
Mohammed Hussein
 
Data structures using c
Data structures using c
Prof. Dr. K. Adisesha
 
Array data structure
Array data structure
maamir farooq
 
Applications of stack
Applications of stack
eShikshak
 
Insertion sort
Insertion sort
almaqboli
 
Priority Queue in Data Structure
Priority Queue in Data Structure
Meghaj Mallick
 
Binary Search Tree in Data Structure
Binary Search Tree in Data Structure
Dharita Chokshi
 
Linked lists
Linked lists
SARITHA REDDY
 
Circular link list.ppt
Circular link list.ppt
Tirthika Bandi
 
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 Presentation
Linear Search Presentation
Markajul Hasnain Alif
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
Drishti Bhalla
 
linear search and binary search
linear search and binary search
Zia Ush Shamszaman
 
Stacks IN DATA STRUCTURES
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
Priority queue in DSA
Priority queue in DSA
junnubabu
 
Quick Sort , Merge Sort , Heap Sort
Quick Sort , Merge Sort , Heap Sort
Mohammed Hussein
 
Array data structure
Array data structure
maamir farooq
 
Applications of stack
Applications of stack
eShikshak
 
Insertion sort
Insertion sort
almaqboli
 
Priority Queue in Data Structure
Priority Queue in Data Structure
Meghaj Mallick
 
Binary Search Tree in Data Structure
Binary Search Tree in Data Structure
Dharita Chokshi
 
Circular link list.ppt
Circular link list.ppt
Tirthika Bandi
 
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
 

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

searching
searching
A. S. M. Shafi
 
Analysis of Algorithm - Binary Search.pptx
Analysis of Algorithm - Binary Search.pptx
Maulana Abul Kalam Azad University of Technology
 
seaching internal 2 ppt
seaching internal 2 ppt
SubhrasisBiswal1
 
Binary search
Binary search
Ramkrishna bhagat
 
Searching & Algorithms IN DATA STRUCTURES
Searching & Algorithms IN DATA STRUCTURES
RAKSHITDOGRA1
 
programming in C
programming in C
ADITHYAM19
 
Searching Algorithm.pptx
Searching Algorithm.pptx
SUGUNA49
 
Searching Techniques and Analysis
Searching Techniques and Analysis
AkashBorse2
 
Chapter 11 ds
Chapter 11 ds
Hanif Durad
 
Binary search Algorithm
Binary search Algorithm
FazalRehman79
 
Presentation
Presentation
zohaib arif
 
Ocw chp6 2searchbinary
Ocw chp6 2searchbinary
Prashant Rai
 
Searching in Data Structure
Searching in Data Structure
raghavbirla63
 
Presentation on Searching and Sorting in C language.pptx
Presentation on Searching and Sorting in C language.pptx
Krishnanandmishra15
 
A presentation on the comparison on complexity between
A presentation on the comparison on complexity between
Jubayer Hasan
 
Algorithm 8th lecture linear & binary search(2).pptx
Algorithm 8th lecture linear & binary search(2).pptx
Aftabali702240
 
Lecture_Oct26.pptx
Lecture_Oct26.pptx
SylrizcinMarieManzo3
 
Binary Search.pptx
Binary Search.pptx
SheherBano57
 
Searching in c language
Searching in c language
CHANDAN KUMAR
 
Dsa – data structure and algorithms searching
Dsa – data structure and algorithms searching
sajinis3
 
Searching & Algorithms IN DATA STRUCTURES
Searching & Algorithms IN DATA STRUCTURES
RAKSHITDOGRA1
 
programming in C
programming in C
ADITHYAM19
 
Searching Algorithm.pptx
Searching Algorithm.pptx
SUGUNA49
 
Searching Techniques and Analysis
Searching Techniques and Analysis
AkashBorse2
 
Binary search Algorithm
Binary search Algorithm
FazalRehman79
 
Ocw chp6 2searchbinary
Ocw chp6 2searchbinary
Prashant Rai
 
Searching in Data Structure
Searching in Data Structure
raghavbirla63
 
Presentation on Searching and Sorting in C language.pptx
Presentation on Searching and Sorting in C language.pptx
Krishnanandmishra15
 
A presentation on the comparison on complexity between
A presentation on the comparison on complexity between
Jubayer Hasan
 
Algorithm 8th lecture linear & binary search(2).pptx
Algorithm 8th lecture linear & binary search(2).pptx
Aftabali702240
 
Binary Search.pptx
Binary Search.pptx
SheherBano57
 
Searching in c language
Searching in c language
CHANDAN KUMAR
 
Dsa – data structure and algorithms searching
Dsa – data structure and algorithms searching
sajinis3
 
Ad

Recently uploaded (20)

Peer Teaching Observations During School Internship
Peer Teaching Observations During School Internship
AjayaMohanty7
 
List View Components in Odoo 18 - Odoo Slides
List View Components in Odoo 18 - Odoo Slides
Celine George
 
Values Education 10 Quarter 1 Module .pptx
Values Education 10 Quarter 1 Module .pptx
JBPafin
 
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
trjnesjnqg7801
 
VCE Literature Section A Exam Response Guide
VCE Literature Section A Exam Response Guide
jpinnuck
 
June 2025 Progress Update With Board Call_In process.pptx
June 2025 Progress Update With Board Call_In process.pptx
International Society of Service Innovation Professionals
 
Photo chemistry Power Point Presentation
Photo chemistry Power Point Presentation
mprpgcwa2024
 
2025 Completing the Pre-SET Plan Form.pptx
2025 Completing the Pre-SET Plan Form.pptx
mansk2
 
CRYPTO TRADING COURSE BY FINANCEWORLD.IO
CRYPTO TRADING COURSE BY FINANCEWORLD.IO
AndrewBorisenko3
 
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
INDUCTIVE EFFECT slide for first prof pharamacy students
INDUCTIVE EFFECT slide for first prof pharamacy students
SHABNAM FAIZ
 
How to Customize Quotation Layouts in Odoo 18
How to Customize Quotation Layouts in Odoo 18
Celine George
 
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
KaryanaTantri21
 
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
ErlizaRosete
 
Birnagar High School Platinum Jubilee Quiz.pptx
Birnagar High School Platinum Jubilee Quiz.pptx
Sourav Kr Podder
 
English 3 Quarter 1_LEwithLAS_Week 1.pdf
English 3 Quarter 1_LEwithLAS_Week 1.pdf
DeAsisAlyanajaneH
 
NSUMD_M1 Library Orientation_June 11, 2025.pptx
NSUMD_M1 Library Orientation_June 11, 2025.pptx
Julie Sarpy
 
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
Ronisha Das
 
Learning Styles Inventory for Senior High School Students
Learning Styles Inventory for Senior High School Students
Thelma Villaflores
 
Great Governors' Send-Off Quiz 2025 Prelims IIT KGP
Great Governors' Send-Off Quiz 2025 Prelims IIT KGP
IIT Kharagpur Quiz Club
 
Peer Teaching Observations During School Internship
Peer Teaching Observations During School Internship
AjayaMohanty7
 
List View Components in Odoo 18 - Odoo Slides
List View Components in Odoo 18 - Odoo Slides
Celine George
 
Values Education 10 Quarter 1 Module .pptx
Values Education 10 Quarter 1 Module .pptx
JBPafin
 
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
Public Health For The 21st Century 1st Edition Judy Orme Jane Powell
trjnesjnqg7801
 
VCE Literature Section A Exam Response Guide
VCE Literature Section A Exam Response Guide
jpinnuck
 
Photo chemistry Power Point Presentation
Photo chemistry Power Point Presentation
mprpgcwa2024
 
2025 Completing the Pre-SET Plan Form.pptx
2025 Completing the Pre-SET Plan Form.pptx
mansk2
 
CRYPTO TRADING COURSE BY FINANCEWORLD.IO
CRYPTO TRADING COURSE BY FINANCEWORLD.IO
AndrewBorisenko3
 
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
 
INDUCTIVE EFFECT slide for first prof pharamacy students
INDUCTIVE EFFECT slide for first prof pharamacy students
SHABNAM FAIZ
 
How to Customize Quotation Layouts in Odoo 18
How to Customize Quotation Layouts in Odoo 18
Celine George
 
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
Romanticism in Love and Sacrifice An Analysis of Oscar Wilde’s The Nightingal...
KaryanaTantri21
 
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
M&A5 Q1 1 differentiate evolving early Philippine conventional and contempora...
ErlizaRosete
 
Birnagar High School Platinum Jubilee Quiz.pptx
Birnagar High School Platinum Jubilee Quiz.pptx
Sourav Kr Podder
 
English 3 Quarter 1_LEwithLAS_Week 1.pdf
English 3 Quarter 1_LEwithLAS_Week 1.pdf
DeAsisAlyanajaneH
 
NSUMD_M1 Library Orientation_June 11, 2025.pptx
NSUMD_M1 Library Orientation_June 11, 2025.pptx
Julie Sarpy
 
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
GREAT QUIZ EXCHANGE 2025 - GENERAL QUIZ.pptx
Ronisha Das
 
Learning Styles Inventory for Senior High School Students
Learning Styles Inventory for Senior High School Students
Thelma Villaflores
 
Great Governors' Send-Off Quiz 2025 Prelims IIT KGP
Great Governors' Send-Off Quiz 2025 Prelims IIT KGP
IIT Kharagpur Quiz Club
 
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.