# Counting Steps – Intro to Algorithms

All right. Let’s try another little quiz, but this one is going to move our understanding forward a little bit more. Here’s a little bit of Python code. A subroutine called “countdown” takes an input x. It executes a statement, and then it goes into a while loop and repeats these two statements some number of times. Then when it’s all done, it does one more statement. We can take for any given input–like this print countdown 50– we could count up the time–the number of statements executed– for this to execute. It’s going to be something like this. We didn’t talk about the number of steps that it take to do a print statement if there’s a subroutine, but we’re going to call it one for the print statement plus however many steps it takes to execute the subroutine call. In these case, countdown 50–what is it going to do? There’s going to be 1 call there, 2 for each time that it counts down, which is going to be–what–10 times, right? It starts off at 50, going to go down by 5s until it hits 0. There is going to be 10 times that it’s executing these two statements. That’s 20–21, 22, and the print statement is 23. This–if we ask the time that this takes–is going to be 23 units. Here’s the trickier question. What if we just say we don’t know what n is. Someone is going to tell us n later. We’re like to know the number of steps, the amount of time that it takes to execute this formula, as a function of n. We can’t automatically grade a mathematical function–or maybe we can. The way that we’re going to score this quiz is instead of you telling me a mathematical expression for this function, I want you to actually give me a function that takes as input n and produces as output the number of time steps that it will take to execute countdown or this entire block of code here. We already figured out what happens when n is 50, but we want a general form of this.

## 2 thoughts to “Counting Steps – Intro to Algorithms”

1. kxrtiswithak says:

I hope brexit kicks you out

2. Zoalerix says:

bruh