block included in your project, and time it for various starting numbers.| Starting Number | 25,000 integers Time |
|---|---|
| 1000 | |
| 10,000 | |
| 100,000 | |
| 1,000,000 | |
| 10,000,000 |
sort block uses an "insertion sort" algorithm.
block included in your project, and time it for each length list.| Length of List | Sort Time |
|---|---|
| 10 | |
| 100 | |
| 1000 |
You can classify algorithms by the amount of time they take to run.
linear search. Confirm that multiplying the list length by ten roughly multiplies the time taken by ten (linear time).binary search. Confirm that the search time for each word list is less than for linear search (sublinear time).25,000 integers. Confirm that it takes about the same amount of time regardless of the input (constant time).sort. Confirm that multiplying the list length by ten roughly multiplies the time taken by one hundred (quadratic time).The difference between linear search and binary search can be very important if you're searching in a list of ten million items, but the most important difference in algorithm efficiency is between polynomial time (proportional to any power of the input size) and exponential time.
In an exponential time algorithm, just adding 1 to the input size (n) of a 2n time algorithm doubles the number of steps! So, for example, if the input size is 20, any polynomial time algorithm will be fast enough, but an exponential time algorithm might take many years to finish.

One reason it's worth learning these categories is to avoid reinventing the wheel. For example, you've learned that if a list is sorted you can search it in sublinear time using binary search. So when you're writing a program that needs to search through a list repeatedly, it's worthwhile to sort the list before searching. Knowing about algorithms that already exist can help you construct new algorithms.
All of the algorithms you've explored so far in this lab (linear search; binary search; 25,000 integers; and sort) are reasonable time algorithms. The following optional activity is an example of an exponential time algorithm.
A problem that may be familiar that requires an exponential time algorithm is computing any given element of Pascal's Triangle. In Pascal's Triangle, each number is found by adding the two numbers above it. For example, 4 + 6 = 10 and 15 + 6 = 21 as shown below. The first and last number of each row, which don't have two numbers above them are 1.
block included in your project, and time it for various inputs.| Inputs | Pascal's Triangle Time |
|---|---|
| 5, 2 | |
| 10, 5 | |
| 15, 7 | |
| 20, 10 | |
| 25, 12 |
pascals triangle that matters. (The position input is only given so you get a time for one of the positions near the middle of the row, which take longer to compute.)These row inputs are very small compared to the input size for the linear search, binary search, and sort algorithms, and yet the time required for pascals triangle is much higher. Your computer probably can't do much past 25.
| Task | Small Town (population 1,000) |
Mid-sized Town (population 10,000) |
Large Town (population 100,000) |
|---|---|---|---|
| Entering Data | 2 hours | 20 hours | 200 hours |
| Backing up Data | 0.5 hours | 5 hours | 50 hours |
| Searching through Data | 5 hours | 15 hours | 25 hours |
| Sorting Data | 0.01 hour | 1 hour | 100 hours |