CS 1083 Mod 2
CS 1083 Mod 2
search
various
Sometimes
sequential
understand algorithm and
i complexity
O"notation
big
Explain the linear search
why
algorithm is OCN)
Method 1
(Andrew's Attempts
Look for val= 5 same attempt ,
would return the
my Attempt last instance of the number .
length ; x++
if (Arr[x] = = test) & public Static final int NOT FOUND = -1;
length ; x++
3 found Pos =
NOT FOUND ;
it (Arr2x] ==
test; E
foundPos =
X;
looking for .
>x x
>X
- -
xx -
Method 2 Similar to last method however ,
the first instance found is returned.
it (Arr[i] = =
test) E
return ;;
3
return NOTFOUND ;
while ()E
Method 3 Note This code is not
fully complete
:
yet .
3 int i = 0;
return found position ; While (found Pos = = NOTFOUND Ali < Arr .
length) E
test) <
if
[Array(i) ==
foundPosition = i;
3;
i + +;
return foundPosition ;