[00:00] Translator: Andrea McDonough Reviewer: Jessica Ruby [00:15] an algorithm is a set of instructions Typically, algorithms are executed by computers, For instance, how would you go about counting [00:28] you probably point at each person, 1, 2, 3, 4 and so forth. a bit more formally in pseudocode, [00:43] Let n equal 0. For each person in room, set n = n + 1. a variable called n [00:57] This just means that at the beginning of our algorithm, After all, before we start counting, Calling this variable n is just a convention. [01:10] Now, line 2 demarks the start of loop, So, in our example, the step we're taking which describes exactly how we'll go about counting. [01:25] So, what the pseudocode is saying we'll increase n by 1. Well, let's bang on it a bit. [01:40] In line 1, we initialize n to zero. we then increment n by 1. on the second trip through that same loop, [01:54] And so, by this algorithm's end, n is 2, How about a corner case, though? besides me, who's doing the counting. [02:09] This time, though, line 3 doesn't execute at all which indeed matches the number of people in the room. But counting people one a time is pretty inefficient, too, no? [02:25] Instead of counting 1, 2, 3, 4, 5, 6, 7, 8, and so forth, It even sounds faster, and it surely is. [02:39] Let n equal zero. set n = n + 2. Rather than count people one at a time, [02:51] This algorithm's thus twice as fast as the last. Does it work if there are 2 people in the room? For that one pair of people, we then increment n by 2. [03:06] which indeed matches the number of people in the room. In line 1, we initialize n to zero. since there aren't any pairs of people in the room, [03:20] which indeed matches the number of people in the room. How does this algorithm fair? For a pair of those people, [03:34] There isn't another full pair of people in the room, And so, by this algorithm's end, Indeed this algorithm is said to be buggy [03:48] Let n equal zero. set n = n + 2. set n = n + 1. [04:02] we've introduced in line 4 a condition, that only executes if there is one person So now, whether there's 1 or 3 [04:14] this algorithm will now count them. Well, we could count in 3's or 4's or even 5's and 10's, At the end of the day, [04:27] algorithms are just a set of instructions These were just three. What problem would you solve with an algorithm?