3. Searching
Generally,
Searching means
to find or discover
something.
Searching in
data-strucutre
refers to the
process of
finding a
desired element
in set of items.
These set of
items are in
various forms ,
such as an Array,
Tree, Graph, or
Linked-list .
4. Searching in Array
Searching in array
means to find
whether a
particular value is
present in array or
not.
If the desired value is
present in the array,
then searching is said to
be successful. And the
searching process gives
the location of that
value in the array.
If the desired
value is not
present in the
array, then
searching is said
to be
unsuccessful.
There are two
popular methods
for searching the
array elements.
Linear
search
Binary
search
5. Linear Search
It is a very basic and simple search algorithm.
In linear search we search an element in given array by traversing the array from the starting till the desired
element is found.
Linear search is mostly used to search an unordered list of elements.
like : A[ ] = { 10,8,4,7,6,2,5,1,9};
6. Algorithm
Step 1 - Read the search element from the user.
Step 2 - Compare the search element with the first element in the list.
Step 3 - If both are matched, then display "given element is found!!!" And terminate
the function
Step 4 - If both are not matched, then compare search element with the next element
in the list.
Step 5 - Repeat steps 3 and 4 until search element is compared with last element in the
list.
Step 6 - If last element in the list also doesn't match, then display "element is not
found!!!" And terminate the function.