Showing posts with label Big Idea - Algorithms. Show all posts
Showing posts with label Big Idea - Algorithms. Show all posts

Sunday, March 3, 2013

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 didn't 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.

Monday, February 11, 2013

Algorithms -Doing the Robot - Part 1


The CS Principles class just started Unit 4 - Algorithms this week. The intention is to teach them how to develop methods, and to use these methods to build algorithms.



In the class we are stuck with C++. There are good and bad things about this as a teaching language - I get a lot of strong opinions from folks about it. It is the language my county has chosen for this level of programming, so that is a debate for another day.

One benefit is the mechanics of creating a method are very similar to Java, and most of my students move on to take the APCS course.

Looking back over what we did last year overall they did learn the mechanics of methods. This is one of those topics that you teach, and you think they get it, and then three weeks later they have forgotten the whole business. For the current APCS course this is a big problem since the framework for most free response questions is a method.

On the other hand we got a bit too bogged down with C++ and didn’t spend enough time on algorithms. It is easy to do, I have taught C++ since it was the AP language over a decade ago and I have a ton of materials developed. As most people with small children know, February is flu/strep month so I was out a fair bit while we were covering this topic, and C++ worksheets make super sub-plans.

Algorithms are one of the core Big Ideas of CS Principles. The Learning Objectives that relate are:

LO 17: The student can develop an algorithm.
LO 21: The student can explain how programs implement algorithms.


These are being assessed though the Programming Portfolio. The Programming Portfolio item states that students must include "a description of the algorithms these programs implement". So at a minimum they need to be aware fo when they have developed an algorithm and articulate what it does.

You can find the full collection of CS Principles documents here. Many are still works in progress, but you can get a sense of where the course is going.

So this year I am trying to move beyond just teaching code and do more activities to build algorithmic thinking. More on that tomorrow.

Tuesday, March 6, 2012

Chalk Talk

We just finished Algorithms and methods last week. I focused on the connection between using methods in C++ and designing good algorithms to solve problems. This is a change, this year I introduced methods before we did if's and loops. My thinking is if the students start by using sub routines we don't have to undo bad habits later. So far it has gone very well.

We did BYOB - Scratch right before Winter Break to move from learning about the Internet to programming. Nice (and unplanned) side effect, it has made methods in C++ much easier for the students. I wish I had designed this nice transition. The reality was that day two of methods one of the kids turned around and yelled across the room "This isn't hard - it's just like all those blocks we did in Scratch before Christmas".
Well, duh.


Sidewalk Chalk

So the Friday before the test we had one of those days. Any public school teacher knows those days. I lost power to 1/3 of the lab (future reference the breaker box is in the boiler room, panel 4). And a mouse, four-legged kind. A very active mouse.

There is a point where no matter how beautiful your lesson plans are, you just have to dump and run. Kids were distracted and we really couldn't do our computer practice. So we went outside.

I borrowed some chalk and put the kids in teams of three. I gave each group a copy of the lab we'll do at the end of next unit. The lab has them design methods for a calendar program. They have to count the number of days left in a month, return the total number of days in a month, then using these they have to count the total number of days between two dates.

We haven't done if's or loops yet, so this is not something they could code in C++, but I was curious to see how they did. They each had to sketch out an algorithms they could use to find a solution.

The solutions were great. Every group figured out that they could use the first two methods in a loop to count the days. This is a program I have done in the past with students and they often struggle with this concept. I am curious to see if the coding is easier this year.

And the mouse is gone- I caught in a cup later that day and he was released back into the garden.

Friday, February 24, 2012

Sidewalk Chalk

Quote of the day: "It was one of those fight or flight things, and you can't fight a mouse." 12th grader explaining why he ran from a mouse.

We had a four legged mouse in the lab today, tiny and cute, but it's gotta go. The kids have already named it Billy and want to keep it.

Considering this week started with 7 inches of snow and today it is 80 degrees they have been a bit off the walls, even without rodents.



So, for the CS Principles class we went outside today. We've been working on Algorithm design (Big Idea # 4). To work on this we did sidewalk art. each team was given a copy of a lab we will program in C++ next month, and using pseudo-code they had to plan out a solution. We haven't done ifs or loops in C++ yet, but they all came up with a correct algorithm for solving the problem.

We started this fall with BYOB Scratch, and they seem to be doing much better this year with using methods in designing their programs. They all got exactly how to call existing methods to find the solution. I am looking forward to seeing if how their labs compare to previous year's students after drawing out their plans.

Friday, October 28, 2011

Simon Says - Recursion!

Spotted this today - they are reissuing Simon Says. The interface reminds me a lot of the Siftables that were designed at MIT. 

Not only are these just plain awesome, the old Simon Says game is a great way t teach the concept of recursion. Can you say QUEUE?


 

Friday, August 12, 2011

Lightbot

This online game moves students through basic commands, functions, conditionals and recursion. Easy interface and a great simple introduction to the concepts of programming.





  • LightBot