38

Similar to @Vince, I think it's a good practice to do both. I don't really agree with the cooking recipe analogy, though. Pseudocode describes that the algorithm does, without going into detail how you do it. I think perhaps a better analogy: Pseudocode: you need to put an egg into the flour mixture Actual code: pick up an egg, crack it open on the side of ...


36

As someone who has now taught CS for many years, let me first reassure you that teaching clear, clean coding is entirely worthwhile. I think this is especially true for those who will not go off into software professionally, because editing, and being able to express ideas in a clean, clear manner is a skill that serves people well in any field. (I've ...


32

When I attended a Mind, Brain, and Learning conference a few years ago, a lecturer posed the following question (paraphrased): If I ask you to figure out the cube root of a number like 150 in your head, and ask Albert Einstein or Richard Feynman to do the same, they will probably come up with the answer faster than you do. But who will be using more of ...


26

Actually I am of the opinion that you should not present your own code, but rather get the students to implement the algorithms you teach them, which you give in pseudocode, and give them the freedom to choose any one of a fixed set of languages that you are familiar with, such as C++/Java/Python. Really, the only way students can truly understand an ...


17

Rather than giving them processes to model algorithmically, have them start coming up with algorithms for everyday activities. Here is the formal assignment I have students complete: CS50 AP - Everyday Algorithms. They begin with a simple pseudocode example: 1 look out the window 2 if it is raining outside 3 put on your rain boots 4 put on ...


14

How do you teach students of this age and ability to think algorithmically? I don't really think there's a silver bullet to this problem. To be able to think algorithmically, you need to solve lots of problems, over and over. Some students will naturally have the ability to be able to describe algorithms without much teaching, but it's not a universal skill,...


13

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, ...


10

Neither is always better, and both have their strengths. The idea of scoring higher marks as a criteria for better is going to be unpredictable without knowing who is granting those marks. Someone who is heavily in favor of one style over the other may grant higher marks to low quality uses of their favored style than they would to high quality answers in ...


9

Homework problems in algorithms classes often involve finding clever tricks that the professors find elegant or interesting That seems like a strange way of teaching algorithms. It shouldn't involve trying to make the students recreate brilliant ideas from scratch (most people won't re-invent Dijkstra's algorithm when asked to find the shortest path through ...


9

Actually, the code is terrible, but I don't think its purpose is to illustrate a stack so much as to illustrate in a very rudimentary way how heap allocation works. (Worse than "terrible", it isn't "pythonic"). But you are wrong about the efficiency. Only the initialize function is O(n). Push an pop are O(1) as should be obvious. But no serious code ...


9

About 20 years ago, I interviewed at a rather well known American software company. I met with about a dozen people over a day that lasted from 8:30 to 4:30. One of the questions was to come up with an algorithmic solution to blindly traversing a space that looked like this, from one end to the other: +----+ | | | | | +---------+ | | +-...


8

I remember a demonstration from early in my first college CS course (this was in 1998, almost 20 years ago!), where the professor brought in a loaf of bread, a butter knife, a jar of peanut butter, and a jar of jelly. He then asked the class to give him instructions to make a peanut butter sandwich, with predictably hilarious results. After we had finally ...


8

I think it's really about breaking down the concepts into smaller pieces. First a student needs to understand recursion well, then they can understand memoization and dynamic programming. It's hard to just jump into e.g. the knapsack problem without first having worked through simpler problems. After one gets practice with the basic concepts, dynamic ...


8

The Wirth formula, Algorithms + Data Structures = Programs is still valid. It is also complete. A program is nothing more than algorithms acting on data structures. That formula does not make explicit the difference between a bad, error-riddled program and a good, error-free efficient program. Looking at the formula, however, can show how to improve the ...


7

The problem as described is simply translation from one firm of words to another, so in some senses, students may not really grasp what you are asking for. I think a more important thing to ask for is to construct algorithms from a less structured problem. A flow chart is just another way to write the algorithm, not really a progression - and not ...


7

I usually teach Uniform Cost Search (UCS) before A*, since it is basicaly A* without the heuristic (and it reduces to BFS when all costs = 1, so it is pretty straightforward to explain). Then I teach A* and show them animated examples of the explored nodes in comparison to UCS (here you can find excellent interactive examples). In this step, one analogy I ...


7

Since all the other great answers are all given, let me mention a minor one. Lateral thinking Puzzles are good for this. They help to teach children to think in a different manner by themselves and encourage general problem solving. However, they can be used to teach one important part of algorithms, the need for rigor in your statements, if one chooses ...


7

I'm a bit confused by your question. Your exercise seems to involve some combination of… Requirements gathering: what are the inputs, outputs, and formulas? Translating the requirements to a conceptual model Translating the conceptual model to pseudocode Translating the pseudocode to code Translating the pseudocode or code back to a flowchart (Why? In ...


7

Thinking algorithmically isn't always natural. In an algorithm, you're going to write down everything the computer is going to, then hit "go" and step away for a few microseconds while the computer does it. In most of our lives, there's more back-and-forth in our interactions, so it takes a while to get used to thinking in this one-pass approach. ...


7

The Dutch National Flag problem is linear in running time. Essentially sort an array with only 3 distinct values each of which may appear 0 or more times. (not length 3). You are allowed only one pass over the array, so the solution is a single while loop with some prior initialization. It was probably originally posed by Dijkstra. It is mentioned in David ...


7

A variant on the ENIGMA machine encryption works well in a single loop, and is sufficiently complex to give students a real challenge. The core idea of the ENIGMA machine for this assignment is that (1) a number is given as an initial key, and (2) every prior letter used influences how the next letter will be encrypted. So, use a modular circle of ...


7

The simplest example that still bears enough complexity to show what's going on is probably merge sort. It's no coincidence that this algorithm is the classical example to begin explaining the divide and conquer technique. I am not sure at what level you teach, but your students should be comfortable with both recursion and inductive proofs before venturing ...


7

I emphasize readability and maintenance of code. Therefore, I will assign a project and later turn around and require another student to complete the second half of it. Everyone ends up maintaining someone else's code as a result. I think you should continue teaching your good habits and thinking styles. That said, you see a student doing Olympiad problems ...


7

When I was about eight years old, my teacher asked the class to describe fool-proof ways to make a cup of tea, or to strike a match then use it to light something like a gas-flame or a cigarette. How would that not meet your citeria?


6

Sounds like you've tried everything already, but here are some suggestions: Use a scenario / problem that every student can relate to Most of my lower ability 13-14 year old boys don't have much experience of wages, tax and jobs. Writing an algorithm for making a perfect cup of tea doesn't do much for them either. Drawing a flow chart for how to irritate ...


6

The hard parts of this are hard for everyone, of course: P = NP (or not). But the others aren't too difficult to get across in a short period of time, especially if the students have something of a math background. You can easily construct problems that grow exponentially and whose programs for solution must also grow at that rate. Drawing a completely ...


6

I had zero experience with algorithms when I started. Here are a couple of things I wish had been done differently. Let Students Make Mistakes My TAs and professors always tried to guide me to the best answer, show me the right "trick", or stop me from making a mistake before I actually made it. Whenever I'm helping someone out with CS now, I usually let ...


6

Pseudocode helps a lot by removing anything unnecessary, and focusing entirely on the algorithm, which can already be hard to understand as is. It's also faster to express ideas : if a student wants to write a different algorithm than the one you taught them, it can be really cumbersome if they have to deal with every details of Java. As others said, it's ...


6

One of the key points here is that you are teaching to future engineers, even if at academic level. The very nature of engineering is solving problems by implementing a solution. Therefore I think that presenting the pseudocode is useful to give your student the correct theoretical POV to frame the problem, BUT showing them an actual, working ...


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