logo

Linear Search Algorithm Analysis

   

Added on  2023-06-11

5 Pages1007 Words121 Views
Running head: LINEAR SEARCH ALGORITHM ANALYSIS
Linear Search Algorithm Analysis
Name of the Student:
Name of the University:
Author note:

1
LINEAR SEARCH ALGORITHM ANALYSIS
The Linear Search Algorithm
Linear search is a very commonly used searching method used by most programmers
in order to search through a small list of elements. This kind of searching technique is also
known as the Sequential Searching algorithm. It is an extremely simple searching algorithm,
where a sequential search is conducted over all items in a list or array, one at a time. Every
element is checked for equality with the being searched element and if a match is found then
that particular element is displayed or returned. However, until the search element is spotted,
the searching goes on till the pointer reaches the end of the list (Deitel and Deitel 2008).
Algorithm
LinearSearch (array myArray, value searchElement)
Step 1: Set index i to 0
Step 2: if i >= length(myArray) then go to step-7, else go to next step
Step 3: if myArray [i] = searchElement, then go to step-6, else go to next step
Step 4: Increment i by 1
Step 5: Go to Step-2
Step 6: Print searchElement ‘Found at index i and go to step-8’
Step 7: Print ‘element not found’
Step 8: Exit
Java Code for the Linear Search Algorithm
public class Search{
public static int LinearSearch(int[] myArray, int searchElement){
int flag=0;
for(int i=0;i<myArray.length;i++){
if(myArray[i[==searchElement){

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Linear Search Algorithm: Introduction, Types of Problems Solved, Working, Implementation, Comparison with Binary Search Algorithm
|6
|1184
|184

Pseudocode Case Complexity
|3
|496
|23

Algorithms for Searching, Sorting, and Matrix Operations
|8
|1756
|131

THE ARTIFICIAL INTELLIGENCE
|9
|1495
|22

AVL Tree, Set Intersection Algorithms, Sloppy Inc. Communication, Array Search
|9
|2413
|78

Desklib SEO Suggestions
|9
|2414
|194