[Solved] CSE100 Algorithm Design and Analysis Lab #01

$25

File Name: CSE100_Algorithm_Design_and_Analysis_Lab_#01.zip
File Size: 414.48 KB

SKU: [Solved] CSE100 Algorithm Design and Analysis Lab #01 Category: Tag:
5/5 - (1 vote)

Linear Search

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

Require: a: array of elements, of type T

Require: as: element to find, of type T

1: N length(a)

2: for i 1 to N do

3: if ai = as then

4: return i

5: end if

6: end for

7: 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.

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CSE100 Algorithm Design and Analysis Lab #01
$25