<p>Do I understand correctly that you're teaching kids already that have not yet learned any programming? And that you are trying to teach them algorithms?</p>

<p>I would not focus on a programming language at all; they are not ready to implement algorithms yet in actual code.  Instead, I would focus on Computational Thinking.  Let them act out various approaches to solving a problem and turn them into recipes.</p>

<p>I would look at <a href="https://cseducators.stackexchange.com/q/2612/27">ice-breaker games</a> and at resources for Computational thinking for nice, active learning ideas to get at algorithms without all of the cumbersome programming at the start.</p>

CC BY-SA 4.0
2019-09-29T09:45:30.433Z
Well the course is not intended for kids : it's for high school graduates who will start learning computing ;)
alk01771
CC BY-SA 4.0
2019-09-29T12:56:36.000Z
Oh dear. I completely missed the "don't know programming" part in my first version of the answer. I've tried to recover.
Buffy
CC BY-SA 4.0
2019-09-29T13:59:23.177Z
@alk01771 That age group still loves to move around. I teach them just 2 months before you get them :)
Ben I.
CC BY-SA 4.0
2019-09-29T02:58:41.390Z
2019-09-29T02:58:41.390Z
Ben I.
<p>I think this is hard to do in four days. You can barely touch the surface. I think that the most you can likely do is give them an appreciation for why the study of algorithms is useful and important. </p>

<p>There is one general sort of algorithm that is "easy" to carry out before students learn to program: Linear Recursion. There are many such problems. The basic idea is that one student "plays" the base case in the recursion and others "play" the recursive case. A simple example is counting the length of a list. The base case, when asked "how many" replies "one". The others, when asked "how many" pass the same message to the student in line to their left and if told, say, five, by that student, replies six. The professor lines up the student and asks the first student "how many". If it happens to go to the base case, the prof gets "one", but otherwise the message gets passed down and reflected by the "base case" and (after a lot of noise" gets back the length of the list. </p>

<p>A similar thing can be done. I've held "choir practice" with a bunch of students where each student has a script. The overall script is to recite <a href="https://en.wikipedia.org/wiki/There_Was_an_Old_Lady_Who_Swallowed_a_Fly" rel="nofollow noreferrer">"There was an old lady who swallowed a fly"</a>, which you can find on the net. </p>

<p>I've also had success with Matryoshka. How do you "paint" a Matryoshka? You can "apply color" to a given figure before the recursion or after. You can even "apply" color to the bottom on the winding phase and to the top on the unwind. The recursion is either (winding phase) "apply color, pass paint" or (unwinding phase) "pass paint, apply color". The base case just applies color and returns. This is an important lesson for students, that you can "do work" in a recursion on both the winding and unwinding phase. Some students miss this essential idea. </p>

<hr>

<p>Another general area that can be explored prior to learning programming is the idea of sorting and what is required to do it. There are a lot of subtleties that are usually glossed over but that can be explored before you even start to program. For example "How do you sort the numbers 1 through 10 numerically". Answer, you don't. They are  already sorted. </p>

<p>You can ask "Why do we want to sort?". Connecting it to the search problem and a real-world scenario and maybe even binary search. </p>

<p>Another subtle issue is the distinction between the size of the multiset (bag) that you are sorted and the size of the set of values from which they are drawn. For example, sorting a list of int or long values can always be done in linear time (linear in the size of the bag, length of the list). This is because the collection of expressible long values is finite. See Radix Sort for example. In general, sorting (mathematical) integer values is harder, since the set of integers is infinite even when the bag to be sorted is finite. Radix sort can be carried out by a group of student "actors", if you either discuss binary representations, OR, adapt the algorithm of a <a href="https://en.wikipedia.org/wiki/IBM_card_sorter" rel="nofollow noreferrer">mechanical sorting machine</a> to use human actors. </p>

<p>Another fun thing to do with sorting is to try to have a competition for the least efficient sorting algorithm anyone can come up with. I can think of some doozies that are either extremely inefficient in space or in time. I have a completely infeasible sorting algorithm that is linear in time but requires too much space. Other inefficient (in time) algorithms are possible. For example, randomize the list and then check. Repeat until sorted. If you have a truly random number generator this is guaranteed to halt (law of large numbers in probability). There are a lot of possibilities. </p>

<hr>

<p>In my first reading of the question here, I somehow completely missed the fact that the students didn't know anything about programming (oh my). If they do, then the following might be appropriate, but they would be hard to do otherwise. </p>

<p>One "interesting" algorithm is just Huffman Encoding. How do you minimize the number of bits sent to encode a message using an alphabet with a given frequency of use. There are several things that need to be discussed here, including the economics of data transmission. "Less is More". Then there is the question of the alphabet and its characteristics <em>in use</em>. See Poe's <em>The Gold Bug</em> for a discussion that is actually incorrect, but interesting and has the right idea if the wrong numbers. Don't be naive and try to use the distribution of the message itself as the source of statistics on the alphabet. It can't work. </p>

<p>Next you need to discuss tree structures, etc, and the bit encoding of the message, including the need to be able to separate the message into discrete characters, since the encoding doesn't use the same number of bits for each character (the essence of the problem, actually). </p>

<p>Note also that even a naive but accurate distribution provides <em>some</em> improvement. Huffman is optimal for a given distribution. So, discuss optimization, as opposed to satisfaction. </p>

<p>Now you need to discuss and maybe implement both the encoding and the decoding algorithms. </p>

<p>Then you can discuss space time tradeoffs. We trade time (for encoding/decoding) for space (bits sent). </p>

<p>An "overnight" thought experiment for the students: Why can't you use the message itself to determine the distribution? It takes a bit of thought and may be obvious or not. But a long discussion here previously showed why it can't work. </p>

<p>You could even spend a bit of time on the difference between linear scanning of a set of data and searching through a tree that has been previously constructed.  This could get you close to something like binary search to put a "future work" idea in their minds. </p>

<p>There are other similar examples. The key is a problem in which the naive solution (same number of bits per character) can be improved (fewer bits for common characters), then showing how to develop the algorithm to do the improvement. </p>

<p>One problem I find magical is the <a href="https://cseducators.stackexchange.com/a/4868/1293">Dutch National Flag</a> as discussed at the link and the book by Gries. A linear time sorting algorithm for a restricted kind of data. Since DNF only involves an array and a few index variables, it can be done with students as "actors" representing the Red, White, and Blue values. A few other actors (index values) point at the corresponding "slot" in the array to keep track of the algorithm as it progresses. </p>

<p>I think other algorithms that use an array or list can be handled similarly, but it is probably necessary to stick to linear running time algorithms. That is just because time is limiting and little insight can be gained if the thing is too complex or takes so much time that the details obscure the main points. </p>

CC BY-SA 4.0
2019-09-28T21:02:48.763Z
Thank you. I'm a little bit surprised and skeptical about teaching the Huffman coding before data structures. Do you have a more complete blueprint ?
alk01771
CC BY-SA 4.0
2019-09-28T23:09:37.503Z
I'm surprised you are teaching algorithms before data structures, actually. Huffman is pretty standard. There is a lot of information you can find, I think.
Buffy
CC BY-SA 4.0
2019-09-28T20:02:08.323Z
2019-09-29T14:12:48.323Z
2019-09-29T14:12:48.323Z
Buffy
<p>A loaf of bread, a knife, a jar of peanut butter and a jar of jelly.  Write an algorithm to build a PB&amp;J.  Have one of the kids follow the literal direction written by a different kid.  This project have been a favorite starter for algorithms for 30 years.</p>

CC BY-SA 4.0
2019-10-30T14:36:37.917Z
A classic, of course. But mostly for the fact that such descriptions of process are too often lacking. What "isn't" an algorithm is a valuable lesson. Tie your shoelaces is even worse. I think.
Buffy
CC BY-SA 4.0
2019-10-30T13:56:56.577Z
2019-10-30T13:56:56.577Z
Garth Flint
<p>A crowd favorite of the Beauty and Joy of Computing (BJC) course from Dan Garcia and many other creative leaders:</p>

<p>Each group of 4 students gets a deck of shuffled playing cards. Groups race the clock to deliver the deck in sorted order, ace to king within suits, suits alphabetically. BJC uses that activity first.</p>

<p>I had interesting results one year using that activity later in the semster, and modifying it: each group gets two distinguishable decks shuffled together, one of them missing a card. Race the clock to identify the card I retained from your group.</p>

<p>Either way, athe key is the post-race discussion. What algorithm did your group follow? What is the best algorithm? Does the answer to the previous question depend on how well the deck is shuffled? Does it depend on which card is missing? Nice tie ins available to complexity and worst case time efficiency.</p>

CC BY-SA 4.0
2019-11-29T03:19:07.397Z
2019-11-29T03:19:07.397Z
Bennett Brown
<p>I will teach algorithms for 4 days for some students. It will be their first course in computer science before learning coding with Java.</p>

<p>My fear is to bore them as I was bored at the university :(</p>

<p>Is there a fun way to teach algorithms ?</p>

CC BY-SA 4.0
2019-09-28T19:16:48.567Z
Why were you bored? Four days seems not much for a deep topic. Say something about the students and what they know. How much of algorithms? Examples only? Analysis? Taxonomy? Fun for whom?
Buffy
CC BY-SA 4.0
2019-09-28T19:35:08.467Z
I was bored because it seemed far for real world applications.
My students are 18 and are about to start learning computer science. They have never learned algorithms. So I'm trying to find a fun way to teach them that topic.
alk01771
CC BY-SA 4.0
2019-09-29T05:37:56.843Z
A perfect funny approach to algorithms would be the famous Hungarian dances for sorting algorithms, which you can find on YouTube!
csabinho
CC BY-SA 4.0
2019-09-29T14:14:58.007Z
Start here for Hungarian Folk dancing: https://flowingdata.com/2011/04/14/sorting-algorithms-demonstrated-with-hungarian-folk-dance/
Buffy
CC BY-SA 4.0
2019-10-29T23:11:03.410Z
I do sorting and searching using cards.You need to ensure that you have enough, and that you don't have a simple sequence (or the students will choose other algorithms, that don't otherwise make sense).
ctrl-alt-delor
<algorithms>
Fun way to teach algorithms
# Fun way to teach algorithms

(Asked by: username_0 on 2019-09-28)

I will teach algorithms for 4 days for some students. It will be their first course in computer science before learning coding with Java.

My fear is to bore them as I was bored at the university :(

Is there a fun way to teach algorithms ?

**Tags:** algorithms

> **Comments:**
> **username_1**: Why were you bored? Four days seems not much for a deep topic. Say something about the students and what they know. How much of algorithms? Examples only? Analysis? Taxonomy? Fun for whom?  
> **username_0**: I was bored because it seemed far for real world applications. My students are 18 and are about to start learning computer science. They have never learned algorithms. So I'm trying to find a fun way to teach them that topic.  
> **username_2**: A perfect funny approach to algorithms would be the famous Hungarian dances for sorting algorithms, which you can find on YouTube!  
> **username_1**: Start here for Hungarian Folk dancing: https://flowingdata.com/2011/04/14/sorting-algorithms-demonstrated-with-hungarian-folk-dance/  
> **username_3**: I do sorting and searching using cards.You need to ensure that you have enough, and that you don't have a simple sequence (or the students will choose other algorithms, that don't otherwise make sense).  

---

## 4 answers

### Answer by username_1 on 2019-09-28. Score: 3

I think this is hard to do in four days. You can barely touch the surface. I think that the most you can likely do is give them an appreciation for why the study of algorithms is useful and important.

There is one general sort of algorithm that is "easy" to carry out before students learn to program: Linear Recursion. There are many such problems. The basic idea is that one student "plays" the base case in the recursion and others "play" the recursive case. A simple example is counting the length of a list. The base case, when asked "how many" replies "one". The others, when asked "how many" pass the same message to the student in line to their left and if told, say, five, by that student, replies six. The professor lines up the student and asks the first student "how many". If it happens to go to the base case, the prof gets "one", but otherwise the message gets passed down and reflected by the "base case" and (after a lot of noise" gets back the length of the list.

A similar thing can be done. I've held "choir practice" with a bunch of students where each student has a script. The overall script is to recite ["There was an old lady who swallowed a fly"](https://en.wikipedia.org/wiki/There_Was_an_Old_Lady_Who_Swallowed_a_Fly), which you can find on the net.

I've also had success with Matryoshka. How do you "paint" a Matryoshka? You can "apply color" to a given figure before the recursion or after. You can even "apply" color to the bottom on the winding phase and to the top on the unwind. The recursion is either (winding phase) "apply color, pass paint" or (unwinding phase) "pass paint, apply color". The base case just applies color and returns. This is an important lesson for students, that you can "do work" in a recursion on both the winding and unwinding phase. Some students miss this essential idea.

---

Another general area that can be explored prior to learning programming is the idea of sorting and what is required to do it. There are a lot of subtleties that are usually glossed over but that can be explored before you even start to program. For example "How do you sort the numbers 1 through 10 numerically". Answer, you don't. They are already sorted.

You can ask "Why do we want to sort?". Connecting it to the search problem and a real-world scenario and maybe even binary search.

Another subtle issue is the distinction between the size of the multiset (bag) that you are sorted and the size of the set of values from which they are drawn. For example, sorting a list of int or long values can always be done in linear time (linear in the size of the bag, length of the list). This is because the collection of expressible long values is finite. See Radix Sort for example. In general, sorting (mathematical) integer values is harder, since the set of integers is infinite even when the bag to be sorted is finite. Radix sort can be carried out by a group of student "actors", if you either discuss binary representations, OR, adapt the algorithm of a [mechanical sorting machine](https://en.wikipedia.org/wiki/IBM_card_sorter) to use human actors.

Another fun thing to do with sorting is to try to have a competition for the least efficient sorting algorithm anyone can come up with. I can think of some doozies that are either extremely inefficient in space or in time. I have a completely infeasible sorting algorithm that is linear in time but requires too much space. Other inefficient (in time) algorithms are possible. For example, randomize the list and then check. Repeat until sorted. If you have a truly random number generator this is guaranteed to halt (law of large numbers in probability). There are a lot of possibilities.

---

In my first reading of the question here, I somehow completely missed the fact that the students didn't know anything about programming (oh my). If they do, then the following might be appropriate, but they would be hard to do otherwise.

One "interesting" algorithm is just Huffman Encoding. How do you minimize the number of bits sent to encode a message using an alphabet with a given frequency of use. There are several things that need to be discussed here, including the economics of data transmission. "Less is More". Then there is the question of the alphabet and its characteristics *in use*. See Poe's *The Gold Bug* for a discussion that is actually incorrect, but interesting and has the right idea if the wrong numbers. Don't be naive and try to use the distribution of the message itself as the source of statistics on the alphabet. It can't work.

Next you need to discuss tree structures, etc, and the bit encoding of the message, including the need to be able to separate the message into discrete characters, since the encoding doesn't use the same number of bits for each character (the essence of the problem, actually).

Note also that even a naive but accurate distribution provides *some* improvement. Huffman is optimal for a given distribution. So, discuss optimization, as opposed to satisfaction.

Now you need to discuss and maybe implement both the encoding and the decoding algorithms.

Then you can discuss space time tradeoffs. We trade time (for encoding/decoding) for space (bits sent).

An "overnight" thought experiment for the students: Why can't you use the message itself to determine the distribution? It takes a bit of thought and may be obvious or not. But a long discussion here previously showed why it can't work.

You could even spend a bit of time on the difference between linear scanning of a set of data and searching through a tree that has been previously constructed. This could get you close to something like binary search to put a "future work" idea in their minds.

There are other similar examples. The key is a problem in which the naive solution (same number of bits per character) can be improved (fewer bits for common characters), then showing how to develop the algorithm to do the improvement.

One problem I find magical is the [Dutch National Flag](https://cseducators.stackexchange.com/a/4868/1293) as discussed at the link and the book by Gries. A linear time sorting algorithm for a restricted kind of data. Since DNF only involves an array and a few index variables, it can be done with students as "actors" representing the Red, White, and Blue values. A few other actors (index values) point at the corresponding "slot" in the array to keep track of the algorithm as it progresses.

I think other algorithms that use an array or list can be handled similarly, but it is probably necessary to stick to linear running time algorithms. That is just because time is limiting and little insight can be gained if the thing is too complex or takes so much time that the details obscure the main points.

> **Comments:**
> **username_0**: Thank you. I'm a little bit surprised and skeptical about teaching the Huffman coding before data structures. Do you have a more complete blueprint ?  
> **username_1**: I'm surprised you are teaching algorithms before data structures, actually. Huffman is pretty standard. There is a lot of information you can find, I think.  

---

### Answer by username_5 on 2019-10-30. Score: 3

A loaf of bread, a knife, a jar of peanut butter and a jar of jelly. Write an algorithm to build a PB&J. Have one of the kids follow the literal direction written by a different kid. This project have been a favorite starter for algorithms for 30 years.

> **Comments:**
> **username_1**: A classic, of course. But mostly for the fact that such descriptions of process are too often lacking. What "isn't" an algorithm is a valuable lesson. Tie your shoelaces is even worse. I think.  

---

### Answer by username_6 on 2019-11-29. Score: 2

A crowd favorite of the Beauty and Joy of Computing (BJC) course from Dan Garcia and many other creative leaders:

Each group of 4 students gets a deck of shuffled playing cards. Groups race the clock to deliver the deck in sorted order, ace to king within suits, suits alphabetically. BJC uses that activity first.

I had interesting results one year using that activity later in the semster, and modifying it: each group gets two distinguishable decks shuffled together, one of them missing a card. Race the clock to identify the card I retained from your group.

Either way, athe key is the post-race discussion. What algorithm did your group follow? What is the best algorithm? Does the answer to the previous question depend on how well the deck is shuffled? Does it depend on which card is missing? Nice tie ins available to complexity and worst case time efficiency.


---

### Answer by username_4 on 2019-09-29. Score: 1

Do I understand correctly that you're teaching kids already that have not yet learned any programming? And that you are trying to teach them algorithms?

I would not focus on a programming language at all; they are not ready to implement algorithms yet in actual code. Instead, I would focus on Computational Thinking. Let them act out various approaches to solving a problem and turn them into recipes.

I would look at [ice-breaker games](https://cseducators.stackexchange.com/q/2612/27) and at resources for Computational thinking for nice, active learning ideas to get at algorithms without all of the cumbersome programming at the start.

> **Comments:**
> **username_0**: Well the course is not intended for kids : it's for high school graduates who will start learning computing ;)  
> **username_1**: Oh dear. I completely missed the "don't know programming" part in my first version of the answer. I've tried to recover.  
> **username_4**: @username_0 That age group still loves to move around. I teach them just 2 months before you get them :)  

---

