SlideShare a Scribd company logo
1 of 11
Submitted To :- Submitted By :-
Miss Jaspreet Kaur
(Assistant Prof.)
Parteek Girdhar
(B130020031)
Searching Technique :-
It refers to the operation of finding the location LOC of
ITEM in DATA, or printing some message that ITEM
does not appear there. The search is said to be
successful if ITEM does not appear in DATA and
unsuccessful otherwise.
Types of Searching :-
Linear Search
 Binary Search
Linear Search :-
 It is a technique for finding a particular element in a
list that checks each element in sequence until the
desired element is found or the list is finished. The list
need not be ordered.
For example:- We have an array of 6 elements.
A={1,2,3,4,5,6}
suppose we want to find 5.
for this we have to traverse the array by comparing
each element of array A one by one.
How Long Does Linear Search Take?
Best Case :- In this case, the target value is in the first
element of the array. So it is denoted with O(1).
Worst Case :- In this case, the target value is in the
last element of the array. So it is denoted with O(n).
Average Case :- In this case, the target value is
somewhere in the array. So this search takes an
amount of time proportional to half the length of the
array – also proportional to the length of the array –
O(n).
Algorithm for Linear Search
LINEAR(DATA,N,ITEM,LOC)
Here DATA is a linear array with N elements, and ITEM is given item of
information. This algorithm finds the location LOC of ITEM in DATA,
or sets LOC:= 0 if the search is unsuccessful.
1. [Insert ITEM at the end of DATA.] Set DATA [N+1]:=ITEM.
2. [Initialize counter.] Set LOC:=1.
3. [Search for item.]
Repeat while DATA[LOC]!=ITEM:
Set LOC:=LOC+1.
[End of loop.]
4. [Successful?] If LOC =N+1,then: Set LOC:=0.
5. Exit.
Binary Search
 In binary search we first access the middle element
of given array.
 If the element to be searched is same as middle
element of array then our search is successful.
 If not then look weather the element is in left or
right half of sub-arrays.
After this apply binary search on sub-arrays.
Given array should be ordered.
How a Binary Search Works
Always look at the
center value. Each time
you get to discard half of
the remaining list.
Is this fast ?
For example:-
Suppose we have to find the location of a name in a
telephone directory.
For this we will apply Binary Search.
We will find the middle elements first.If it matches
our search element then we will stop here.
If not then we will determine which half contains the
element and we will access the middle elements of that
half.
If middle element is not same then repeat the same
procedure as we did above for each quarter and so on.
Algorithm:-
BINARY(DATA,LB,UB,ITEM,LOC)
1. [Initialize = segment variables.]
Set BEG:=LB,END:=UB and MID=INT((BEG+END)2)
2. Repeat step 3 and 4 while BEG<=END and DATA[MID]!=ITEM.
3. If ITEM <DATA[Mid],then:
Set END:=MID-1.
Else:
Set BEG:=MID+1.
[END of If structure.]
4. Set MID:=INT((BEG+END)/2)
[End of step 2 Loop.]
5. If DATA[MID]= ITEM, then:
Set LOC:=MID.
Else:
Set LOC:=NULL.
[End of if structure.]
6. Exit.
THANKS ;)

More Related Content

What's hot

Fuzzy logic by zaid da'ood
Fuzzy logic by zaid da'oodFuzzy logic by zaid da'ood
Fuzzy logic by zaid da'ood
master student
 

What's hot (19)

Binary search
Binary searchBinary search
Binary search
 
Chapter 5 searching and sorting handouts with notes
Chapter 5   searching and sorting handouts with notesChapter 5   searching and sorting handouts with notes
Chapter 5 searching and sorting handouts with notes
 
Search Algprithms
Search AlgprithmsSearch Algprithms
Search Algprithms
 
Binary search python
Binary search pythonBinary search python
Binary search python
 
SEARCHING
SEARCHINGSEARCHING
SEARCHING
 
Linear and binary search
Linear and binary searchLinear and binary search
Linear and binary search
 
Linear Search
Linear SearchLinear Search
Linear Search
 
Quick sort
Quick sortQuick sort
Quick sort
 
COMPUTER PROGRAMMING UNIT 1 Lecture 6
COMPUTER PROGRAMMING UNIT 1 Lecture 6COMPUTER PROGRAMMING UNIT 1 Lecture 6
COMPUTER PROGRAMMING UNIT 1 Lecture 6
 
Ch05 Black Jack
Ch05  Black  JackCh05  Black  Jack
Ch05 Black Jack
 
Sorting Algorithms
Sorting AlgorithmsSorting Algorithms
Sorting Algorithms
 
Linear Search Data Structure
Linear Search Data StructureLinear Search Data Structure
Linear Search Data Structure
 
Fuzzy logic by zaid da'ood
Fuzzy logic by zaid da'oodFuzzy logic by zaid da'ood
Fuzzy logic by zaid da'ood
 
Data operatons & searching and sorting algorithms
Data operatons & searching and sorting algorithmsData operatons & searching and sorting algorithms
Data operatons & searching and sorting algorithms
 
An Introduction To Python - Lists, Part 1
An Introduction To Python - Lists, Part 1An Introduction To Python - Lists, Part 1
An Introduction To Python - Lists, Part 1
 
Linear Search Presentation
Linear Search PresentationLinear Search Presentation
Linear Search Presentation
 
Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithm
 
practice problems on array IN SWIFT
practice problems on array IN SWIFTpractice problems on array IN SWIFT
practice problems on array IN SWIFT
 
Binary search Algorithm
Binary search AlgorithmBinary search Algorithm
Binary search Algorithm
 

Similar to Searching techniques

Searching Sorting
Searching SortingSearching Sorting
Searching Sorting
guest2cb109
 
DS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptxDS - Unit 2 FINAL (2).pptx
DS - Unit 2 FINAL (2).pptx
prakashvs7
 

Similar to Searching techniques (20)

MODULE 5-Searching and-sorting
MODULE 5-Searching and-sortingMODULE 5-Searching and-sorting
MODULE 5-Searching and-sorting
 
Searching Sorting
Searching SortingSearching Sorting
Searching Sorting
 
4- searching.ppt
4- searching.ppt4- searching.ppt
4- searching.ppt
 
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
 
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
 
advanced searching and sorting.pdf
advanced searching and sorting.pdfadvanced searching and sorting.pdf
advanced searching and sorting.pdf
 
searching
searchingsearching
searching
 
search_sort.ppt
search_sort.pptsearch_sort.ppt
search_sort.ppt
 
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
 
Searching_Sorting.pptx
Searching_Sorting.pptxSearching_Sorting.pptx
Searching_Sorting.pptx
 
Lecture_Oct26.pptx
Lecture_Oct26.pptxLecture_Oct26.pptx
Lecture_Oct26.pptx
 
arrays in c
arrays in carrays in c
arrays in c
 
Searching
SearchingSearching
Searching
 
Unit 6 dsa SEARCHING AND SORTING
Unit 6 dsa SEARCHING AND SORTINGUnit 6 dsa SEARCHING AND SORTING
Unit 6 dsa SEARCHING AND SORTING
 
Sorting and searching arrays binary search algorithm
Sorting and searching arrays binary search algorithmSorting and searching arrays binary search algorithm
Sorting and searching arrays binary search algorithm
 
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
 
Binary Search Algorithm.pptx
Binary Search Algorithm.pptxBinary Search Algorithm.pptx
Binary Search Algorithm.pptx
 
Linear and Binary search .pptx
Linear and Binary search .pptxLinear and Binary search .pptx
Linear and Binary search .pptx
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
 

Recently uploaded

Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
dharasingh5698
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 

Recently uploaded (20)

Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Netaji Nagar, Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 
22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf22-prompt engineering noted slide shown.pdf
22-prompt engineering noted slide shown.pdf
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 

Searching techniques

  • 1. Submitted To :- Submitted By :- Miss Jaspreet Kaur (Assistant Prof.) Parteek Girdhar (B130020031)
  • 2. Searching Technique :- It refers to the operation of finding the location LOC of ITEM in DATA, or printing some message that ITEM does not appear there. The search is said to be successful if ITEM does not appear in DATA and unsuccessful otherwise.
  • 3. Types of Searching :- Linear Search  Binary Search
  • 4. Linear Search :-  It is a technique for finding a particular element in a list that checks each element in sequence until the desired element is found or the list is finished. The list need not be ordered. For example:- We have an array of 6 elements. A={1,2,3,4,5,6} suppose we want to find 5. for this we have to traverse the array by comparing each element of array A one by one.
  • 5. How Long Does Linear Search Take? Best Case :- In this case, the target value is in the first element of the array. So it is denoted with O(1). Worst Case :- In this case, the target value is in the last element of the array. So it is denoted with O(n). Average Case :- In this case, the target value is somewhere in the array. So this search takes an amount of time proportional to half the length of the array – also proportional to the length of the array – O(n).
  • 6. Algorithm for Linear Search LINEAR(DATA,N,ITEM,LOC) Here DATA is a linear array with N elements, and ITEM is given item of information. This algorithm finds the location LOC of ITEM in DATA, or sets LOC:= 0 if the search is unsuccessful. 1. [Insert ITEM at the end of DATA.] Set DATA [N+1]:=ITEM. 2. [Initialize counter.] Set LOC:=1. 3. [Search for item.] Repeat while DATA[LOC]!=ITEM: Set LOC:=LOC+1. [End of loop.] 4. [Successful?] If LOC =N+1,then: Set LOC:=0. 5. Exit.
  • 7. Binary Search  In binary search we first access the middle element of given array.  If the element to be searched is same as middle element of array then our search is successful.  If not then look weather the element is in left or right half of sub-arrays. After this apply binary search on sub-arrays. Given array should be ordered.
  • 8. How a Binary Search Works Always look at the center value. Each time you get to discard half of the remaining list. Is this fast ?
  • 9. For example:- Suppose we have to find the location of a name in a telephone directory. For this we will apply Binary Search. We will find the middle elements first.If it matches our search element then we will stop here. If not then we will determine which half contains the element and we will access the middle elements of that half. If middle element is not same then repeat the same procedure as we did above for each quarter and so on.
  • 10. Algorithm:- BINARY(DATA,LB,UB,ITEM,LOC) 1. [Initialize = segment variables.] Set BEG:=LB,END:=UB and MID=INT((BEG+END)2) 2. Repeat step 3 and 4 while BEG<=END and DATA[MID]!=ITEM. 3. If ITEM <DATA[Mid],then: Set END:=MID-1. Else: Set BEG:=MID+1. [END of If structure.] 4. Set MID:=INT((BEG+END)/2) [End of step 2 Loop.] 5. If DATA[MID]= ITEM, then: Set LOC:=MID. Else: Set LOC:=NULL. [End of if structure.] 6. Exit.