For me, it’s a constant challenge, when planning teaching activities, to figure out how best to help students learn various topics within the constraints of the available resources. A while ago, I was pleased to find what seems to be a good teaching method for hash tables, which is the subject of this post.
More of hash tables later. First, some background:
Usually for a module, we have a large lecture room booked for two hours, followed by multiple small-group rooms booked for one hour. Typically, the larger room is used for a lecture, containing an initial presentation of the module concepts. Whilst there can be a certain amount of participation and interactivity in a lecture setting, it’s the smaller-group sessions (practical classes) that usually offers a better opportunity to engage students and make sure that they are learning the material, because as it’s a smaller group, there’s more opportunity for tutors to help give students individual feedback on how they are doing. Obviously, we want students to attend the small-group sessions because people generally learn better if they are doing some kind of activity where they are active participants, rather than sitting back and watching someone else do it. The idea is that if you have to do it yourself, you have to understand it, because you need the understanding to do the task.
So far, so good, but there’s an issue we have to bear in mind when planning what’s going to happen in the practical classes: like other universities up and down the country, levels of attendance aren’t what they should (or could) be, so how do we best encourage students to attend their practical classes? We asked our students some years ago what affected their attendance: it turns out one of the factors that affects whether they go to practical classes is how much value they see themselves as getting out of that class.
And herein lies the tricky bit.
If we set worksheets that the students have to work through individually, with the idea that the tutor can help when they get stuck, despite the help available, several of them tend to take the line “Oh I can work through this at home”, and I can understand why they’d prefer the comfort of their own desk with all its comforts to one of the University’s computer labs.
On the other hand, if we set worksheets more oriented towards a group activity, that does tend to be more attractive for them: not only is the class an experience they can’t get at home (which contributes to their perception of the practical’s value), but some students like keeping quiet in a group and letting others do the active work, and then they’re not getting as much out of the class as if they were actively participating.
In a nutshell, it’s quite a challenge to both get them through the door and give them the best chance of learning the material once they’re there in the practical class.
And that brings me on to hash tables.
Hash tables are a method of storing data: you have a table with slots in it for data, and understanding hashing is all about understanding which slot to put data into. To get students to understand hashing, as a teacher I feel that I really want each individual student insert data into a hash table table.
I used to have a practical worksheet which involved students being given data to insert into various hash tables, on their own, and I wasn’t happy with this worksheet. One reason was that the time taken to insert the data was quite substantial, and many students didn’t get to try all the different hashing schemes covered on the worksheet. Another reason was that it was the kind of exercise that students might feel that they could do it on their own rather than attend practicals.
Here’s what I did that I felt worked really well:
I had prepared in advance several little cards like this, each with a different number on, and randomly distributed them to the students. We were looking at three different hashing schemes, so each student got three cards, each with a different number on (the number being the data to be inserted into the hash table), one card for each hashing scheme.
Stage 1: students on their own went to the computers (or their pocket calculators) and calculated what the hash values of the three numbers they had, filling the values in on the space on the cards. These “hash values” are useful information, to be used in the second stage.
Stage 2: for each of the three hashing schemes, we started with an empty hash table. This hash table was displayed on an OHP screen, but could have been displayed on a whiteboard or on the floor, just so long as everyone could see it. Then, one by one, the students took it in turns to enter their own individual piece of data for that table. I supervised, to make sure that they were putting the data in the correct place and understanding why they did so.
This seemed to work really well. Every student had to place a piece of data, so every student had to participate and understand why the data gets placed where it does, including the shy students (who need not go first but can do one after their friend has done one). Because students only calculated hash values for one piece of data each, at the beginning 5 minutes of the session, the students didn’t spend so long calculating hash values but instead spent much more time on watching how all the various numbers got inserted into the hash table. That meant we had enough time for all of the students to look at all the hashing schemes, not like before where only the speedy students covered them all.
Of course, it doesn’t have to be numbers for the data. Strings work pretty well where you can base hash values on things like the length of the string, or how many vowels the string has got.
Next time, I think I’ll bring a prop, a kind of large mat, to be placed on the floor where everyone can see it, with the outline of the slots of a hash table, so that students can physically place the numbers in the slots on the hash table mat.

