To Make a Program you Have to Break Some Eggs

| |

One of my favorite toys in computer science are plastic eggs. Cheap and they can be used to teach so many things. We are working on searches and sorts in the APCS class right now. They also work well when doing algorithms in the CS Principles class.

To start with searches and sorts I use plastic eggs filled with fish tank gravel. Email your faculty and parents - I guarantee you can get these for free. Fill the eggs with varying amount of gravel and tape them shut. Better yet have a kid do this. You are busy.




I let the kids pick a partner and each pair gets 6 or 7 eggs. Please do not forget to explain that the eggs do not have candy in them. I didnt do that the first time we did this and it made for a very disappointing mess.

Have them put the eggs in a row then "search" for the heaviest egg. Write out the steps you followed.

On the board I then do:

int eggs[] = new int[6];

This is in the APCS class, in CS Principles I make this less formal since they will be doing this in Scratch.

I have the kids come to the board and write out their algorithm, in Java in the APCS, pseudocode in CS Pricniples, using this array. Bam! They just all created a Linear Search.

So, why eggs?

I used to do this writing numbers on the board. They watched and I did. It is always better when THEY do. They are going to remember the Linear Search much better if it was their idea in the first place. 

Also, when you do numbers the amazing processor that is the human brain can just scan the list and pick the biggest. No problem. 

But a computer cannot do that - it cannot just look at a data set in aggregate and pick one. It must "touch" every piece of data in the set and make a comparison. Which is exactly what the kids do with the eggs. Point that out, they should know that.

This is also a good time to go over swapping. They get so confused on this.

How many times have you had them try to swap two numbers and they do:

a = b;
b = a;

Here is the fix: Hand each group some cups - make it look like you are giving them an arbitrary number, but make sure they all get at least 3.

Rule - you can only have an egg in a cup. NEVER can you have two eggs in a  cup. Now swap two eggs.

Again, once they get the point of using a third cup, you have them write out the algorithm in the language of your choice.

Related Posts by Categories

0 komentar:

Posting Komentar