-->

Friday, November 7, 2014

Design an algorithm to search a number using linear search technique

Design an algorithm to search a number using linear search technique

Problem: Design an algorithm to search a number using linear search technique.
Input :  A list (array) of numbers, number of elements in the list and key to search.
Output : Returns 1 if the key is found otherwise returns 0.

LSEARCH(LIST, N, KEY)

[LIST is an array of numbers, N is the size of the array and key is the number to search]
Repeat For I=0, 1, 2, 3......N-1 [Assuming that array index starts from 0]
If(Key == LIST[I]) then:
Returns 1
[End of If]
Returns 0
Exit.





Read other related articles

Also read other articles

© Copyright 2013 Computer Programming | All Right Reserved