SlideShare a Scribd company logo
2
Most read
8
Most read
10
Most read
Government Polytechnic Lucknow
INFORMATION
TECHNOLOGY 2ND YEAR
Presented by : Krishnanand Mishra, Sumit Shukla , Ankur Kumar , Utkarsh Tiwari
Data structure using C
Searching
Linear
search
Binary
search
Searching
Searching in Array
Searching in array
means to find
whether a
particular value is
present in array or
not.
If the desired value is
present in the array,
then searching is said to
be successful. And the
searching process gives
the location of that
value in the array.
If the desired
value is not
present in the
array, then
searching is said
to be
unsuccessful.
There are two
popular methods
for searching the
array elements.
Linear
search
Binary
search
Linear Search
It is a very basic and simple search algorithm.
In linear search we search an element in given array by traversing the array from the
starting till the desired element is found.
Linear search is mostly used to search an unordered list of elements.
like : A[ ] = { 10,8,4,7,6,2,5,1,9};
Algorithm
Step 1 - Read the search element from the user.
Step 2 - Compare the search element with the first element in the list.
Step 3 - If both are matched, then display "given element is found!!!" And terminate the function
Step 4 - If both are not matched, then compare search element with the next element in the list.
Step 5 - Repeat steps 3 and 4 until search element is compared with last element in the list.
Step 6 - If last element in the list also doesn't match, then display "element is not found!!!" And terminate the
Example
Code
Int linear_search ( a[ ], LB, UB, item ) // LB= Lower bound, UB= upper bound,
{
int k;
for (k = LB ; k <= UB; K++)
{
if ( a [k] == item )
{
return k ;
}
}
return LB -1;
}
Binary search
Binary search is the search technique that works efficiently on sorted lists.
To search an element into some list using the binary search technique, we must ensure that
the list is sorted.
Binary search follows the divide and conquer approach in which the list is divided into two
halves, and the item is compared with the middle element of the list.
If the match is found then, the location of the middle element is returned. Otherwise, we
search into either of the halves depending upon the result produced through the match.
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 and find the new middle.
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
Example
.
Code
Int binary_ search ( A[ ], LB, UB, item ) // LB= Lower bound, UB= Upper bound,
{ int low=LB, high=UB;
int mid=(low + high) / 2;
while( (A[mid]!= item) && ( low<=high ) )
{ if( item<A[mid] )
high = mid -1 ;
else
low = mid +1 ;
mid = (low + high ) / 2;
}
if( A[ mid ]= item )
return min ;
else
return LB -1 ;
}
Linear search vs Binary search
Linear search Binary search
1. Data can be in any order. 1. Data should be in sorted order.
2. Multi dimensional array also can 2. Only single dimensional array is
be used. used.
3. Time complexity O(n). 3. Time complexity O log (n).
4. Not an efficient method to be used 4. Efficient for large inputs also.
if there is a large item.
Visualization
,
Thank you

More Related Content

Similar to Presentation on Searching and Sorting in C language.pptx (20)

PDF
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
PDF
linear search and binary search
Zia Ush Shamszaman
 
PPTX
unit II_2_i.pptx
HODElex
 
PPTX
Sequential & binary, linear search
montazur420
 
PPTX
Introduction to Searching Algorithm for beginners
JoshuaEddyson1
 
PPTX
data_structure_Chapter two_computer.pptx
Mohammed472103
 
PPTX
Rahat &amp; juhith
Rj Juhith
 
PDF
programming in C
ADITHYAM19
 
PPTX
placement preparation for Array Searching.pptx
upasnatiwari10
 
PDF
Binary search
Ramkrishna bhagat
 
PPTX
Searching & Algorithms IN DATA STRUCTURES
RAKSHITDOGRA1
 
PPTX
27631722026_T._TAJESWAR_RAO_PCC-CS301_CSE(CS).pptx
AyanMandal44
 
DOCX
MODULE 5-Searching and-sorting
nikshaikh786
 
PPT
Searching
Muhammad Farhan
 
PPTX
linear-search-and-binary-search-170418023907.pptx
gayathrigsits
 
PPTX
Searching and Sorting Unit II Part I.pptx
Dr. Madhuri Jawale
 
PPTX
unit 2 First.pptx Searching - Linear and Binary Search
Vaibhav Parjane
 
PPTX
Searching techniques in Data Structure And Algorithm
03446940736
 
PPTX
Linear search-and-binary-search
International Islamic University
 
PPTX
Linear and Binary search .pptx
p83629918
 
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
linear search and binary search
Zia Ush Shamszaman
 
unit II_2_i.pptx
HODElex
 
Sequential & binary, linear search
montazur420
 
Introduction to Searching Algorithm for beginners
JoshuaEddyson1
 
data_structure_Chapter two_computer.pptx
Mohammed472103
 
Rahat &amp; juhith
Rj Juhith
 
programming in C
ADITHYAM19
 
placement preparation for Array Searching.pptx
upasnatiwari10
 
Binary search
Ramkrishna bhagat
 
Searching & Algorithms IN DATA STRUCTURES
RAKSHITDOGRA1
 
27631722026_T._TAJESWAR_RAO_PCC-CS301_CSE(CS).pptx
AyanMandal44
 
MODULE 5-Searching and-sorting
nikshaikh786
 
Searching
Muhammad Farhan
 
linear-search-and-binary-search-170418023907.pptx
gayathrigsits
 
Searching and Sorting Unit II Part I.pptx
Dr. Madhuri Jawale
 
unit 2 First.pptx Searching - Linear and Binary Search
Vaibhav Parjane
 
Searching techniques in Data Structure And Algorithm
03446940736
 
Linear search-and-binary-search
International Islamic University
 
Linear and Binary search .pptx
p83629918
 

Recently uploaded (20)

PPTX
Gupta Art & Architecture Temple and Sculptures.pptx
Virag Sontakke
 
PDF
Tips for Writing the Research Title with Examples
Thelma Villaflores
 
PPTX
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
PDF
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
PPTX
Introduction to Probability(basic) .pptx
purohitanuj034
 
PPTX
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
PPTX
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
The Future of Artificial Intelligence Opportunities and Risks Ahead
vaghelajayendra784
 
PPTX
Applied-Statistics-1.pptx hardiba zalaaa
hardizala899
 
PPTX
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
PPTX
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 
DOCX
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
PDF
John Keats introduction and list of his important works
vatsalacpr
 
PPTX
K-Circle-Weekly-Quiz12121212-May2025.pptx
Pankaj Rodey
 
PPTX
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PDF
EXCRETION-STRUCTURE OF NEPHRON,URINE FORMATION
raviralanaresh2
 
Gupta Art & Architecture Temple and Sculptures.pptx
Virag Sontakke
 
Tips for Writing the Research Title with Examples
Thelma Villaflores
 
Top 10 AI Tools, Like ChatGPT. You Must Learn In 2025
Digilearnings
 
Module 2: Public Health History [Tutorial Slides]
JonathanHallett4
 
Introduction to Probability(basic) .pptx
purohitanuj034
 
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
I INCLUDED THIS TOPIC IS INTELLIGENCE DEFINITION, MEANING, INDIVIDUAL DIFFERE...
parmarjuli1412
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
The Future of Artificial Intelligence Opportunities and Risks Ahead
vaghelajayendra784
 
Applied-Statistics-1.pptx hardiba zalaaa
hardizala899
 
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
Rules and Regulations of Madhya Pradesh Library Part-I
SantoshKumarKori2
 
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
John Keats introduction and list of his important works
vatsalacpr
 
K-Circle-Weekly-Quiz12121212-May2025.pptx
Pankaj Rodey
 
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
Translation_ Definition, Scope & Historical Development.pptx
DhatriParmar
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
EXCRETION-STRUCTURE OF NEPHRON,URINE FORMATION
raviralanaresh2
 
Ad

Presentation on Searching and Sorting in C language.pptx

  • 1. Government Polytechnic Lucknow INFORMATION TECHNOLOGY 2ND YEAR Presented by : Krishnanand Mishra, Sumit Shukla , Ankur Kumar , Utkarsh Tiwari
  • 2. Data structure using C Searching Linear search Binary search
  • 4. Searching in Array Searching in array means to find whether a particular value is present in array or not. If the desired value is present in the array, then searching is said to be successful. And the searching process gives the location of that value in the array. If the desired value is not present in the array, then searching is said to be unsuccessful. There are two popular methods for searching the array elements. Linear search Binary search
  • 5. Linear Search It is a very basic and simple search algorithm. In linear search we search an element in given array by traversing the array from the starting till the desired element is found. Linear search is mostly used to search an unordered list of elements. like : A[ ] = { 10,8,4,7,6,2,5,1,9};
  • 6. Algorithm Step 1 - Read the search element from the user. Step 2 - Compare the search element with the first element in the list. Step 3 - If both are matched, then display "given element is found!!!" And terminate the function Step 4 - If both are not matched, then compare search element with the next element in the list. Step 5 - Repeat steps 3 and 4 until search element is compared with last element in the list. Step 6 - If last element in the list also doesn't match, then display "element is not found!!!" And terminate the
  • 8. Code Int linear_search ( a[ ], LB, UB, item ) // LB= Lower bound, UB= upper bound, { int k; for (k = LB ; k <= UB; K++) { if ( a [k] == item ) { return k ; } } return LB -1; }
  • 9. Binary search Binary search is the search technique that works efficiently on sorted lists. To search an element into some list using the binary search technique, we must ensure that the list is sorted. Binary search follows the divide and conquer approach in which the list is divided into two halves, and the item is compared with the middle element of the list. If the match is found then, the location of the middle element is returned. Otherwise, we search into either of the halves depending upon the result produced through the match.
  • 10. 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 and find the new middle. 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
  • 12. Code Int binary_ search ( A[ ], LB, UB, item ) // LB= Lower bound, UB= Upper bound, { int low=LB, high=UB; int mid=(low + high) / 2; while( (A[mid]!= item) && ( low<=high ) ) { if( item<A[mid] ) high = mid -1 ; else low = mid +1 ; mid = (low + high ) / 2; } if( A[ mid ]= item ) return min ; else return LB -1 ; }
  • 13. Linear search vs Binary search Linear search Binary search 1. Data can be in any order. 1. Data should be in sorted order. 2. Multi dimensional array also can 2. Only single dimensional array is be used. used. 3. Time complexity O(n). 3. Time complexity O log (n). 4. Not an efficient method to be used 4. Efficient for large inputs also. if there is a large item.