You are on page 1of 28

AlgorithmsforSolvingRubiksCubes

ErikD.Demaine1,MartinL.Demaine1,SarahEisenstat1,AnnaLubiw2,andAndrewWinslow3
1MITComputerScienceandArtificialIntelligenceLaboratory,Cambridge,MA02139,USA, {edemaine,mdemaine,seisenst}@mit.edu2DavidR.CheritonSchoolofComputerScience,Universityof Waterloo,Waterloo,OntarioN2L3G1,Canada,alubiw@uwaterloo.ca3DepartmentofComputerScience,Tufts University,Medford,MA02155,USA,awinslow@cs.tufts.edu Abstract. The Rubiks Cube is perhaps the worlds most famous and iconic puzzle, wellknown to have a rich underlying mathematical struc ture (group theory). In this paper, we show that the Rubiks Cube also has a rich underlying algorithmic structure. Specifically, we show that the nnn RubiksCube,aswell asthenn1variant, has a Gods Number (diameter of the configuration space) of (n2/log n). The up per bound comes from effectively parallelizing standard (n2) solution algorithms, while the lower bound follows from a counting argument. The upper bound gives an asymptotically optimal algorithm for solving a general Rubiks Cube in the worstcase. Given a specific starting state, we show how to find the shortest solution in annO(1)O(1)Rubiks Cube. Finally, we show that finding this optimal solution becomes NP hard in an nn1 RubiksCube whenthe positionsandcolorsofsomeofthecubiesareignored(notusedindeterminingwhetherthecubeissolved). Keywords:combinatorialpuzzles,diameter,Godsnumber,combinatorialoptimization

1Introduction
A little over thirty years ago, Hungarian architecture professor Ern o Rubik re leased his Magic Cube to the world.4 What we now all know as the Rubiks Cube quickly became a sensation [26]. It is the bestselling puzzle ever, at over 350 million units [15]. It is a tribute to elegant design, being part of the perma nent collection of the Museum of Modern Art in New York[18]. It isan icon for difficultpuzzlesan intellectual Mount Everest. It is the heart of World Cube Associations speedcubing competitions, whose current record holders can solve a cube in under 7 seconds (or 31 seconds blindfold) [1]. It isthebasis for cubeart,aformofpopartmadefrommanycarefullyunsolvedRubiksCubes.(For
4SimilarpuzzleswereinventedaroundthesametimeintheUnitedStates[9][17],the UnitedKingdom[6],andJapan[10]butdidnotreachthesamelevelofsuccess.

2E.D.Demaine,M.L.Demaine,S.Eisenstat,A.Lubiw,A.Winslow

example,therecentmovieExitThroughtheGiftShopfeaturesthestreetcubeartistknownasSpace Invader.)Itisthebaneofmanycomputers,whichspentabout35CPUyearsdeterminingin2010thatthe bestalgorithmtosolvetheworstconfigurationrequiresexactly20movesreferredtoasGodsNumber [22].Toamathematician,orastudenttakingabstractalgebra,theRubiksCubeisashiningexampleof grouptheory.TheconfigurationsoftheRubiksCube,orequivalentlythetransformationsfromone configurationtoanother,formasubgroupofapermutationgroup,generatedbythebasictwistmoves.This perspectivemakesiteasiertoprove(andcompute)thattheconfigurationspacefallsintotwoconnected components,accordingtotheparityofthepermutationonthecubies(theindividualsubcubesthatmakeup thepuzzle).See[7]forhowtocomputethenumberofelementsinthegroupgeneratedbythebasicRubiks Cubemoves(oranysetofpermutations)inpolynomialtime. To a theoretical computer scientist, the Rubiks Cube and its many gen eralizations suggest several natural open problems. What are good algorithms for solving a given Rubiks Cube puzzle? What is an optimal worstcase bound on the number of moves? What is the complexity of optimizing the number of moves required for a given starting configuration? Although Gods Number isknown to be 20 for the 3 3 3, the optimal solution of each configuration in this constantsize puzzle still has not been computed [22] even writing down the first move in each solution would take about 8 exabytes (after factoring out symmetries). While computing the exact behavior for larger cubes is out of the question, how does the worstcase number of moves and complexity scale with the side lengths of the cube? In parallel with our work, these questions were recently posed by Andy Drucker and Jeff Erickson [4]. Scalability isimportant given the commercially available 444 Rubiks Revenge [25] 555 Professors Cube [13]the6 6 6 and 7 7 7 VCUBEs [28] whose design enables cubes as large as 111111 according to Verdess design patent [30] Leslie Les 3Dprinted 121212[14] andOskar van Deventers 171717 Over the Top andhis2220OverlapCube,bothavailablefrom3Dprintershapeways[29]. Diameter / Gods Number. The diameter of the configuration space of a Rubiks Cube seems difficult to capture using just group theory. In general, a set of permutations (moves) can generate a group with superpolynomial diameter [3]. If we restrict each generator (move) to manipulate only k elements, thenthe diameter is O(nk) [16], butthis gives veryweak (superexponential)upper boundsfor n n nandn n 1 RubiksCubes. Fortunately, we show that the general approach taken by folk algorithms for solving Rubiks Cubes of various fixed sizes can be generalizedto perform a constantnumberof movespercubie, for anupper bound of O(n2). This result is essentially standard, but we take care to ensure that all cases can indeed be handled. Surprisingly, this bound is not optimal. Each twist move in the nnn and nn1 Rubiks Cubes simultaneously transforms n(1) cubies (with the expo nent depending on the dimensions and whether a movetransformsaplaneorahalfspace).Thispropertyoffersaformofparallelismforsolvingmultiplecubies

AlgorithmsforSolvingRubiksCubes3

at once, to the extent that multiple cubies want the same move tobe applied at a particulartime. We show that this parallelism can be exploited to reduce the number of moves by a logarithmic factor, to O(n2/logn). Furthermore, an easy counting argument shows an averagecase lower bound of (n2/logn), because the numberofconfigurationsis2(n2)andthereareO(n)possiblemovesfromeachconfiguration. Thuswesettlethediameterofthennnandnn1RubiksCubes,uptoconstantfactors.These resultsaredescribedinSections4and3,respectively. n21 puzzle. Another puzzle that can be described as a permutation group given by generators corresponding to valid moves is the n n generalization of the classic Fifteen Puzzle. This n2 1 puzzle also has polynomial diameter, though lacking any form of parallelism, the diameter is simply (n3) [20]. Interestingly, however, computing the shortest solution from a given configuration of the puzzle is NPcomplete [21]. More generally, given aset ofgenerator permutations, itis PSPACEcomplete tofindthe shortest sequence of generators whose product is a given target permutation [5,11]. These papers mention the Rubiks Cube as motivation, but neither address the natural question: is itNPcomplete tosolve a given n n n or n n 1 Rubiks Cube using the fewest possible moves?Although the n nn problem was posed as early as 1984 [2,21], both questions remainopen[12]. We give partialprogress toward hardness, aswellasapolynomialtimeexactalgorithmforaparticulargeneralizationoftheRubiksCube. Optimization algorithms. We give one positive and one negative result about finding the shortest solution from a given configuration of a generalized RubiksCubepuzzle.On the positive side,we showinSection 6 how to compute the ex act optimum for nO(1)O(1) Rubiks Cubes. Essentially, we prove structural results about how an optimal solution decomposes into moves in the long dimen sion and the two short dimensions, and use this structure to obtain a dynamic program. This result mayprove usefulfor optimally solving configurations of OskarvanDeventers 2220 OverlapCube[29], but it doesnotapplytothe333 Rubiks Cube because we need n to be distinct from the other two side lengths. On the negative side, we prove in Section 5 that it is NPhard to find an optimal solution to a subset of cubies in an nn 1 Rubiks Cube. Phrased differently, optimally solving a given n n 1 Rubiks Cube configuration is NPhard when the colorsand positionsof some cubiesareignored (i.e., theyarenotconsidered in determining whetherthe cubeissolved).

2CommonDefinitions
We begin with some terminology. Anl m n RubiksCubeis composed oflmncubies, each of which has some position (x,y,z), wherex {0,1,...,l1},y {0,1,...,m1}, and z{0,1,...,n1}. Eachcubiealsohasan orientation.EachcubieinaRubiksCubehasacoloroneachvisibleface.Therearesixcolors

4E.D.Demaine,M.L.Demaine,S.Eisenstat,A.Lubiw,A.Winslow

intotal.WesaythataRubiksCubeissolvedwheneachfaceofthecubeisthesamecolor,uniquefor eachface. A slice of aRubiks Cube isa set of cubiesthat matchin onecoordinate (e.g. all of the cubiessuch that y = 1). A legal move on a Rubiks Cube involves rotating one slice around its perpendicular5. In order to preserve the shape of the cube, there are restrictions on how much the slice can be rotated. Ifthe slice to be rotated is a square, then the slice can berotated 90 in eitherdirection.Otherwise,theslicecanonlybe rotated by 180. Finally, note that if one dimension of the cube has length 1, we disallow rotations of the onlysliceinthatdimension.Forexample,wecannotrotatetheslicez=0inthenn1cube. AconfigurationofaRubiksCubeisamappingfromeachvisiblefaceofeachcubietoacolor.Areachable configurationofaRubiksCubeisaconfigurationwhichcanbereachedfromasolvedRubiksCubeviaa sequenceoflegalmoves.ForeachoftheRubiksCubevariantsweconsider,wewilldefinethecontentsofa cubiecluster.Thecubieswhichbelonginthiscubieclusterdependontheproblemweareworkingon however,theydosharesomekeyproperties: 1.Eachcubieclusterconsistsofaconstantnumberofcubies.2.Nosequenceoflegalmovescancause anycubietomovefromonecubie clusterintoanother. Each cubie cluster has a cluster configuration mapping from each visible face of the cubie cluster to its color. Because the number of cubies in a cubie cluster is constant, the number of possible cluster configurationsisalsoconstant. We say that a move affects a cubie cluster ifthemovecausesatleast onecubiein the cubie cluster to change places. Similarly, we say that a sequence of moves affects a cubie cluster if at least one cubie in thecubieclusterwillchangepositionororientationafterthesequenceofmoveshasbeenperformed.

3Diameterofnn1RubiksCube
When considering an n n 1 Rubiks Cube we omit the third coordinate of a cubie, which by necessity must be 0. For simplicity, we restrict the set of solutions to those configurations where the topof the cube isredandthebottomofthecubeisblue. Consider the set of locations that a cubie at position (x, y) can reach. Ifwe flip columnx, the cubie will move to position (x, ny1). If we instead flip row y, the cubie will move to position (nx1,y). Consequently, there are at most four reachable locations for a cubie that starts at (x, y): (x, y),(x, n y 1),(nx1,y),and(nx1,ny1).Wecallthissetoflocationsthecubiecluster(x,y).
5Whileother reasonable definitions of a legal move exist (e.g. rotating a set of con tiguous parallelslices),this movedefinitionmostcloselymatchesthedefinitionusedinpopularmovenotations.

AlgorithmsforSolvingRubiksCubes5

If a cubie is in the first or last row or column, we call it an edge cubie. If a cluster contains an edge cubie, then we call it an edge cluster, because all of its cubies are edge cubies. The special edge cluster which contains the cubie in the first row and first column is called the corner cluster, and its cubies are corner cubies. If n is odd, then there is a cluster with one cubie which is in both the median row and the median column. We will call this cubie the center cubie or center cluster. In addition, ifn is odd then there are also clusters with two cubies found in the median row or column. We call the clusters cross clusters andthecubiesinthemcrosscubies. We begin by showing that for any reachable cluster configuration, there exists a sequence of moves of constantlengthwhichcanbeusedtosolvethatclusterwithoutaffectinganyotherclusters. IntheremainderofSection3,weusethenotationH
1

,H
2

andV
1

,V
2

to denote the two rows and columns containing cubies from a single cubie cluster. We also use the same symbols to denote single moves affecting these rowsand columns. Recall that for a n n 1 cubethere isonly one validnonidentity operation on a row or column: rotation by 180. In thespecial cases of cross andcentercubie clusters, we denotethesingleroworcolumncontainingtheclusterbyHorV,respectively. Webeginbyprovingthefollowinglemmaaboutcubieclusterconfigurations. Lemma1.Inasolvablenn1RubiksCube,thecolorsonthetopfacesofthecubiesinacubiecluster canonlybeinthesixconfigurationsinFig.1. Proof. Consider what happens to a cubie cluster when a move is performed.If the movedoes not affectthe cubie cluster, then its cubie configuration will not change. Otherwise, the move will swap twocubies in the same row or column while reversing the color of each cubie. If both cubies are the same color, then both cubies will become the other color. In other words, if one cubie is red and the other is blue, thenthecolor configurationwillnotchange. Figure 1(a) shows the solved configuration, which is quite obviously reach able. The four moves which affect this cubie cluster result in configurations 1(b), 1(c), 1(d), and 1(e). Consider how the four possible moves affect each of configu rations 1(b), 1(c), 1(d), and 1(e). For each configuration, two of the four possible moves involve one red cubie and one blue cubie,and therefore donotaffectthecolors. Inaddition, one move for each configuration is the inverse of the move used to reach that configuration, and therefore leads back to configuration 1(a). The final move for each configuration results in configuration 1(f), thus completingthesetofreachableconfigurations. Becauseoftheselimitationsoncubieclusterconfigurations,wecanprovethefollowinglemma. Lemma 2. All six cluster configurations from Lemma 1 can be solved using a sequence of at most six movesthatdoesnotaffectthepositionofanycubiesnotinthecubiecluster.(SeeFig.1.)

6E.D.Demaine,M.L.Demaine,S.Eisenstat,A.Lubiw,A.Winslow

H 1 H 2 V 1 V 2 (a)Solved. V 1 V 2 (b)V 1 V 1 V 2 H 1 H 1 H 2 H 2 ,H 1 ,V 1 ,H 1 . (c)V 2

,H 1 ,V 2 ,H 1 . H 1 H 2 V 1 V 2 V 1 V 2 V 1 V 2 H 1 H 1 H 2 H 2 (d)H 1 ,V 1 ,H

1 ,V 1 . (e)H 2 ,V 1 ,H 2 ,V 1 . (f)H 1 ,H 2 ,V 1 ,H 1 ,H 2 ,V 1 . Fig.1.Thereachableclusterconfigurationsandthemovesequencestosolvethem.

Proof. The correct move sequence for each configuration from Lemma 1 is given in Fig. 1. Thefactthat we always use each move twice ensures that all other clusterswillnotbe affected by the move sequence. The correctnessofthesesequencescanbeverifiedbythereader. In order to handle the edge, corner, and cross clusters, we need a more complicated sequence of moves. These clusters cannot always be solvedwithoutaffectinganyother cubes.Soratherthan show that wecansolveeachclusterindividually,weshowthatwecansolveallsuchclusterstogether. Lemma 3. Given a solvable configuration of ann n 1Rubiks Cube, thereexistsa sequence of moves of lengthO(n)whichcanbeusedtosolvetheedgeclustersandcrossclusters. Proof. We begin by solving the corner cluster, and, if n is odd, the center cluster and the two edge cross clusters. These four clusters combined have only O(1) reachable configurations, and so all four can be

obviously be fixed in O(1) moves, disregardingtheeffect that these moves might have onanyother clusters. Next we solve the other edge clusters.Our goalis to solve eachcluster without affecting any of the clusters wehavepreviouslysolved. Without loss of generality, say that we are trying to solve an edge cluster with coordinates (x,0). We begin by using the move sequences from Lemma 2 to make sure that the cluster has all four red stickers visible. Then it will be in one of the states depicted in Fig. 2. To solve the cluster, we can use the move sequences given in Fig. 2. Although the given move sequences are not guaranteed to apply the identity permutation to all other clusters, they do have the property that any horizontal move will be performed an evennumberoftimes.Hence,this

AlgorithmsforSolvingRubiksCubes7

movesequencewillapplytheidentitypermutationtoallotheredgeclusters.Inaddition,noneofthemove sequencesaffectthecentercubie.
H 1 H 2 V 1 V 2 (a)Solved. V 1 V 2 (b)H 1 V 1 V 2 (c)H 1 V 1 V 2H 1 H 1 H 1 H 2 H 2

H 2 ,V 1 ,H 1 . ,V 2 ,H 1 . (d)H 1 ,V 1 ,V 2 ,H 1 . Fig.2.Whenallfourredstickersarefacingforwards,thesearethepossibleconfigurationsforanedgecluster, andthemovesequencesusedtosolvethem.

Once all the edge clusters have been solved, we want to solve the cross clus ters. We know that the center cluster has already been solved. Wealso knowthat there areO(n)crossclusters, so ifwe can solve each cross cluster inO(1)moveswithout affecting the rest oftheclusters, thenwe will have solved the edge and cross clusters in a total of O(n) moves. Without loss of generality, say that we are trying to solve the crosscluster((n1)/2,y).ThefourpossiblestatesforacrossclusteraredepictedinFig.3.
H 1 H 2 V (a)Solved. V (b)n/a. V

(c)n/a. V H 1 H 1 H 1 H 2 H 2 H 2 (d)H 1 ,V,H 1 ,V. Fig.3.Thefourreachableconfigurationsforacrosscluster.Twoofthemcanbesolvedwithoutaffectingtherestof theclusters.

However, because we have already solved all of the edge clusters, we know that the set of possible configurations for our cross cluster is more restricted. Both horizontal movesaffectingourcrosscluster will cause one of the two cubies to change color. Nomatterwhat state the crossclusteris in, the vertical move cannot change the color of only one cubie. Therefore, if the cross cluster is in the configurationdepicted in Fig. 3(b) or the configuration depicted in Fig.3(c),then the restofthesolution mustperform either the move H
1

orthemoveH 2anoddnumberoftimes. ConsidertheeffectofthisontheedgeclusteraffectedbyH


1

andH
2

.Eachmoveintheedgecluster causesaswapoftwocubies.Ifanorderisplacedon

8E.D.Demaine,M.L.Demaine,S.Eisenstat,A.Lubiw,A.Winslow

the cubies inthecluster,eachswap isapermutation of thisorder, and the setof permutationsconstructible usingswapsisequivalenttothepermutationgroupon4elements,S
4

. By permutation group theory, if a particular cluster configuration can be solved using an even number of swaps, then any solution for that cluster configuration has an even number of swaps. We know that the edge cluster is already solved, so it can be solved using an even number of swaps.SoiftherestofthesolutioncontainsanoddnumberofmovesH
1

andH
2

,thenitmustalsocontainanodd numberofedgemovesV
1

andV
2

.
H H(a)(b)(c)(d) V 2 V 2 V 1 V 1V 1 V 1 V 2 V 2 (e)(f)(g)(h) H H Fig.4.Thepossibleconfigurationsofanedgecrosscluster.

Now consider the effect of an odd number of edge moves on the affected edge cross cluster. Figure 4 gives the configuration space for that cluster. We know that it is currently in the solved state labelled (a). AnysequenceofmoveswhichcontainsanoddnumberofedgemovesV
1

andV
2

will cause theedgecrosscluster toleave the solved state.SotherestofthesolutioncannotcontainanoddnumberofedgemovesV


1

andV
2

.Thismeansthattherestofthesolutioncannotcontainanodd numberofhorizontalmovesH
1

andH
2

affecting a single cross cluster. So every cross cluster must be in one of the states depicted in Figs. 3(a) and 3(d), each of which can be solved withoutaffectinganyotherclustersusingthesequenceofmoveslistedforeachstate. 3.1nn1UpperBound There are n2 clusters in the nn1 Rubiks Cube. If we use the move sequences given in Fig. 1 to solve each cluster individually, we have a sequence ofO(n2) moves forsolving the entirecube. In this section, we takethissequenceofmovesandtakeadvantageofparallelismtogetasolutionwithO(n2/logn)moves. SaythatwearegivencolumnsXandrowsYsuchthatallofthecubieclusters(x,y)XYareinthe configurationdepictedinFig.1(b).Ifweattempted

AlgorithmsforSolvingRubiksCubes9

tosolveeachoftheseclustersindividually,thenumberofmovesrequiredwouldbeO(|X||Y|). Consider insteadwhat would happenif wefirstflipped all ofthe columns x X, thenflippedalloftherows y Y , then flipped all of the columnsx X again, and finally flippedalloftherows yY again.What would be the effect of this move sequence on a particular(x,y) XY ? Theonlymovesaffecting thatcluster are the column moves x and (n 1 x) and the row moves y and (n1y). So the subsequence of moves affecting (x,y) would consist of the column move x, followed by the row movey, followedby thecolumn move x again, and finally the row move y again. Those four moves are exactly themovesneeded to solve thatcluster. Thisideaallowsustoparallelizethesolutionsformultipleclusters,resultinginthefollowinglemma. Lemma 4. Given an n n 1 Rubiks Cube configuration and sets X, Y {0,1,...,n/2 1}, if all cubie clusters (x, y) X Y are in the same cluster configurations, then all cubie clusters (x, y) XY can be solvedinO(|X|+|Y|)moveswithoutaffectingtherestofthecubies. Proof. By Lemma 2, we know that there exists a sequence of moves of length at most six whichwillsolve the configuration of a single cubie cluster (x, y) XY . We writethis sequence of moves inageneral form asinLemma2.WethenreplaceeachmoveV
1

withasequenceofmovesthatflipseachcolumnxX.Similarly,wereplaceeach moveV
2

withasequenceofmovesthatflipseachcolumnnx1,wherex X.WeperformsimilarsubstitutionsforH
1

andH
2

, using the rows y and n y 1 instead. Because the original sequence of moves had length at most six,itiseasytoseethatthelengthofthenewmovesequenceisO(|X|+|Y|).
(a)(b)(c)(d)(e) Fig.5.Solvingfourcubieclustersatthesametime.

We claim that this new sequence of moves will solve all cubie clusters (x,y)X Y, and thatno other cubie clusters will be affected. To see that this is true, consider how some cubie cluster (x,y) {0,1,...,n/21}{0,1,...,n/2 1} will be affected by the move sequence. If x / X and y /Y , then none of the moves in the sequence will affect the position of any cubies in the cubie cluster, and therefore the cubieclusterwillbeunaffected.IfxXandyY,then

10E.D.Demaine,M.L.Demaine,S.Eisenstat,A.Lubiw,A.Winslow

the subsequence of moves whichaffect thiscubiecluster will beexactly the se quenceofmoves necessary to solve this cubie cluster. Otherwise, either x X or y Y , but not both. Therefore,the subsequence of moves which affect this cubie cluster will be either all vertical, or all horizontal, and each move will occur exactly twice. This means that the subsequence of moves which affect this cubie cluster will apply the identitypermutationtothiscubiecluster. This technique allows us to solve all cubie clusters (x, y) X Y using only O(|X|+ |Y|) moves, ifeach one of those clusters is in the same configuration. Our goal is to use this technique for a relatedproblem: solving all of the cubie clusters (x, y) X Y that are in a particularcluster configuration c,leavingtherest of the clusters alone. To that end, we divide up the columns X according to the pattern of rows that are in configurationc,andsolveeachsubsetoftherowsusingthetechniqueofLemma4.Moreformally: Lemma 5. Suppose we are given an n n 1 Rubiks Cube configuration, a cluster configuration c, and sets X, Y {0,1,...,n/2 1}such that |X| = l.Then all cubie clusters (x, y) X Y that arein configuration ccanbesolvedinO(l2l+|Y|)moveswithoutaffectingtherestofthecubies. Proof.ForeachyY,wedefineS
y

={xX|thecubiecluster(x,y)isinconfiguration2lc}.ForeachS X,weletY
S

={yY|S
y

=S}.TherearepossiblevaluesforS.Foreach Y
S

,weusethesequenceofmoveswhichisguaranteedtoexistby Lemma4tosolveall(x,y)SY
S

.ThissequenceofmoveshaslengthO(|S|+ |Y
S

|)=O(l+|Y
S

|).WhenwesumthelengthsupforallY
S

,wefindthatthenumberofmovesisboundedby O ( l2l+

) =O
S

( l2l+|Y| ) . Unfortunately, this resultis not costeffective. We need tomakesurethatl issmall enoughto preventan exponential blowup in thecostof solving the RubiksCube. To that end, we divide upthecolumns into small groupstogetthefollowingresult: Lemma 6. Suppose we are given an n n 1 Rubiks Cube configuration, a cluster configuration c, and sets X, Y {0,1,...,n/2 1}.Then all cubie clusters (x, y) X Y that arein configuration ccanbe solved inO(|X||Y|/log|Y|)moveswithoutaffectingtherestofthecubies. Proof.Letl=12 |Y
S

| Xintoaseriesoflog sets2 |YX|,1 so,...,Xthatk 2leach= of|Ywhich|.Lethask=size|X|/l.l.PartitionFortheset eachX


i

,wesolvethecubieclustersin X
i

YusingthesequenceofmovesthatisguaranteedtoexistbyLemma5.The numberofmovesrequiredtosolveasingleX
i

is O (

l2l+|Y| ) =O (( 12 log
2

|Y| ) |Y|+|Y| ) =O(|Y|).

You might also like