Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
14

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


11

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


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


8

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


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


8

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


7

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


7

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


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

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


6

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


6

To add some context from the chat room conversation: This is part of a larger course that introduces technology in an applied fashion. The segment with the robot is 10 days and the students have not necessarily programmed elsewhere. Empty while loops I would recommend against beginning with any empty loops for your students. All the looping constructs are ...


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


5

You could show them the results with a given heuristics function, that has a single parameter which impacts how the heuristic function affects the cost estimate. As an example, estimate = D * (horizontal_distance + vertical_distance) where the distance is the one between the current node and the goal (quite straight forward in a maze, albeit not such a ...


5

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


5

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


5

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


4

Even though it can be complicated, recursion gives a great algorithmic view of problems. I have seen quite a few students start to think in an algorithmic way after I introduce recursion (just very simple problems such as printing the individual characters of a string. I'll refer to this exercise as an example task throughout the answer). This gives them ...


4

One thing that helps in my experience (albeit with older students) is to give a pseudo-code cheat-sheet and insist that the problem has to be solved only using the building blocks on the sheet. In particular, you must insist that anything that is not on the list must be written using the building blocks. So if at some point they need to fill an array with ...


4

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


4

I just finished up 8th grade. I took an Intro to Engineering/Robotics class as an elective this past semester. I have programmed (mainly in Python 3) before this class, and I was mainly excited for the Robotics part. When we started, the teacher talked to us about how the computer takes things very literally, etc, etc, and then - he had us pretend he was ...


4

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


4

One technique I use for sorting algorithms follows after CS50's demonstrations of the differences among bubble sort, selection sort, and insertion sort. I have 8 students line up in the following order: 4 - 2 - 6 - 8 - 1 - 3 - 7 - 5 Here, 4 represents index 0 of an array of numbers I'd like to sort. I literally walk them through the algorithms, and they ...


4

Any programming is a two step process: deciding how to solve the problem, then implementing that as code on a particular system: choosing or designing an algorithm is the first step. There are great ways to illustrate how the choice of algorithm matters. An introductory one might be search - comparing random, linear and binary algorithms to, for example, ...


4

I have a contrary view. Dynamic programming and it's close cousin memoization are actually pretty easy to teach. It's true that students frequently struggle mightily with dynamic programming, but I strongly believe that it's usually not the actual dynamic programming that they're struggling with, but rather the underlying recursive relationships. If I ...


4

The answer here, as it seems to be so often, is "it depends." The courses you've compared are comparing apples to oranges. Which are you trying to make, apple juice, or orange juice? You have to select to version implementation or application, which best moves the lessons, and the students, toward the objectives and goals set for the course. The Apples ...


4

Yes, you should at least introduce the idea to your students. That said, it is also a truism of education that you need not explain every concept at the same level of detail. In this particular case the first couple of paragraphs of the Wikipedia article on the subject is probably enough. A couple of minutes could be well-spent. Students need to know ...


4

Some project ideas: Implement a very basic programming language. Write the parser for them, but have them manipulate the AST (eval expressions, perform constant folding, etc). (So hey, trees are a thing...) And of course, all programming languages have variables. How do we store variables? Hey, wouldn't having dictionaries be useful...? Use dictionaries to ...


4

I can offer two ideas here. The first is to try, whenever possible, to use some real world metaphor for the technical problem at hand. Railway sidings, card shuffling, etc. Some instructors use these as a matter of course in introducing a new algorithmic concept. But if you want a thorough study of how to approach and develop algorithms, get a copy of: ...


4

I have seen two approaches that work: Unplugged: Leave the computer, and design the algorithm. Use white boards, acting, puppets, physical objects, etc. (This method is best used when you don't yet know what you are trying to achieve.) Use Test Driven Development with Transformation Priority. (This method is best used when you know what you are trying ...


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