---
title: 'What''s an Algorithm? — David J. Malan'
source: 'https://youtube.com/watch?v=6hfOvs8pY1k'
video_id: '6hfOvs8pY1k'
date: 2026-07-29
duration_sec: 297
---

# What's an Algorithm? — David J. Malan

> Source: [What's an Algorithm? — David J. Malan](https://youtube.com/watch?v=6hfOvs8pY1k)

## Summary

The video explains what an algorithm is using the example of counting people in a room. It demonstrates how algorithms are sets of instructions that can be optimized for efficiency and must handle corner cases. The speaker walks through pseudocode for counting, from a simple loop to a faster but buggy approach, and finally a corrected version.

### Key Points

- **Definition of Algorithm** [00:15] — An algorithm is a set of instructions, typically executed by computers.
- **Counting People Example** [00:28] — The example of counting people in a room illustrates how algorithms work.
- **Pseudocode for Basic Algorithm** [00:43] — Initialize n to 0, then for each person, increment n by 1.
- **Algorithm Works for Two People** [01:54] — For two people, the algorithm correctly yields n=2.
- **Corner Case: Empty Room** [02:09] — If the room is empty, the loop doesn't execute, and n remains 0, which is correct.
- **Faster Algorithm: Counting by Twos** [02:39] — Instead of counting one by one, count by pairs: set n=n+2 for each pair, doubling speed.
- **Bug: Odd Number of People** [03:20] — For one person, the pair algorithm fails (n=0), indicating a bug.
- **Fix with Condition** [03:48] — Add a conditional step: if one person remains, increment n by 1 after counting pairs.
- **Generalization of Algorithms** [04:14] — Algorithms can be extended to count in larger groups, but at the core, they are just sets of instructions.

### Conclusion

Algorithms are fundamental to computing, and the video shows how even simple counting algorithms can be refined for efficiency and correctness, highlighting the importance of careful design.

## Transcript

Translator: Andrea McDonough Reviewer: Jessica Ruby
an algorithm is a set of instructions Typically, algorithms are executed by computers, For instance, how would you go about counting
you probably point at each person, 1, 2, 3, 4 and so forth. a bit more formally in pseudocode,
Let n equal 0. For each person in room, set n = n + 1. a variable called n
This just means that at the beginning of our algorithm, After all, before we start counting, Calling this variable n is just a convention.
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.
So, what the pseudocode is saying we'll increase n by 1. Well, let's bang on it a bit.
In line 1, we initialize n to zero. we then increment n by 1. on the second trip through that same loop,
And so, by this algorithm's end, n is 2, How about a corner case, though? besides me, who's doing the counting.
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?
Instead of counting 1, 2, 3, 4, 5, 6, 7, 8, and so forth, It even sounds faster, and it surely is.
Let n equal zero. set n = n + 2. Rather than count people one at a time,
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.
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,
which indeed matches the number of people in the room. How does this algorithm fair? For a pair of those people,
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
Let n equal zero. set n = n + 2. set n = n + 1.
we've introduced in line 4 a condition, that only executes if there is one person So now, whether there's 1 or 3
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,
algorithms are just a set of instructions These were just three. What problem would you solve with an algorithm?
