0% found this document useful (0 votes)
9 views9 pages

Slidesgo Unlocking The Secrets of Linear Search A Journey Through C Language 20250105093740AuSW

Linear Search is a fundamental algorithm that sequentially checks each element in a list until the desired element is found, making it a great starting point for programming beginners. Although it is simple and easy to implement, it can be inefficient for large datasets due to its O(n) time complexity. Understanding Linear Search in C equips learners with essential programming skills and serves as a foundation for more complex searching techniques.

Uploaded by

kotaa6731
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views9 pages

Slidesgo Unlocking The Secrets of Linear Search A Journey Through C Language 20250105093740AuSW

Linear Search is a fundamental algorithm that sequentially checks each element in a list until the desired element is found, making it a great starting point for programming beginners. Although it is simple and easy to implement, it can be inefficient for large datasets due to its O(n) time complexity. Understanding Linear Search in C equips learners with essential programming skills and serves as a foundation for more complex searching techniques.

Uploaded by

kotaa6731
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 9

LInEaR

SEaRch By
CH.SRINIV
AS
24911A6611
Introduction to Linear
Search
is a fundamental
algorithm in computer science.
This presentation will take you on
a
journey through the t
explore how this simple o
yet
effective search method
works. Get ready to unlock the
secrets
behind its mechanics
and applications!
What is Linear
Search?
Linear Search is an
that checks each element in
a list until the
desired element is found. It's
simple and intuitive, making it
a great starting point for
beginners in programming.
Let's dive into how it
operates step by step.
Source Code of Linear Search
#include <stdio.h>
int linearSearch(int a[ ], int n, int val) {
// Going through array sequencially
for (int i = 0; i < n; i++)
{
if (a[i] == val)
return i+1;
}
return -1;
}
int main() {

int a[ ] = {70, 40, 30, 11, 57, 41, 25, 14, 52}; // given array
int val = 41; // value to be searched
int n = sizeof(a) / sizeof(a[0]); // size of array
int res = linearSearch(a, n, val); // Store result
printf("The elements of the array are - ");
for (int i = 0; i < n; i++)
printf("%d ", a[i]);
printf("\nElement to be searched is - %d", val);
if (res == -1)
printf("\nElement is not present in the array");
else
printf("\
nElement is present at %d position of array", res);
return 0;
How Linear Search
Works
In Linear Search, we start at
the of the array
and check each element
one by one. If we find the
target, we return its
; if not, we
continue until we reach the
end. This method is
straightforward but can be
inefficient for large
datasets.
Implementing in C Language
Let's see how to implement
Linear Search in C. The basic
structure involves a loop that
iterates through the array. We'll
use simple conditional
statements to check for the
target value. This is an excellent
opportunity to practice your
coding skills!
Pros and Cons of Linear Search

While Linear Search is easy to


understand and implement, it has
its drawbacks. It can be slow
for large datasets, as it has a
time complexity of O(n).
However, its simplicity makes it a
valuable tool in many scenarios.
Let's weigh the pros and cons!
Conclusion: The
Journey Ahead
In conclusion, Linear Search is a
foundational algorithm that
opens the door to more complex
searching techniques.
Understanding its principles in C
Language equips you with
essential programming skills.
Keep exploring, and who knows
what other secrets you'll
unlock!
Thank
you...

You might also like