Classifying Algorithms

EK: 4.2.1A, 4.2.1B, 4.2.1C, 4.2.1D
Blue button feedback:
  1. If it isn't already open, load the project U5L3-timer from the previous page, and experiment with time function on algorithms you've built (such as alphie way, betsy way, factorial, find in unsorted list, find in sorted list, and any others you have handy). What happens to the running time if you double the size of the input?
You can classify algorithms by the amount of time they take to run. At a basic level, many problems can be solved in a reasonable time, while others cannot, even for small input sizes.
  1. Open this project, and use the list from A to B block to build the following two blocks in Snap!. Then, determine which block's algorithm can be executed in a reasonable time, and which cannot.
    The list of 2-digit numbers goes from 10 to 99. There's a math operations block that can give you powers of 10.
    1. list of 1000 numbers
    2. all N digit numbers

To classify an algorithm, look at the number of steps it takes to complete the algorithm, compared to the size of the input.

It's important to recognize that an unreasonable algorithm still solves a problem correctly! It just takes an unreasonably long time. Unreasonable algorithms can sometimes be replaced by heuristics, simpler algorithms that may not succeed in solving the problem exactly but give a reasonable approximation.
  1. Look at some algorithms you've built. Determine whether each algorithm runs in constant time, linear time, polynomial time, or unreasonable time.
  1. For Alphie's way of adding integers, create a graph with the number of integers on the horizontal and the runtime on the vertical. Generate data for the graph by running time function with large inputs to Alphie's way (say, multiples of 100). Then use the techniques from Lab 2 to plot the graph.
  2. What information does this graph tell you about Alphie's algorithm? Is it constant time, linear time, other polynomial time, or is it unreasonable time?