CLASS10 Fundamentals of Data Structures

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 6

Searching

Searching is the process of determining whether or not a given value exists


in a data structure or a storage media. Searching is an important function in
computer science. Many advanced algorithms and data structures have been
devised for the sole purpose of making searches more efficient. And as the
data sets become larger and larger, good search algorithms will become
more important.

At one point in the history of computing, sequential search was sufficient.


But that quickly changed as the value of computers became apparent. Linear
search has many interesting properties in its own right, but is also a basis for
all other search algorithms. Learning how it works is critical. Binary search
is the next logical step in searching.

By dividing the working data set in half with each comparison, logarithmic
performance, O (log n), is achieved. That performance can be improved
significantly when the data set is very large by using interpolation search,
and improved yet again by using binary search when the data set gets
smaller.
Linear Search

Linear search is a basic form of search. Linear search is the basic


searching algorithm, also called as sequential search. Algorithm searches
the element by comparing the each element in the list, until the desired
element found.

This method of searching for data in an array is straightforward and easy


to understand. To find a given item, begin your search at the start of the
data collection and continue to look until you have either found the target
or exhausted the search space.

Clearly to employ this method you must first know where the data
collection begins and the size of the area to search. Alternatively, a
unique value could be used to signify the end of the search space.
Binary Search

When it is known that a data set is in sorted order it is possible to


drastically increase the speed of a search operation in most cases.
An array-based binary search selects the median (middle)
element in the array and compares its value to that of the target
value.

Because the array is known to be sorted, if the target value is less


than the middle value then the target must be in the first half of
the array. Likewise if the value of the target item is greater than
that of the middle value in the array, it is known that the target
lies in the second half of the array. In either case we can, in
effect, “throw out” one half of the search space with only one
comparison.
THANKS

You might also like