Project ideas come from all sorts of places. Textbooks, other teachers I work with, blogs, random conversations, conferences (do you know about Nifty Assignments from SIGCSE?) and more. Some of the best come from students. Not always intentionally though. The other day I caught a student playing around on a website while I was lecturing. Apparently I wasn’t doing enough to hold his interest. The website converted letters to Morse Code and back again. There are probably many of these sites on the Internet. My first reaction was that this makes a good programming project. (Does that make me weird?) So we started talking about it as a class.
Student’s first reaction was “that’s hard” and “I don’t know Morse Code.” But of course it’s not really that hard to implement if you know how to use arrays. The tedious part is building an array to use for conversion.
Morse = ".-";
Morse = "-...";
Morse = "-.-.";
Morse = "-..";
I've decided to do that for my students. After all I want them to use the array not go crazy trying to build one.
Converting from ASCII letters to Morse Code using a string array like this is a simple and fast operation. Big O(1) for access. We’ve already done some work like this writing a program to count the number of times various letters occur in a string. Going the other way, from code to ASCII is a little harder.
In that case we have to do a search of some kind though the array. A simple sequential search is probably the easiest way to do things. I know there are other ways. We could create a hash which would probably be faster. Or a nice binary tree (see this method – Thanks to Rebecca Dovi for the link).
These methods would be more complicated though and this is a first programming class. So we’ll talk about other ways to do it and maybe in the AP Class they’ll implement something faster and/or more complicated.
We will have a good chance to talk about the various performance issues and the various ways that arrays can be searched. I’m looking forward to the discussion.