fork download
  1. /*
  2. In the book "Masterminds of Programming" on page 282, you were asked a very silly question, and I
  3. just wanted to point that out in case you missed it :)
  4.  
  5. The question "Why use a linear search through an array? Quicksort is faster!" makes no sense.
  6.  
  7. First of all, linear search is a *search* algorithm, whereas Quicksort is a *sort* algorithm. They
  8. achieve completely different goals, so it does not even make sense to compare their efficiency.
  9.  
  10. Second of all, Quicksort is *never* faster than linear search! Linear search has O(n) complexity,
  11. whereas Quicksort has O(n log n) complexity (best case and average) or O(n^2) complexity (worst case).
  12. Linear search touches each element at most once, whereas Quicksort touches each element at least once.
  13. Hence, it is impossible for Quicksort to be faster than linear search.
  14.  
  15. To make the question meaningful, it has to be changed to compare either
  16. a) linear search with binary search or
  17. b) some quadratic sort algorithm like bubble sort with quicksort.
  18. */
  19.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty