Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.

Channels ▼

Bil Lewis

Dr. Dobb's Bloggers

Sudoku and the Turkey Bird

November 29, 2009

I was asked to teach a class on algorithms. This was a regular part of
the Tufts undergraduate ciriculum and it had a set book and language:
C++. I was not a happy camper.

It's damn hard to write any program in C++ and it's especially
difficult for younger programmers who only have half an idea of how a
computer works in the first place. The book didn't make things any
easier. The authors seemed to think that it was important for students
to learn every feature of the language at the same time.

Moreover, they were quite fond of the STL (Standard Template Library)
for C++. The STL is an excellent example of how NOT to write a
library. It supplies a complex interface to an unorganized set of
classes and adds no protection against simple mistakes. 

The STL Vector class is basically an ArrayList (that doesn't check for
out of bounds errors) and a List is a LinkedList. They are not
related. If you are using a List and realize that a Vector would be a
better choice, you have to rewrite your entire program.

By contrast, Java, Python, and many of the newer languages do it
right: Both LinkedList and ArrayList are implementations of List, so
all you have to do is change the constructor and everything will
continue to work, only faster. (If it isn't faster, then don't make
the change!)

Programmers need protection.

Undergraduate programmers need a lot of protection.

If you don't give them that protection, then they'll waste a lot of
time trying to track down stupid bugs and get bored with computer
science and leave.

So our first project was a Java-like List hierarchy, with out of
bounds protection. And then maps and hash tables and trees, all with
simple, safe interfaces. We basically rewrote the Java Collections

And it worked.

Usually most students don't manage to finish all the assignments
because they get lost in a mass of compilation errors and runtime
exceptions. My students did.

By Thanksgiving, the class was ready for something bigger. They were
ready for dealing with abstract datatypes in the real world.

At this time, Sudoku had recently taken off in the Boston newspapers
and folks were solving puzzles everywhere. Now what could be more real
world than Sudoku?!

I wrote up a Sudoku solver in Java, refined it, and translated it to
C++. (I could not have written it in C++ from scratch, certainly not
that quickly.) I was able to separate the basic data structures from
the logic of the solver cleanly, and then introduce the students to
the basic structures independently.

Now my idea of a good time is to hang out at Thanksgiving with my
brother on his ranch in Utah, take the horses up the mountain
(sneaking around the security guards*), cook some coffee over a fire
and dream about data structures. This particular year, I arrived to
find a 55 gallon drum heating water in the driveway and a monsterous
turkey looking on.

Sandy had decided to raise the turkey himself and he fed it a little
too well. He couldn't find anything smaller to de-feather it in than
the drum. We had to remove the drumsticks just to get it in the
oven. And we ate around midnight.

So this is what my assignment to my students was. I introduced them to
the basic ideas of Sudoku and what the useful ADTs were (there's the
individual cell, then three versions of sets of nine cells--boxes,
rows, and columns, but NO two dimentional arrays!). Then I told them
to go enjoy the vacation and day dream about their soon-to-be glorious
Sudoku solver.

And they came back and built the structures under my watchful eye,
then built their own solvers (not under my watchful eye) and succeeded!

Not only did they learn about the realities of programming with ADTs,
they left the class with something cool that they could show to their

It's hard to get English majors excited about writing an N log(N) sort
routine, but a Sudoku solver! That's something one can brag about.


* Actually, there's not much they can do even if they do see
  you. Pickup trucks are not very good over rough terrain and horses
  can go anywhere. They'd shake their fists at us and we'd smile and

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.