Data Structure and Algorithms Linear Search


Advertisements

Linear search is a very simple search algorithm. In this type of search, a sequential search is made over all items one by one. 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.

Linear Search Animation

Algorithm

Linear Search ( Array A, Value x)

Step 1: Set i to 1
Step 2: if i > n then go to step 7
Step 3: if A[i] = x then go to step 6
Step 4: Set i to i + 1
Step 5: Go to Step 2
Step 6: Print Element x Found at index i and go to step 8
Step 7: Print element not found
Step 8: Exit

Pseudocode

procedure linear_search (list, value)

   for each item in the list
      if match item == value
         return the item's location
      end if
   end for

end procedure

To know about linear search implementation in C programming language, please click-here.

Useful Video Courses

Video

Azure Data Lake Online Training

42 Lectures 1.5 hours

Ravi Kiran

Video

Data Structure Online Training

141 Lectures 13 hours

Arnab Chakraborty

Video

Oracle Data Guard Online Training

26 Lectures 8.5 hours

Parth Panjabi

Video

Big Data & Hadoop Online Training

65 Lectures 6 hours

Arnab Chakraborty

Video

Python with Data Science

Best Seller

75 Lectures 13 hours

Eduonix Learning Solutions

Video

Mathematics for Data Science and Machine Learning using R

64 Lectures 10.5 hours

Eduonix Learning Solutions

Advertisements