A batch record-sorting routine in a utility billing system uses a comparison sort whose running time grows as , where is the number of records. Sorting 100{,}000 records requires 0.42 s on the target processor. On the same processor, the time required to sort 800{,}000 records is most nearly:
- (A)3.36 s
- (B)3.97 s
- (C)26.9 s
- (D)31.7 s
Show worked solution
Answer: (B)
An eightfold increase in record count costs a factor of 9.44 in time, since the logarithmic factor grows too, and the sort runs about 3.97 s.
Runtime for a comparison sort is proportional to , so the unknown machine constant cancels when two problem sizes are compared as a ratio.
The record count rises by a factor of eight while the logarithmic factor rises only from to .
Scaling the measured 0.42 s by that factor gives the projected batch time.
FE Reference Handbook — Software Engineering: Algorithms, Algorithm Efficiency (Big-O Notation)
Why the other choices appear
- (A)Treats the growth as purely linear in , giving s and discarding the logarithmic factor.
- (C)Assumes quadratic growth , giving s.
- (D)Combines quadratic and logarithmic growth as , giving s.