What's more important: faster computer or better algorithm

  • Consider:

    1. A sorting algorithm (e.g. Merge Sort) with O(nlog(n)) running time

    2. A sorting algorithm (e.g. Insertion Sort) with O(n2) running time running on a faster computer (e.g., 1,000,000 times faster)

  • Which sorting program will finish first ?

    Answer:

    •  

       

What's more important: faster computer or better algorithm

  • Consider:

    1. A sorting algorithm (e.g. Merge Sort) with O(nlog(n)) running time

    2. A sorting algorithm (e.g. Insertion Sort) with O(n2) running time running on a faster computer (e.g., 1,000,000 times faster)

  • Which sorting program will finish first ?

    Answer:

    • It depends....

      on the input size !!!

What's more important: faster computer or better algorithm

Merge Sort (O(nlog(n)) on normal computer Insertion Sort (O(n2) on faster (super) computer
n = 1,000 n = 1,000 (1,000,000x faster )
# operations = 1,000*10 = 10,000 # operations = 1,0002 = 1,000,000
Time = 10,000 u Time = 1 u
n = 1,000,000 n = 1,000,000 (1,000,000x faster )
# operations = 1,000,000*20 = 20,000,000 # operations = 1,000,0002 = 1,000,000,000,000
Time = 20,000,000 u Time = 1,000,000 u
n = 1,000,000,000 n = 1,000,000,000 (1,000,000x faster )
# operations = 1,000,000,000*30 = 30,000,000,000 # operations = 1,000,000,0002 = 1,000,000,000,000,000,000
Time = 30,000,000,000 u Time = 1,000,000,000,000 u

A better algorithm will always beat an average algorithm when the input size is sufficiently large !!!