11.07.2015 Views

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

Data Structures and Algorithm Analysis - Computer Science at ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Sec. 3.3 A Faster <strong>Computer</strong>, or a Faster <strong>Algorithm</strong>? 61f(n) n n ′ Change n ′ /n10n 1000 10, 000 n ′ = 10n 1020n 500 5000 n ′ = 10n 105n log n 250 1842 √ 10n < n ′ < 10n 7.372n 2 70 223 n ′ = √ 10n 3.162 n 13 16 n ′ = n + 3 −−Figure 3.3 The increase in problem size th<strong>at</strong> can be run in a fixed period of timeon a computer th<strong>at</strong> is ten times faster. The first column lists the right-h<strong>and</strong> sidesfor each of five growth r<strong>at</strong>e equ<strong>at</strong>ions from Figure 3.1. For the purpose of thisexample, arbitrarily assume th<strong>at</strong> the old machine can run 10,000 basic oper<strong>at</strong>ionsin one hour. The second column shows the maximum value for n th<strong>at</strong> can be runin 10,000 basic oper<strong>at</strong>ions on the old machine. The third column shows the valuefor n ′ , the new maximum size for the problem th<strong>at</strong> can be run in the same timeon the new machine th<strong>at</strong> is ten times faster. Variable n ′ is the gre<strong>at</strong>est size for theproblem th<strong>at</strong> can run in 100,000 basic oper<strong>at</strong>ions. The fourth column shows howthe size of n changed to become n ′ on the new machine. The fifth column showsthe increase in the problem size as the r<strong>at</strong>io of n ′ to n.If your algorithm’s growth r<strong>at</strong>e is linear (i.e., if the equ<strong>at</strong>ion th<strong>at</strong> describes therunning time on input size n is T(n) = cn for some constant c), then 100,000records on the new machine will be sorted in the same time as 10,000 records onthe old machine. If the algorithm’s growth r<strong>at</strong>e is gre<strong>at</strong>er than cn, such as c 1 n 2 ,then you will not be able to do a problem ten times the size in the same amount oftime on a machine th<strong>at</strong> is ten times faster.How much larger a problem can be solved in a given amount of time by a fastercomputer? Assume th<strong>at</strong> the new machine is ten times faster than the old. Say th<strong>at</strong>the old machine could solve a problem of size n in an hour. Wh<strong>at</strong> is the largestproblem th<strong>at</strong> the new machine can solve in one hour? Figure 3.3 shows how largea problem can be solved on the two machines for five of the running-time functionsfrom Figure 3.1.This table illustr<strong>at</strong>es many important points. The first two equ<strong>at</strong>ions are bothlinear; only the value of the constant factor has changed. In both cases, the machineth<strong>at</strong> is ten times faster gives an increase in problem size by a factor of ten. In otherwords, while the value of the constant does affect the absolute size of the problemth<strong>at</strong> can be solved in a fixed amount of time, it does not affect the improvement inproblem size (as a proportion to the original size) gained by a faster computer. Thisrel<strong>at</strong>ionship holds true regardless of the algorithm’s growth r<strong>at</strong>e: Constant factorsnever affect the rel<strong>at</strong>ive improvement gained by a faster computer.An algorithm with time equ<strong>at</strong>ion T(n) = 2n 2 does not receive nearly as gre<strong>at</strong>an improvement from the faster machine as an algorithm with linear growth r<strong>at</strong>e.Instead of an improvement by a factor of ten, the improvement is only the square

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!