Lab #01 Linear Search Solution

$30.00 $24.00

Description In this assignment you are requested to implement linear search algorithm for nding an item in an array: Require: a: array of elements, of type T Require: as: element to nd, of type T N length(a) for i 1 to N do if ai = as then return i end if end for return…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Description

5/5 – (2 votes)

Description In this assignment you are requested to implement linear search algorithm for nding an item in an array:

Require: a: array of elements, of type T

Require: as: element to nd, of type T

  1. N length(a)

  1. for i 1 to N do

  2. if ai = as then

  1. return i

  1. end if

  1. end for

  1. return -1

Input structure The sequences and the element to search are integers (i.e. you can safely store them into int variables). Each case starts with a number which is the number of integers in the sequence. The following number is the element to search. Then the elements of the sequence follow, one per line.

Output structure Algorithm must return 1 if as is not in the sequence, or its position (i.e.

array index) if it is contained. You can assume that all the numbers in the sequence are distinct.

Lab #01 Linear Search Solution
$30.00 $24.00