SlideShare a Scribd company logo
Data structures in C..
ADITHYA. M
2ND SEM, BCA
19NCBC1042
National college
Linear
search
method
Linear search..
Searching is the process of looking for something.Linear search is the simplest search algorithm and
often called sequential search.In computer science,a linear search or sequential search is a method for
finding an element within a list.We search an element or value in a given array or list by traversing the
array from the starting,till the desired element or value is found.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
otherwise the algorithm returns NULL.
Simple steps for linear search..
• 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 function.
Implementing Linear Search..
 Traverse the array using a for loop.
 In every iteration,compare the target value with the current value of the array.
 If the values match,return the current index of the array.
 If the values do not match,move on to the next array element.
 If no match is found,return -1
programming in C
Algorithm..
• Step 1:Select the first element as the current element.
• Step 2:Compare the current element with the target element.If matches,then go
to step 5.
• Step 3:If there is a next element,then set current element to next element and
go to Step 2.
• Step 4:Target element not found.Go to Step 6.
• Step 5:Target element found and return location.
• Step 6:Exit process
Applications..
• Linear search is usually very simple to implement,and is practical when the list has only a few
elements,or when performing a single search in an un-ordered list.
• When many values have to be searched in the same list,it often pays to pre-process the list in order to
use a faster method.For example,one may sort the list and use binary search,or build an efficient
search data structure from it.
• As a result,even though in theory other search algorithms may be faster than linear search (for
instance binary search),in practice even on medium-sized arrays (around 100 items or less) it might
be infeasible to use anything else.On larger arrays,it only makes sense to use other,faster search
methods if the data is large enough,because the initial time to prepare (sort) the data is comparable
to many linear searches.
Comparison between Binary Search and Linear Search:…
• Binary Search requires the input data to be sorted;Linear Search doesn’t
• Binary Search requires an ordering comparison;Linear Search only requires equality
comparisons
• Binary Search has complexity O(log n);Linear search has complexity O(n) as discussed earlier
• Binary Search requires random access to the data;Linear Search only requires sequential access
(this can be very important — it means a Linear Search can stream data of arbitrary size)
Thank you…

More Related Content

Similar to programming in C (20)

PPTX
Linear Search for design and analysis of algorithm
JavedKhan524377
 
PPTX
Data structure Unit - II Searching and Sorting.pptx
gavanisanjana
 
PPTX
Searching, Sorting and Hashing Techniques
Selvaraj Seerangan
 
PPTX
Presentation on Searching and Sorting in C language.pptx
Krishnanandmishra15
 
PPTX
Searching_Techniques Linear search Algorithm
Anil Yadav
 
PPTX
Searching techniques in Data Structure And Algorithm
03446940736
 
PPTX
Searching_Techniques Binary search Algorithm
Anil Yadav
 
PPTX
Data Structures_ Sorting & Searching
ThenmozhiK5
 
PPTX
DS - Unit 2 FINAL (2).pptx
prakashvs7
 
PPTX
Data Structures Unit 2 FINAL presentation.pptx
dilipd20
 
PPTX
Data structure and algorithms
technologygyan
 
PPTX
seaching internal 2 ppt
SubhrasisBiswal1
 
PDF
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
PPTX
SORTING techniques.pptx
Dr.Shweta
 
PDF
searching
A. S. M. Shafi
 
PPTX
Linear search-and-binary-search
International Islamic University
 
PDF
Data Structure & Algorithms - Operations
babuk110
 
PPTX
unit II_2_i.pptx
HODElex
 
PPTX
Searching,sorting
LavanyaJ28
 
PPT
Searching in c language
CHANDAN KUMAR
 
Linear Search for design and analysis of algorithm
JavedKhan524377
 
Data structure Unit - II Searching and Sorting.pptx
gavanisanjana
 
Searching, Sorting and Hashing Techniques
Selvaraj Seerangan
 
Presentation on Searching and Sorting in C language.pptx
Krishnanandmishra15
 
Searching_Techniques Linear search Algorithm
Anil Yadav
 
Searching techniques in Data Structure And Algorithm
03446940736
 
Searching_Techniques Binary search Algorithm
Anil Yadav
 
Data Structures_ Sorting & Searching
ThenmozhiK5
 
DS - Unit 2 FINAL (2).pptx
prakashvs7
 
Data Structures Unit 2 FINAL presentation.pptx
dilipd20
 
Data structure and algorithms
technologygyan
 
seaching internal 2 ppt
SubhrasisBiswal1
 
BCA DATA STRUCTURES SEARCHING AND SORTING MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
SORTING techniques.pptx
Dr.Shweta
 
searching
A. S. M. Shafi
 
Linear search-and-binary-search
International Islamic University
 
Data Structure & Algorithms - Operations
babuk110
 
unit II_2_i.pptx
HODElex
 
Searching,sorting
LavanyaJ28
 
Searching in c language
CHANDAN KUMAR
 

Recently uploaded (20)

PPTX
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
PDF
NEW-Viral>Wondershare Filmora 14.5.18.12900 Crack Free
sherryg1122g
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PDF
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
PDF
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Comprehensive Risk Assessment Module for Smarter Risk Management
EHA Soft Solutions
 
NEW-Viral>Wondershare Filmora 14.5.18.12900 Crack Free
sherryg1122g
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
How to Hire AI Developers_ Step-by-Step Guide in 2025.pdf
DianApps Technologies
 
vMix Pro 28.0.0.42 Download vMix Registration key Bundle
kulindacore
 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
 
Home Care Tools: Benefits, features and more
Third Rock Techkno
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Ad

programming in C

  • 1. Data structures in C.. ADITHYA. M 2ND SEM, BCA 19NCBC1042 National college Linear search method
  • 2. Linear search.. Searching is the process of looking for something.Linear search is the simplest search algorithm and often called sequential search.In computer science,a linear search or sequential search is a method for finding an element within a list.We search an element or value in a given array or list by traversing the array from the starting,till the desired element or value is found.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 otherwise the algorithm returns NULL.
  • 3. Simple steps for linear search.. • 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 function.
  • 4. Implementing Linear Search..  Traverse the array using a for loop.  In every iteration,compare the target value with the current value of the array.  If the values match,return the current index of the array.  If the values do not match,move on to the next array element.  If no match is found,return -1
  • 6. Algorithm.. • Step 1:Select the first element as the current element. • Step 2:Compare the current element with the target element.If matches,then go to step 5. • Step 3:If there is a next element,then set current element to next element and go to Step 2. • Step 4:Target element not found.Go to Step 6. • Step 5:Target element found and return location. • Step 6:Exit process
  • 7. Applications.. • Linear search is usually very simple to implement,and is practical when the list has only a few elements,or when performing a single search in an un-ordered list. • When many values have to be searched in the same list,it often pays to pre-process the list in order to use a faster method.For example,one may sort the list and use binary search,or build an efficient search data structure from it. • As a result,even though in theory other search algorithms may be faster than linear search (for instance binary search),in practice even on medium-sized arrays (around 100 items or less) it might be infeasible to use anything else.On larger arrays,it only makes sense to use other,faster search methods if the data is large enough,because the initial time to prepare (sort) the data is comparable to many linear searches.
  • 8. Comparison between Binary Search and Linear Search:… • Binary Search requires the input data to be sorted;Linear Search doesn’t • Binary Search requires an ordering comparison;Linear Search only requires equality comparisons • Binary Search has complexity O(log n);Linear search has complexity O(n) as discussed earlier • Binary Search requires random access to the data;Linear Search only requires sequential access (this can be very important — it means a Linear Search can stream data of arbitrary size)