ALGORITHMS HAVE NO ABSOLUTES
You may think that you can create a scenario in which you can say that you always use a
particular kind of algorithm to solve a particular kind of problem. However, this isn’t the
case. For example, you can find discussions of the relative merits of using brute-force
techniques against certain problems as compared to divide and conquer. It shouldn’t
surprise you to discover that divide and conquer doesn’t win in every situation. For
example, when looking for the maximum value in an array, a brute-force approach can
win the day when the array isn’t sorted. You can read a discussion of this particular topic
at
http://stackoverflow.com/questions/11043226/why-do-divide-and-
conquer-algorithms-often-run-faster-than-brute-force
. The interesting
thing is that the brute-force approach also uses fewer resources in this particular case.
Always remember that rules have exceptions and knowing the exceptions can save you
time and effort later.
CHAPTER 2
Do'stlaringiz bilan baham: |