Search

Friday, November 7, 2014
0 comments

Design an algorithm to search a number using linear search technique

11:11 PMFriday, November 7, 2014
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.





Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top