31

I think this is a problem where the answer is partly in the prevention. I've observed many classes where printing is the method used to access the results of calculations for several weeks, both within functions and within main(). Then, return values of functions are suddenly introduced, but, they only serve to pass the result to main to be printed once ...


30

Here's an analogy that I've used for several years, and that students seem to understand. It doesn't focus on the rules, but why we have public and private and protected. "Most of you know that I live down at the beach. If you find yourself riding past my house, and it's hot outside, you might come to my front door, knock and ask if you could have a soda. I ...


22

The Tower of Hanoi was one of the first ways that I encountered recursion. "The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules: Only one disk can be moved at a time. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e. a disk can only be moved ...


22

If I catch it quickly and can easily explain the error, I use it as an example of failing up. "Ooops, look at me, here's my mistake, here's how I can learn from it." If students catch it, and I'm not immediately sure who is right, I make a note to do some research and come back to it in the next class. If I don't realize it until class is over, I make sure ...


21

I once had to implement a limited undo function (undo changes to the current field, or addition/deletion of records). The lists of undo deltas (one for field changes and one for records) were stored as stacks.


18

I think that this problem is pretty widespread, actually. I believe that it comes from a misunderstanding of the difference between what the program/computer can know/do and what the person operating it can know/do. I think the problem is worse for interactive systems where the printf sends its output to the screen in front of the person running the program. ...


17

Can't claim it's my own idea but I can embellish it a little... Imagine you are entering a cinema. You sit down in a row but realise you had to sit in row 20. Being a lazy computer scientist in an already full theatre of other computer scientists (they're all there watching War Games again) you decide to recursively determine your row. You ask the person ...


15

I like to use something that a student can connect with and something that they have to deal with regularly. You could choose any recursive everyday activity, but I like to choose revising an essay. Let's say you've already written your essay, and now you want to go back and perfect it. First you read the essay again, then you get feedback from others, then ...


15

A rather interesting analogy is that of a firearms magazine. if we look at this picture: It is easy to see that bullets can be inserted from the top, and only the topmost bullet is accessible. Such is a stack. A magazine works by LIFO (Last In First Out), and so does a Stack. Furthermore, the four (five1) basic operations of a Stack are applicable: ...


14

The image that I kept in my head when I was learning recursion was from Dr. Seuss:


14

A stack of trays in a cafeteria. I also like the pole of rings analogy. With the trays, you can pop (take a tray) and push (return it when you're done). You can see what the top tray (first item) is (ex. what color), and see if the stack is empty. Non-stack operations such as getting a count of the trays are non-trivial. It is also impossible to insert or ...


14

Mistakes are fine. We are human, we make mistakes. In fact, one of the worst things you can do in teaching is to never make a mistake and to always say exactly the right thing. This is pretty much guaranteed to reduce the fraction of students who actually learn. A lot of things in CS need to be approached from various, more or less accurate, directions, ...


13

What my teachers used was the following example, which is pretty simple and most people understood. Your father orders a pizza. The delivery guy arrives and expects payment. The wallet containing the money belongs to the object father If the wallet is private, then you have to get your father to open it and pay. If the wallet is protected, you can go and ...


12

The back button on a web browser is an excellent example of a stack implementation that is easily understood even by non-experts and easily demonstrated in a class. You can illustrate the stack in diagrams, and you can show it in action in a browser. When a user visits a new web page, the current page gets pushed onto the stack. When the user clicks the ...


12

This is such a consistent trap that I ultimately created a worksheet to deal with it. At this point in my course, I have recently covered binary and hexadecimal, so I also use this worksheet as an opportunity to gently review those concepts. My worksheet may not be as physically active as some of the lessons that have already been posted, but it is highly ...


12

Back around 1985, Susan Merritt created an Inverted Taxonomy of Sorting Algorithms. The idea is that to sort an array you have two phases, the split phase and the join phase. She divided the various algorithms into two types easy split/hard join and hard split/easy join varieties. Merge sort is of the former type. Quick sort is the latter. But all sorts, ...


11

Ooh, this is one of my favorite lessons! I don't introduce package private and protected in the same lesson as private and public, because there are 3 principles that I want them to absorb that ultimately motivate the entire system. My lesson introduces a few more ideas than just permissions (it's really how I get started with Ojects), but the key ideas of ...


10

I've got to jump in here and talk about my experience having to help a former boss understand why the project he wanted to do wasn't possible in the time available. It came down to incompatible data types and he just couldn't see why I couldn't convert from one to the other (he wanted to do real-time motion capture using an XBox Kinect to animate a 3D mesh ...


10

Check whether a string of parentheses is balanced or not. For example, return True for these input strings: (()()) ([]{{}}[]) but False for these strings: (() ([)(]) You can solve this using recursion, but a very efficient and clear solution would be to iterate over the string, whenever you encounter an opening symbol, you push it into the stack. ...


10

The teaching philosophy I came to as a young teacher (i.e. in my first year) was that I would ground myself in two qualities: passion and humility. (I've since added gratitude as an important third, but that's another topic.) Humility is essential regardless of the discipline. Teachers are, after all, human. We make mistakes. We forget. We may occasionally ...


10

I attack this problem with three "visits" over the course of two years with my students At our first brush with Complexity, I don't spend a ton of time motivating the study of it. I introduce the notations of $\Omega$, $\Theta$, and $O$ (as well as briefly touching upon $\omega$, $\theta$, and $o$). I show the difference between linear and binary search, ...


9

I like the pez dispenser. Also the stack of papers (where the actual human interaction is never to take the top item but rather to take the second from the top. At some point you have to talk about pancakes and the fact that people don't actually eat them as a stack -- they frequently destroy stack integrity by cutting top to bottom. I personally use a ...


8

Recursion as a loop I'd present recursion as a form of a loop rather than being separate thing. Then, I'd show the students how to covert between flat form and recursive form, and discuss the pro's/con's of using both in implementation. Flat-vs.-recursive formats rather than examples of recursion Since any loop can be written in recursive format, there's ...


8

If your student has tried it once, you can use sudoku as an example (it does not work so well if the student has never heard of it). Given a completed sudoku grid, write a program that verifies that it is valid: your student can probably write this simple program in a few minutes, or if you give the answer see that it is really easy. Given an incomplete ...


8

I used seats in the room. The classroom has an address. So, if someone wanted to come and talk to one of the students they would come down the hall and into my room. But, that only gets them to the room (server). They need to talk to a specific person, so they go to seat 17 so they can talk to Bob. So Bob's socket is room.123:17. I tried once to ...


8

I don't think the address metaphor is that off-the-mark -- real addresses are more segmented then IP addresses, true, but I don't know if that's really that much of a conceptual barrier. Regarding ports, I would tweak your metaphor slightly -- a port is more like an apartment number, rather then the apartment itself. That is, the port just serves as an ...


8

I have been adding: “make lots of mistakes” to my student's lesson objectives. I have been asking “What does it mean when we make a mistake?” [That we are learning. That we are trying hard.] When programming: “What strategies can we adopt, to help us when it does not work?”. When a pupil asks what angle should the turtle turn to make a triangle. “What ...


8

Whenever I run into students who are baffled by the return concept (and in your case, them substituting it with printf), I do something like this. I use role-play. I become one function (lets say the main function) and the student is another function (lets say some function add that adds two numbers and returns the values). Here is how the role play ...


8

Going with real-world things which they should be familiar with are best, even if it is completely outside of education. As you have applied the tag for adult education, I'm going to presume it is outside of normal university/college courses. A bit of creativity and looking around can develop many an idea as long as you get outside the box. The cafeteria ...


7

A good analogy might use animals and their classification. Class: think felines. A feline will purr, go out only at night, eat meat, etc. One could think of the methods purr, goOut:time, eat:food, where a valid feline will only accept a night time and food that is meat. Inheritance: meanwhile, felines are very different from each other, despite sharing ...


Only top voted, non community-wiki answers of a minimum length are eligible