2012-09-16

I've been studying up on a computer science question that burned me on a 2nd interview code-test after a very successful 1st interview. Otherwise, I would've considered it a slam-dunk.

Basically, I was to implement minesweeper, using lattice cells, in under 2 hours.

Where if it's a 1X1, there is one cell.

Then if it's a 2X2, one cell has four cells (children?), each of which are doubly-linked to the parent. Also, the 2 children are doubly-linked to each other. And so are the other two children.

Traversing from a child cell to another child cell would mean having to either just jump to the next chid link (a sibling), or traversing back to the parent first, then to the destination child within the other child link-pair set. (Note: the tree-idea is just my idea, not a requirement)

The general idea I had was to establish a pattern-creation mechanism that then gets larger and larger, implicitly, according to a depth parameter. A kind of tree-structure seemed to be the best approach.

It seemed easy enough. But I just couldn't get my head around the pattern-creation logic:

Tree structures, with multiple children are easy enough (oct-tree, quad-tree, binary tree, etc.), but coming up with an elegant system where whenever a parent spawns multiple children, the children are also implicitly linked to only specific siblings was a mind-twister for me. So, essentially, according to my idea, the root is the center of the lattice diagram, and the furthest child nodes are on the edges.

Also, there might be many aspects of lattice cells that I don't understand. I dug around the internet, trying to find a ground-up explanation on why or how this is useful. I found a primer on the subject that talks about the logic basics: partially ordered sets, powerset, reflexivity, and lattice diagrams based on those principles, such as a Hasse Diagram.

However, this still isn't good enough for me: there were no C++ or even pseudo-code examples.

I understand hash tables, linked lists, reversing linked lists (recursive/iterative), binary trees (balanced/unbalanced), vectors, strings, reversing, etc. (all the basic basics). Trig, linear algebra, quaternions. Some Calc. And a multitude of graphics programming tricks/techniques. I've even written two game engines from scratch, but simple lattice problems escape me. I'm embarrassed. I want to learn as much as I can about lattices, so I'm never burned like that ever again. However, the documentation I require is hard to find.

I'm looking for a good primer/tutorial on the subject of lattices (as it relates to writing C++ algorithms)--hopefully one that holds my hand for me (from beginner, onward) like a typical Sam's teach yourself C++ in 21 days, or something. Since lattices seem to be an intermediate to very advanced subject, this might not be possible.

If not a tutorial, if any of you could kindly give me what knowledge you have on this subject, I'd greatly appreciate it.

Thanks.

Show more