In sorting
a collection of numeric values, we arrange the values in either increasing or decreasing
order of magnitude. All the sorting algorithms presented in this blog aim at sorting
collection of items in increasing order of size. You can achieve the opposite by
simply changing the comparison operator as
can be clearly seen soon.
Generally,
in the analysis of algorithms we have the best case, average case and the worst
case. The best case is when the input is already in the desired form. For example,
when the collection of items to sort, is already sorted in the order we want e.g.
in increasing order. The worst case scenario is when we have to do the maximum amount
of work. For example, if the given collection is in complete decreasing order and
we have to sort in increasing order. You see we have to touch and move every item.
The average case lies in between.
In evaluating
the efficiency and running time (time taken to finish execution) of an algorithm
called the time complexity, we usually use the worst case scenario so that we can
say with confidence that the running time cannot exceed so and so values.
No comments:
Post a Comment