简体   繁体   中英

Understanding Lattices

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.

The confusion arises from the misleading use of the word lattice: in math a lattice is a poset in which every two elements have a lub (least upper bound) and a glb (greatest lower bound). The game 'tree' (nodes are states of the board, edges the moves clearly fails to have any glb because of the unique path property of trees), even if you join identical states which are reached via different sequences of moves (in which case the tree becomes a directed graph), would fail to have glb if from a given state you can reach two different final states. I haven't played minesweeper for a decade, but my impression is that it is possible to end the game such way. So the underlying data structure you need to be thinking of is a directed (possibly acyclic) graph, which sometimes is a lattice (ignoring the directions on the edges) in the math sense, but not always.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM