3. Searching
Searching is a process of finding an
element within the list of elements
stored in any order or randomly.
Linear search and binary search are
the two methods which are used in
arrays for searching the elements.
4. Linear Search
A linear search scans one item at a time,
without jumping to any item .
• The worst case complexity is O(n),
sometimes known an O(n) search
• Time taken to search elements keep
increasing as the number of elements
are increased.
5. Advantage of Linear Search
The primary advantage of linear search is its
simplicity: conceptually, it's extraordinarily easy
to understand, and, implementation-wise, it's
also very straight-forward. From an operational
standpoint, linear search also is very resource
efficient - it does not require copying /
partitioning of the array being search, and thus is
memory-efficient. It also operates equally well
on both unsorted and sorted data.
6. Disadvantage of Linear Search
The primary disadvantage of linear search
is that it has a very poor O(n) general
efficiency. That is, the performance of the
algorithm scales linearly with the size of the
input. For the general case, linear search
thus is considerably slower than many
other search algorithms.
7. Binary Search
A binary search however, cut down your
search to half as soon as you find middle
of a sorted list.
• The middle element is looked to check
if it is greater than or less than the
value to be searched.
• Accordingly, search is done to either
half of the given list
8. Advantage of binary search
•It’s a fairly simple algorithm, though
people get it wrong all the time.
•It’s well known and often implemented
for you as a library routine.
•Binary search is an optimal searching
algorithm using which we can search
desired element very efficiently .
9. Disadvantages of binary search
• It’s more complicated than linear search, and
is overkill for very small numbers of elements.
• It works only on lists that are sorted and kept
sorted.
• It works only on element types for which
there exists a less-than relationship. Some
types simply cannot be sorted
10. Applications
• The Binary Search is an efficient searching
method and is used to search desired record
from database.
• For solving non-linear equation, with one
unknown, this method is used.