What is the output from the following algorithm?
I love stuff like this. I made this in a bit of a rush. I was trying to remember the binary search algorithm and got very close. For me, this is the perfect challenge for all students. If you have a basic understanding of recursive functions or even just functions, you can trace through this without too many mishaps. It also returns the correct answer - position 1 on the list. But is it correct? Try running through the algorithm looking for the position of 15. Why doesn't it work? Could you fix it? Lots of lovely questions to stretch higher ability students.
Getting students to really look at a piece of code and go beyond the initial question helps foster a sense of curiosity but also true deep processing. On the face of it, students might think this is just about tracing through a problem but in reality, when we are testing code we have written we must test for multiple values to be truly sure the algorithm works correctly.
Comments