Skip to content
DATA STRUCTURE
DATA STRUCTURE

Learn everything about Data structure

  • Algorithms
  • DSA
  • Array
  • Stack
  • Queue
  • Matrix
  • Programs
DATA STRUCTURE

Learn everything about Data structure

Algorithm for Linear Search in Array

YASH PAL, September 26, 2022March 6, 2023

In this tutorial, we are going to write a Linear search algorithm in Array. using this algorithm we can write a program to linear search in the array for an element in almost every programming language like java, python, c++, and c programming.

[br]

Algorithm for Linear Search in Array.

1. Read N
2. Repeat step3 for I:=0 to n-1
3.         Read A[I].
4. [End of Step 2. loop]
5. Read ITEM.
6. Set FOUND:=FALSE
7. Repeat step7 For I:=0 to n-1 [Searching]
8.       If A[I]=ITEM, then:
9.           a. Set FOUND:=TRUE.
10.           b. GoTo Step 8.
11.       [End of If Structure.]
12. [End of Step 6. loop]
13. If FOUND=TRUE, then:
14.       Write “Item is found at position:”,I+1.
15. Else:
16.       Write “Item not Found”.
17. [End of If Structure.]
18. Exit.
[br]
Here in the above algorithm first we read an Integer variable N that is presenting the length of an array. after that using the value of N we run a for loop to repeat step number 3. using step 3 we read the value from the user and store it in the array. and then read a new number that the user wants to search in the array. after that, we set the value of FOUND to FALSE and then using the value of N we again run a for loop and then check if the value of the ITEM variable is equal to the A[I].
[br]
then we set the value of FOUND variable to true else we again repeat the same steps 8 and 9 and then after ending the for loop we check if the value of FOUND variable is TRUE then we write “Item is found at position” on output screen else we write “Item not Found” on output screen and then we exit from the program.
[br]
Also, Read
  1. Algorithm to Find Maximum of Two Numbers
  2. Algorithm to Find Maximum of Three Numbers
  3. Algorithm to Input percentage From user and Print grade
  4. Algorithm to Print the Series 1 to N using for loop
  5. Algorithm to Print the Series 1 to N using while loop
  6. Algorithm to Print the Series 1 to N using Do While loop
  7. Algorithm to Reverse a given Number
  8. Algorithm to Find Whether a Number is Prime or Not
  9. Algorithm to Calculate Factorial using Function
algorithms algorithm

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

  • HackerRank Dynamic Array Solution in Python
  • HackerRank 2D Array DS solution in Python
  • HackeRank Array – DS solution in Python
  • Streaming Demystified: How Much Data Does Your Favorite Show Really Use?
  • Parenthesis Matching program in C programming
  • HackerRank Dynamic Array Solution in Python
  • HackerRank 2D Array DS solution in Python
  • HackeRank Array – DS solution in Python
  • Streaming Demystified: How Much Data Does Your Favorite Show Really Use?
  • Parenthesis Matching program in C programming
  • About US
  • Contact US
  • Data Structures and algorithms tutorials
  • Digital Communication Tutorials
  • DMCA
  • HackerRank All Algorithms problems solutions
  • HackerRank C problems solutions
  • HackerRank C++ problems solutions
  • HackerRank Java solutions
  • HackerRank Python solutions
  • Human Values Tutorials
  • Internet of Things Tutorials
  • Privacy Policy
©2025 DATA STRUCTURE | WordPress Theme by SuperbThemes