Disassembly using breadth first and graphs: how the take-apart search handles positions it has already found
How a known assembly is taken apart: why its moves make a graph and not a tree, what the search keeps of each position, what it does with the moves that lead back to positions it knows, and what that saves on a burr that needs 98 moves to open
21 November 2026 · Sources: core/shapelogic/solve/disassembler.cpp, node_hash.cpp, disassembler_node.h and movement_analysator.cpp; counts from a copy of the search with counters added, run on puzzles from ShapeLogic's test files (ShapeLogic 2.0, MacBook Air M4, 32 GB)
Where this page fits
The Solver works on a puzzle in two stages. First it finds the assemblies: every way the pieces can fill the shape, with no thought yet of whether they can be put there. That is an exact cover search, done with dancing links, and is described in Puzzle Solving: Assemblies using Dancing Links and Dancing Cells. Then it takes each assembly apart, starting from the pieces in their finished places, to see whether the puzzle can really be put together and taken apart, and in how few moves.
Everything on this page belongs to the second stage, the disassembly. Each search here starts from one assembly that is already known and only moves its pieces. Which assemblies exist is settled before it begins.
Summary
The positions of an assembly being taken apart form a graph, not a tree. Many different move sequences lead to the same position. In Pelikan Burr at least 5.7 × 1014 different 98-move sequences reach the position where the puzzle first comes apart, and there are only 6,742 positions on the way.
The take-apart search keeps each position once, with one link back to the position it was first reached from. Together the links make a tree inside the graph, and every way back along them is a shortest one.
A move that leads to a position the search already has is dropped on the spot. Nothing about it is recorded. In Pelikan Burr 92% of the 81,007 moves the search found were of this kind.
Three levels are enough to recognize a known position: the one being worked on, the one before and the one after. Every move the search follows can be made backwards, so nothing older can come round again.
Positions are freed as soon as nothing needs them. When an old level is let go, every position in it that is not on the way back from a newer one goes too. Pelikan Burr never needs more than 1,524 positions in memory at once.
When the Solver takes an assembly apart, it starts from the assembled puzzle and looks for every move the pieces can make: one piece or a group of pieces sliding one or more units in one direction, or, when rotations are switched on, a quarter turn. Each move gives a new position: where every piece is and which way it is turned. The search is over when it reaches a position in which the puzzle has fallen into two parts. It wants the fewest moves that get there. Each part is then taken apart in the same way (section 7).
The obvious way to picture this is a tree. The assembled puzzle is the root. Every move from it is a branch, every move from the end of a branch is a smaller branch, and so on. Figure 1 shows why that picture is wasteful, even for a puzzle with only two moves. Move a can be undone, which leads straight back to the start. And when a and b move pieces that do not touch, making them in either order ends in the same position. After only two moves the tree already has the start twice and position C twice, and every copy would grow its own branches.
Figure 1. Left: the move sequences of a small puzzle, written out as a tree; dashed circles are positions the tree already has. a′ undoes move a. Right: the same four positions drawn once each, with one line for each move. A line can be followed both ways, because every move can be made backwards.
On a real puzzle the tree is hopeless. Pelikan Burr, designed by Dic Sonneveld, needs 98 moves before the first part comes out of its box. Its positions allow 12.8 moves each on average, so a tree of every sequence of 98 moves would have around 10108 branches at the bottom. Yet the whole search only ever meets 6,742 different positions.
So the search works on the right-hand picture, a graph: each position is a dot that appears once, and each move is a line between two dots. The fewest moves to take the puzzle apart is then the shortest route from the start to any dot where the puzzle has separated.
2. One link back
Each position the search finds is stored once. It holds:
for every piece, its place (x, y and z) and which way it is turned, as small whole numbers;
the move that led to it: its direction and how many units it went;
how many moves it is from the start;
one link to the position it was reached from.
Two positions count as the same when every piece lies in the same place relative to the first piece. Moving the whole puzzle, frame and all, by one unit does not make a new position.
The search is breadth first. It finds every position one move from the start, then every position two moves away, and so on. Each of these sets is a level. A position is therefore always found first by one of its shortest ways, and the link it gets then is the one it keeps. In this search the link never changes afterwards. The set that holds a level could replace a link if a shorter way turned up later, but none can: every position in a level is the same number of moves from the start.
All the links together form a tree, but a different one from Figure 1. It contains every position exactly once and follows only shortest ways. In graph terms it is a shortest-path tree. Once a separating position is found, the moves are read off by following its links back to the start.
3. Three fronts
While it works on level d, the search holds three sets of positions, each a hash table that finds a position by its pieces: the old front (level d − 1), the current front (level d) and the new front (level d + 1, as far as it has been found). It takes the positions of the current front one at a time. For each one, call it P, it works out every move, and each move leads to one of four places (Figure 2):
Back: a position in the old front, one move nearer the start. The move that undoes the one that brought P here always lands here.
Sideways: another position in the current front, the same distance from the start. Slides of different lengths are separate moves, so sliding a piece one unit and sliding it two units both give positions of the same level, and one more unit takes the first to the second.
Found already: a position in the new front that another position of level d, or another move of P, has reached first.
New: a position in none of the three. It goes into the new front with a link to P. If the puzzle has come apart in it, the search stops there.
Figure 2. The three fronts while the search works on position P. Gray lines are the links back, one for each position. Of P's four moves, only the one to a new position adds anything. The others are recognized and dropped.
Why three levels are enough. A search like this usually keeps a list of everything it has ever seen, so that it never goes round in circles. This one needs only the three fronts, because every move it follows can be made backwards: a slide can slide back and a turn can turn back. Removing a piece is the one move that cannot be undone, and it ends the search, so it is never followed. Suppose a move from P, in level d, led to a position Q that was first found in some level k two or more levels earlier. Undoing the move would take Q to P in one move, which would put P in level k + 1 at the latest, not in level d. So Q can only be in level d − 1, d or d + 1, and the three fronts hold exactly those.
When the current front is through, the old front is let go, the current front becomes the old one, the new front becomes the current one, and an empty set becomes the new front.
Figure 3 runs the whole search on a small graph of positions. It shows every move tested against the three fronts, the one link each new position gets, the fronts moving on after each level, a dead end being freed together with the branch behind it (section 6), and at the end the moves read back along the links.
Figure 3. The take-apart search on a small graph of positions, move by move (47 steps, about 90 seconds at 1×, then it starts again). S is the assembled puzzle and in X the puzzle has come apart. The graph is made up to show every case; a real puzzle’s levels hold hundreds of positions. The arrows (or the arrow keys) go a step back or forward, and clicking the picture pauses or plays it.
Threads. When a level holds many positions, the search shares them out over the processor's cores. Each thread lists what its positions' moves lead to, without changing anything shared. The lists are then put together in the order a search on one thread would have made them. So every position gets the same link, and the take-apart comes out the same, however many threads ran.
4. What happens to the other moves
The short answer to "how does the search keep track of all the moves that end in positions it has already found?" is that it does not. Such a move is tested against the three fronts and dropped. The search never stores the lines of the graph, only which positions exist and the one link of each.
That is enough because of the question the search asks: what is the fewest moves to a separation? The shortest-path tree answers it, and the dropped moves could not improve on it. A move back or sideways leads to a position that already has a way at least as short. A move to a position found already offers a second way of the same length, never a shorter one. Questions that need the dropped moves, such as how many shortest ways there are or which positions are dead ends, would mean recording more. Counting the ways for section 5 meant adding a number to every position.
Figure 4 shows what becomes of the moves in Pelikan Burr, level by level. Of the 81,007 moves the search found, 25% led back, 47% sideways and 19% to positions found already. That last share includes the 3% where two moves of the same position led to the same place. Only 8% led anywhere new.
Figure 4. Every move the search found from each level of Pelikan Burr, by where it led. Only the blue part adds positions. Level 97 is the last searched: the position that separates the puzzle turned up while it was being worked through, and the search stopped there. Hover over a bar for its numbers.The numbers for each level
Level
Positions
Moves
Back
Sideways
Found already
New
Held
Shortest sequences
0
1
10
0
0
0
10
11
1
1
10
104
10
16
35
43
54
10
2
43
515
78
162
152
123
177
78
3
123
1,638
279
974
275
110
286
489
4
110
1,149
378
538
172
61
330
1,587
5
61
550
233
186
96
35
283
3,254
6
35
346
131
143
25
47
211
6,314
7
47
486
72
216
122
76
212
7,344
8
76
845
213
428
145
59
235
1,382
9
59
519
212
202
53
52
257
3,552
10
52
312
104
137
40
31
221
4,824
11
31
148
71
56
10
11
177
6,424
12
11
45
22
16
0
7
115
2,292
13
7
22
7
4
3
8
72
96
14
8
25
11
8
2
4
47
192
15
4
19
6
6
4
3
47
288
16
3
14
7
2
2
3
27
552
17
3
14
5
4
0
5
28
840
18
5
29
5
8
9
7
34
840
19
7
50
16
14
12
8
38
2,688
20
8
69
20
20
9
20
58
6,552
21
20
169
29
99
26
15
71
24,696
22
15
90
38
40
4
8
75
20,496
23
8
26
12
8
2
4
60
13,104
24
4
18
6
8
0
4
48
7,560
25
4
36
4
8
11
13
48
7,056
26
13
164
23
97
4
40
86
39,312
27
40
385
44
245
48
48
133
129,024
28
48
316
96
165
33
22
143
282,240
29
22
124
55
42
16
11
139
310,464
30
11
46
27
12
2
5
87
308,448
31
5
25
7
8
5
5
61
122,976
32
5
32
11
16
3
2
49
50,400
33
2
11
5
0
1
5
48
60,480
34
5
47
6
19
8
14
54
241,920
35
14
107
22
48
15
22
76
1.0 × 106
36
22
187
37
65
43
42
117
2.9 × 106
37
42
342
86
104
67
85
195
9.6 × 106
38
85
631
152
258
121
100
287
2.3 × 107
39
100
941
222
385
230
104
379
6.0 × 107
40
104
963
333
426
137
67
388
1.6 × 108
41
67
422
197
174
34
17
326
2.5 × 108
42
17
84
52
16
9
7
240
1.5 × 108
43
7
34
16
12
3
3
126
9.8 × 107
44
3
12
6
2
0
4
73
6.1 × 107
45
4
23
4
6
2
11
72
1.1 × 106
46
11
88
13
26
23
26
87
3.5 × 106
47
26
225
49
76
68
32
118
1.5 × 107
48
32
311
100
96
69
46
162
5.4 × 107
49
46
454
115
158
115
66
214
1.6 × 108
50
66
625
181
254
132
58
253
4.5 × 108
51
58
500
190
160
105
45
280
1.2 × 109
52
45
395
152
142
71
30
251
2.5 × 109
53
30
309
103
112
57
37
224
3.0 × 109
54
37
396
94
146
77
79
232
1.2 × 109
55
79
968
144
582
157
85
280
3.7 × 109
56
85
1,244
240
549
344
111
377
4.0 × 109
57
111
2,000
447
1,018
373
162
471
1.2 × 1010
58
162
2,809
531
1,446
648
184
573
4.0 × 1010
59
184
2,718
810
1,237
542
129
608
1.6 × 1011
60
129
1,954
640
938
331
45
576
3.6 × 1011
61
45
654
386
223
21
24
435
5.1 × 1011
62
24
193
44
69
31
49
269
2.6 × 1011
63
49
528
74
292
98
64
246
5.5 × 1011
64
64
497
161
242
51
43
261
1.3 × 1012
65
43
296
94
114
53
35
277
2.1 × 1012
66
35
230
79
100
22
29
243
1.7 × 1012
67
29
207
51
76
38
42
238
1.5 × 1012
68
42
333
78
149
53
53
230
1.4 × 1012
69
53
416
99
231
62
24
234
2.6 × 1012
70
24
205
84
99
13
9
213
1.5 × 1012
71
9
47
22
20
0
5
154
1.1 × 1012
72
5
19
5
8
0
6
114
5.5 × 1011
73
6
64
6
33
10
15
103
3.8 × 1011
74
15
112
24
38
13
37
131
1.5 × 1012
75
37
316
51
147
74
44
174
4.5 × 1012
76
44
406
114
168
70
54
226
1.2 × 1013
77
54
550
125
282
96
47
254
2.7 × 1013
78
47
526
148
221
114
43
261
5.5 × 1013
79
43
554
163
327
45
19
230
1.3 × 1014
80
19
155
65
69
15
6
195
1.5 × 1014
81
6
37
18
12
3
4
141
1.8 × 1013
82
4
16
7
4
2
3
104
8.8 × 1011
83
3
13
5
6
1
1
91
1.1 × 1012
84
1
14
2
0
2
10
99
6.3 × 1011
85
10
178
10
62
69
37
132
6.3 × 1012
86
37
765
96
339
244
86
218
5.2 × 1013
87
86
1,425
307
743
230
145
363
2.7 × 1014
88
145
1,919
367
775
533
244
601
6.0 × 1014
89
244
4,274
780
1,884
1,252
358
915
2.2 × 1015
90
358
7,966
1,586
4,654
1,394
332
1,173
7.1 × 1015
91
332
5,274
1,677
2,212
1,003
382
1,392
2.2 × 1016
92
382
5,869
1,372
2,923
1,215
359
1,483
4.9 × 1016
93
359
5,278
1,604
2,357
978
339
1,524
1.3 × 1017
94
339
4,614
1,338
2,441
576
259
1,412
3.6 × 1017
95
259
3,086
843
1,511
501
231
1,317
7.3 × 1017
96
231
3,385
722
1,591
713
359
1,243
1.1 × 1018
97
359
3,446
744
1,521
753
428
1,347
2.1 × 1018
Pelikan Burr's eleven other assemblies never come apart. Their searches run until a level comes out empty, having found every position the pieces can reach, and they show the same pattern. On the other puzzles most moves also lead to positions already found.
Puzzle
Assemblies searched
Positions found
Moves found
Back
Sideways
Found already
New
Pelikan Burr
the assembly that comes apart
6,742
81,007
25%
47%
19%
8%
Pelikan Burr
the 11 that do not
7,460
76,055
27%
46%
17%
10%
Dracula's Dental Disaster
all 84 assemblies
1,308
7,426
18%
53%
13%
16%
Cube in Cage
all 96 assemblies
856
2,596
47%
4%
20%
29%
Prisgon
its one assembly
17
39
38%
15%
5%
41%
The table counts the search of the whole assembly, up to its first separation or until nothing new is left. The searches of the parts (section 7) are not included. In the short take-aparts of Prisgon and Cube in Cage the levels hold only a handful of positions, so a larger share of the moves leads somewhere new. Even there, most do not.
5. How many ways there are
The search drops the moves that lead to a position found already, so it never learns how many shortest ways lead anywhere. The copy of the search used for this page counted them. Each position carried a number: 1 for the start, and for every other position the sum of the numbers of all the positions one level nearer the start that have a move to it. Figure 5 sets these counts against the number of positions in each level.
Figure 5. Pelikan Burr, on a log scale. The positions in a level stay in the hundreds, while the number of different shortest move sequences into the level grows by about 1.5 times for every move. At level 84 a single position is left, and every shortest way passes through it.
By level 97 the 359 positions of the level are reached by 2.1 × 1018 different shortest move sequences. The separating position is reached by at least 5.7 × 1014 of them. That is a lower bound, because the search stopped as soon as it was found and did not see the other positions of level 97 that might also lead to it. A tree, even one that only kept shortest ways, would have to hold every one of those sequences. The graph holds 6,742 positions.
The single position at level 84 is a bottleneck: the puzzle has to pass through exactly that arrangement, 84 moves in, on any shortest way out. There are 6.3 × 1011 shortest ways to reach it, and the search keeps one.
6. What the links keep in memory
Each position counts the references to it. A front holds a reference to each of its positions, and each position holds a reference to the one its link points to. When the old front is let go, a position in it survives only if some newer position's link leads back through it. Dead ends, positions from which nothing new was found, are freed. So are the branches behind them.
Figure 6 compares the positions the search has found so far with the positions it holds at the same moment. Pelikan Burr's search found 6,742 positions. At most 1,524 were in memory at once, at level 93: the three fronts, plus 444 older positions that are kept only because a link runs through them. The rest had been freed along the way.
Figure 6. Pelikan Burr: the positions found so far, the positions held in memory at the end of each level, and how many of those are held only as links back from the fronts. Hover for the numbers.
These numbers are small: the whole solve of Pelikan Burr, assemblies and take-apart, takes about 0.03 seconds. What matters is that memory follows the width of the fronts, not everything the search has seen. The same code takes apart puzzles whose levels are far wider, and it runs once for every assembly the Solver finds, sometimes thousands of times in one solve.
7. After the first separation
When a position separates the puzzle, the search follows the links from it back to the start and writes down every position on the way. These are the moves the Solver shows for this part of the take-apart.
The pieces have now fallen into two parts. A part of one piece is done, and so is a part whose pieces may stay together as a group. Any other part becomes a new search of the same kind. It starts from the places its pieces had just before the separation and has three fronts of its own. That continues until every piece is free, and the results form the separation tree that the Solver animates. The search of a part runs inside the search of the whole, so the whole one's fronts stay in memory until its parts are done.
The level the Solver reports for Pelikan Burr is 99.3.4.2. Each number counts the moves until a single piece comes free. The search above found the first separation after 98 moves, but that separation splits the puzzle into two groups of pieces, not a single piece. The part that came out needs one more move to free a piece, so the first number is 99. The puzzle file's own note agrees: "It takes 98 moves to get the first piece out of the box."
Fast (Crowell), the Solver's other take-apart, keeps the same three fronts and links. The differences are that it takes at most 100 new positions from each position and finds turns with a generator of its own. Because of that limit it can miss a shorter way.
8. The sliding and Panex solvers
The Sliding Puzzle Solver and the Panex Solver also search breadth first for the fewest moves, and they also drop every move that leads to an arrangement they already have. The bookkeeping is different, because their levels can hold millions or billions of arrangements, where a take-apart's usually hold hundreds or thousands.
No links. An arrangement is a single number, a key of 64 or 128 bits, and a level is a sorted list of keys. Nothing points from an arrangement to the one it came from.
The same three levels, on sorted lists. The next level is sorted and merged in one go, which drops repeats within it, and anything already in the two levels before it is dropped. The reason three levels are enough is the one in section 3. With nested slides a few moves cannot be made backwards, and those arrangements are also looked up in the older levels.
The path is rebuilt, not followed. From the last arrangement the solver works out its moves again and looks the results up in the level below. One of them is there, because that is how the arrangement got into its level. It repeats this down to the start. So the older levels are kept on disk for the rebuild, and some can be thinned out.
From both ends. When the goal is a single arrangement, the solvers also search backwards from the goal until the two searches meet. The take-apart cannot do this, because it does not know in advance which position will separate the puzzle.
Every piece's place and turn, the move, the distance and one link back
One 64- or 128-bit key; no link
A level
A hash table of positions
A sorted list of keys, in memory or on disk
Known positions found in
The level before, this level and the next
The new level while it is merged, then the two newest levels; with nested slides, older levels for one-way moves
Moves to known positions
Dropped
Dropped
The path
Followed back along the links
Rebuilt by looking moves up in the level below
What stays behind the fronts
Only positions on a chain of links
Older levels, for the rebuild (some thinned when the disk fills)
From both ends
No: the separating position is not known in advance
Yes, when the goal is one arrangement
The Sliding Puzzle Solver's older search, still used for trays too big for the widest key, works like the take-apart. It keeps a table that gives every arrangement the arrangement it came from, and follows that table back to rebuild the path.
9. Where it comes from
The take-apart search was ported from BurrTools by Andreas Röver: its three fronts, the counted links and the rule that two positions are equal up to a shift of the whole puzzle. The moves are found with Bill Cutler's method from his booklet Computer Analysis of All 6 Piece Burrs. It starts from how far each piece can move while every other piece stands still. ShapeLogic gives the same answers as the original on the comparison corpus.
The counts in sections 4 to 6 come from a copy of the search loop, on one thread, with counters added. It reaches the first separation in the same number of moves as the Solver on every assembly the Solver takes apart completely: Pelikan Burr, Prisgon, Cube in Cage and Dracula's Dental Disaster. The puzzles are the files of those names in ShapeLogic's test data: Pelikan Burr by Dic Sonneveld, Prisgon by Markus Gotz, Cube in Cage by Mineyuki Uyematsu and Dracula's Dental Disaster by Ronald Kint-Bruynseels.
Counts of positions and moves do not depend on the machine or on the number of threads.
Bill Cutler, Computer Analysis of All 6 Piece Burrs: the movement analysis behind the moves.