8.14. Estimating With Big-O¶
We can use Big-O categories to do an estimation of how long a problem will take to solve based on a smaller version of the problem. We simply need to set up a proportion like the one below and solve it:
The key is to remember that the work does not necessarily equal the size of the problem. Instead, we have to use the size of the problem and the Big-O of the algorithm we are applying to calculate the approximate amount of work.
For example, say we have a list of 1000 things…
If we want to do a Binary Search, the Big-O is
. That means the estimated work would be or ~9.9657 units of work.If we want to do a Linear Search, the Big-O is
. That means the estimated work would just be 1,000 units of work.If we want to do a Selection Sort, the Big-O is
. That means the estimated work would be or 1,000,000 units of work.
Note
You can use Wolfram Alpha website to calculate log base 2 by typing something like “log2(1024)”. Try it below.
Sample Problem 1
I have timed selection sort on 10,000 items and it takes 0.243 seconds. I want to estimate the time it will take to sort 50,000 items. Because selection sort is an
So…
Cross multiplying gives:
Solving for time for job 2 gives:
Sample Problem 2
I have timed linear search on 10,000,000 items and it takes 8.12 seconds (call this job 1). I want to estimate the time it will take to use binary search instead (job 2). The problem sizes are the same for both jobs: 10,000,000 items. However, the algorithms will require different amounts of work. Linear search is a
So…
Cross multiplying gives:
Solving for time for job 2 gives:
Significantly faster!