Classifying Algorithms

BH and MF: keep page appended to end of 5.1.2 (page 3) with some yellowboxing the whitetext; drop #3-5; keep #7 and 6 in reversed order (need to say "unreasonable for large inputs"

Brian, after we review my changes below, we should address both of these:

PG: Scrap. If AP still requires it, we must, but I'm not in love with this.

BH: Item 87 of isn't a great example, even though true, because the time depends on how the list was constructed. Also, add n log n.

MF: so much text; I think we are overdoing this idea. Much could be yellowboxed.

On this page, you will learn that some correct algorithms take too long to be practical.

  1. This feels repetitive even though the task actually isn't. --MF, 3/11/19
    If it isn't already open, load the project U5L3-timer from the previous page. You will be experimenting with time function with each of these input functions: For each one, what happens to the running time if you double the size of the input?
    What does it mean to double the size of the input for numbers from () to ()?

You can classify algorithms by the amount of time they take to run.

  1. Click here to load this file. Then save it to your Snap! account.
    Use the list from () to () 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. 1000 numbers starting from ()
    2. all () digit numbers

I want to put the two definitions in vocab box(es) and to yellowbox-hint all the efficiency categories. --MF, 9/26/18

BH and MF agreed to focus on polynomial vs. exponential and on clarifying what exponential means (since many people get it wrong), and then to say, oh BTW, the college board calls this reasonable and unreasonable. --MF, 3/22/19

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

This feels more important than we are giving time for. --MF, 3/11/19
It's important to recognize that an unreasonable-time algorithm still solves a problem correctly. Unreasonable-time algorithms can sometimes be replaced by heuristics, which are polynomial-time algorithms that don't solve the problem exactly, but give a good enough approximation.
Yellowbox-Hint this too. --MF, 9/26/18

One reason it's worth learning these categories is that in writing programs, you often need to solve a problem for which there are already established solutions. For example, you've learned that searching for something in an unordered list takes linear time, but if the list is sorted, you can search it faster (in sublinear time). So when you're writing a program that needs to search through a list repeatedly, you'll know that it's worthwhile to sort the list before the searching. Knowing about standard algorithms that already exist can help you construct new algorithms.

    No one is going to do this. We need more direction. --MF, 3/11/19
  1. Look at some algorithms you've built. Determine whether each algorithm runs in constant time, sublinear time, linear time, quadratic time, or unreasonable time.
    Need to decide what to do here since the graphing labs are being replaced. --MF, 3/11/19
  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?
Do we need all the commented out content here and elsewhere on this page? --MF, 9/26/18
    I suggest swapping the order of these two problems so that the paragraph writing isn't lost and also so that idea is closer to the content about it (rather than having a big block of slightly less conected content in between. --MF, 3/11/19
  1. This question is similar to those you will see on the AP CSP exam.
    The table below shows the computer time it takes to complete various tasks on the data of different sized towns.

    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

    Based on the information in the table, which of the following tasks is likely to take the longest amount of time when scaled up for a city of population 1,000,000.
    Entering data
    Backing up data
    Searching through data
    Sorting data
  2. Write a paragraph explaining the difference between algorithms that run in a reasonable time and algorithms that require unreasonable time to run.