96

I find a very easy to understand example for recursion is the folder structure on a computer. Look through all folders (within a certain location) and... list all .doc files, for example. First, you look in the location you were given and see what you're looking for... or not, but you see more folders. Then you take each of those folders, look into ...


95

Buffy's lovely answer shows well how two variables can refer to the same thing, but since we are in early cognitive development and working with Scratch, in which you can't pass parameters, and can't arrange for two different names to refer to the same instance/spawn, I wouldn't focus my efforts on that point yet. What matters is the idea of a holding place ...


41

I'm not as familiar with Python as I am with other languages, but I'm sure your students have played Minecraft. If you haven't, I suggest taking a few minutes to find some introductory "Lets Play" videos on YouTube first. Let's talk Blocks. Minecraft has dozens of blocks. Dirt, some, water, colored wool... All blocks can be broken, picked up, placed, ...


37

My usual explanation is related to names; specifically names of people. People have names. The names are not the people, but can be used to refer to the people. Some people don't have any names at all. This is common just after birth at least, before the parents decide on a name. Names can be changed. A person can have a name for a while and then later ...


33

The best way to show your students that their work is vulnerable to SQL injection is to demonstrate it. I'd suggest that you challenge the students to "hack" each others projects using SQL injection. You could then give bonus points for the students who are able to find the most vulnerabilities and for the students who didn't leave that attack vector open. ...


32

You can get at this concept very intuitively in strings before you ever get to arrays. Take a string like "hello world" and ask them a subtle-sounding point: does the string begin here: "*hello world", or here: "h*ello world". They'll certainly be able to identify the correct answer. Then ask, "how far from the start of the string do we have to go to get ...


32

I don't think the core issue is that some students are bad at using Stack Overflow -- I view that more as a symptom of a deeper root problem. When somebody doesn't seem to be able to productively ask questions on Stack Overflow, I think that one or more of the following core issues are at play: They don't really understand what it means to self-learn and ...


31

Ages in the United States (it's not the same around the world). For the first year of life, children are 0 years old. Only after completion of a year is the age changed to 1. By this logic, a child in his/her second year of life is 1 just as the second element of an array is found at index 1. Edit: another example is the counting of centuries. An event ...


26

An analogy that will work well in Europe, but not in North America: Image licensed under the CC BY-SA 3.0 by Bidgee of Wikimedia Commons. Floors (in European countries) are typically numbered with 0 (or G) as the ground floor, then 1 as the first floor above ground, etc. This could easily be compared to a list/array of floors, with floors[0] being ground, ...


25

What about You have alot of values that you need to remember, so you put a label on each one (a little piece of paper to remind you what this value means) so you can find the value easily when you need it.


24

One good example is to make permutations of all of the letters in a word of arbitrary length. It's quite tricky to do iteratively, since you essentially have to recreate the program stack to get it done. The recursive solution, however, is clean and clear. Let the students try to work in pairs on an iterative solution for just five minutes. The goal ...


24

One good overall educational strategy is to teach the same thing to students repeatedly, using a Spiral approach, in which each turn of the spiral teaches at a deeper level. Don't expect the students to completely get much of anything at the first mention of it, but reinforce the ideas and deepen the knowledge. You can do this for many things in one course, ...


23

I can't speak to cloud9 but I've always taught on Linux and am a CLI wonk. One thing I do is differentiate between user friendly and learner friendly. GUI interfaces are learner friendly - they're easy to learn but they're not user friendly because they're not that powerful. They're basically program loaders. You load your program, work in it, exit, next. ...


21

Writing recursive code to output the Snowflake Curve (Koch snowflake) was something that definitely pushed my buttons early on. It's formed as follows: The Koch snowflake can be constructed by starting with an equilateral triangle, then recursively altering each line segment as follows: divide the line segment into three segments of equal length. ...


20

The clock (24 hours system) If we look at the clock, we have to examples of counting hours. The 24 hour system is 0 based. The 12 hour system is interesting, neither 0 or 1 based. The 12-hour clock In the 12-hour clock system we start at 12 and make our way up to 11. This needs some explanation. The 12 hour clock has a funny way of counting, that you ...


19

Other than the obvious merge sort, I really like the minimax algorithm, especially when applied to creating a computer player of a simple game. Start with something simple like tic-tac-toe. When it's your turn, you can think about putting an X on each of the 9 squares. Then you have to think about what your opponent would do in each case. Your opponent ...


17

One way to show them the value of the command line would be to juxtapose doing a task with a GUI and with the command line. You could do something like the following: Create a directory with mixed content (eg. text files, audio files and images). Ask your students to perform these actions via a GUI, then via the command line: Move any text file that ...


16

Quite honestly, I would be upfront with them about the debate. Send them to a couple other SE threads: Efficiency: recursion vs loop “Necessary” Uses of Recursion in Imperative Languages Are functional languages better at recursion? This now becomes a teachable moment on a number of levels: imperative v. functional languages, recursion v. iteration, "...


16

A couple suggestions - The classic xkcd comic about Bobby Tables: Shown, complete with the explain xkcd article can provide a nice, humorous introduction that will get them to start paying to attention. Sites like hack this site are completely legal and allow users to experiment and learn about vulnerabilities (in this case, using them to solve levels ...


16

I like the idea of producing a few style sheets, and having the pupils apply them to their HTML. They can then see the power of having separate style sheets. Start with a style sheet that you made. Use the new grid layout, have some college styling. But at first get them only creating the html. They can then start editing the style sheets. They will see ...


16

Too many examples that you find are (IMO) fatally flawed. The Animal->Dog is especially flawed, though widely used. The problem is that these sorts of examples almost require that the superclass has a certain set of public methods that isn't the same as that of the subclass, requiring you to add additional public methods to the subclass. This is because an ...


14

When I teach recursion, even if I am not at a point in the curriculum where it is possible to introduce trees in coding problems, I always at least provide a high level discussion of trees, and the way that recursion is a natural way to process anything organized in a tree. Anyone that has worked with files and folders/directories on a computer is already ...


13

I'm going to focus on student's understanding recursion at a fairly deep level, rather than coding. First, to really understand recursion you need a sense of its parts. There is the base case, of course and most teachers spend time working on that, but students often miss it. But Before the process hits the base case there is a winding phase working toward ...


13

The variable that children are most familiar with is score: whether in computer games, sports or board games, a child will almost certainly understand that a score is a value that is clearly not constant. Variables are abstract, but using familiar examples turns this into something easy to grasp. Once numeric variables are understood, you can extend the ...


12

You can't teach the value of the command line. You can, however, sell it. Students have at least one of two primary goals in any class: Get good grades (pass the class) Learn something they like These are not mutually exclusive, and may change as the class progresses in their relative positions. For the students who's motivating goal for the class is ...


12

Introduce test-driven development. TDD and agile methods of development are very popular at the minute, and for good reason — you know, ahead of time, exactly what each part of the program must achieve, and you can confidently say that the program will work as intended as long as your tests are thorough. I think that sometimes, the confusion begins when ...


11

I also have this problem frequently. I use the example of Microsoft Word, and I would say something like this: "Word allows you to give a document the appearance that you'd like. You can bold, you can center, you can change font sizes. Word is creating a markup (in this case, it is generating a type of markup called XML). "Markups" mark up text, just ...


11

If you search 'computerphile SQL injection' on google, it should bring you to the link below. The man in this video explains SQL injection very clearly and uses a practical example as well by breaking into a vulnerable website he created for the video's purposes. https://www.youtube.com/watch?v=ciNHn38EyRc PLEASE NOTE HE USES MySQL in this video. He ...


11

If you only want to build a page that is simple and ad-hoc and will never change in the future and will only ever be seen on one kind of device, then, sure, build the styling directly into html. It is the same when you write a program that will only be run once on one device to get an answer, after which the program becomes obsolete. There is, then, no ...


11

Memory is a linear sequence of storage locations. Like a lined sheet of paper. Take a lined sheet of paper and choose a line. In the left margin, write a label. The variable is that label - it gives a name to a spot. Now look for the label and write something to the right of the margin. That is assignment.


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