# Programming Abstractions: Lecture 10

## Lecture 10

Instructor (Julie Zelenski):Hey there. Welcome. Welcome. Welcome. My computer's not quite talking to anything yet here. You guys got an answer for that? Unplug and replug that? Okay, I don't know what's – whether somebody can help make my computer talk to the projector? Yeah. It's plugged in like ordinary. Yeah, I – we do this every day. There we go. Thank you very much. All right, back to your regularly scheduled lecture.

Today I'm gonna keep talking a little bit more about another procedural recursion example and then go on to talk about, kind of, the approach for recursive backtracking, which is taking those procedural recursion examples and kind of twisting them around and doing new things with them. This corresponds with to the work that's in chapter six of the reader.

Student:

A B C D.

Instructor (Julie Zelenski):A B C D. So the exact string I gave it, right, is the one that it picks, right, the very first time, and that's because, if you look at the way the for loop is structured, the idea is that it's gonna make a choice and it's gonna move through the recursion. Well, the choice it always makes is to take the next character of rest and attach it to the permutation as its first time through the for loop. So the first time through the very first for loop it's got A B C D to chose, it chooses A, and now it recurs on A in the permutation and B C D to go.

Well, the next call does exactly the same thing, chooses the first of what remains, which is B, attaches it to the permutation and keeps going. So the kind of deep arm of the recursion making that first choice and working its way down to the base case, right, right remember the recursion always goes deep. It goes down to the end of the – and bottoms on the recursion before it comes back and revisits any previous decision, will go A B C D, and then eventually come back and start trying other things, but that very first one, right, is all just the sequence there.

The next one that's after it, right, is A B D C, which involved unmaking those last couple decisions. If I look at the tree that I have here that may help to sort of identify it. That permute of emptying A B C, the first choice it makes is go with A, and then the first choice it makes here is go with B, and so on, so that the first thing that we can see printed our here will be A B C D, we get to the base case.

Once it's tried this, it'll come back to this one, and on this one it'll say, well, try the other characters. Well, there's no other characters. In fact, this one also finishes. It'll get back to here as it unwinds the stack the way the stack gets back to where it was previously in these recursive calls. And now it says, okay, and now try the ones that have, on the second iteration of that for loop, D in the front, and so it ends up putting A B D together, leaving C, and then getting A B D C.

And then, so on kind of over here, the other variations, it will print all of the ones that have A in the front. There are eight of them. I believe three, two – no, six. Six of them that have A in the front, and we'll do all of those. And only after having done all of working out that whole part, which involves kind of the [inaudible] of this whole arm, will eventually unwind back to the initial permute call, and then say, okay, now try again. Go with B in the front and work your way down from reading the A C D behind it. So we'll see all the As then the bunch that lead with B, then the bunch that leads with C, and then finally the bunch that leads with D.

It doesn't turn out – matter, actually, what order it visits them in because, in fact, all we cared about was seeing all of them. But part of what I'm trying to get with you is the sense of being able to look at that recursive code, and use your mind to kind of trace its activity and think about the progress that is made through those recursive calls. Just let me look at that code just for a second more and see if there's any else that I want to highlight for you.

I think that's about what it's gonna do. So if you don't understand this cost, if there's something about it that confuses you, now would be an excellent time for you to ask a question that I could help kind of get your understanding made more clear. So when you look at this code, you feel like you believe it works? You understand it?

Student:[Inaudible]. I have a question. Is there a simple change you can make to this code so that it does combinations [inaudible]?

Instructor (Julie Zelenski):Does combinations – you mean, like, will skip letters?

Student:Right.

Instructor (Julie Zelenski):Yes. It turns out we're gonna make that change in not five minutes. In effect, what you would do – and there's a pretty simple change with this form. I'm gonna show you a slightly different way of doing it, but one way of doing it would be to say, well, give me the letter, don't attach it to next right? So right now, the choices are pick one of the letters that remain and then attach it to the permutation. Another option you could do was pick a letter and just discard it, right? And so, in which case, I wouldn't add it into so far. I would still subtract it from here, and I'd make another recursive call saying, now how about the permutations that don't involve A at all? And I would just drop it from the thing and I would recurs on just the B C D part. So a pretty simple change right here. I'm gonna show you there's a slightly different way to formulate the same thing in a little bit, but – anybody want to own up to having something that confuses them?

Student:

[Inaudible] ask how you, like, what you would set up to test it?

Instructor (Julie Zelenski):So [inaudible] one of the, you know, the easiest thing to do here, and I have the code kind of actually sitting over here just in case, right, hoping you would ask because right now I just have the most barebones sort of testing. It's like, yeah, what if I just, you know, throw some strings at it and see what happens, right? And so the easiest strings to throw at it would be things like, well what happens if I give it the empty string, right? You know, so it takes some really simple cases to start because you want to see, well what happens when, you know, you give it an empty input. Is it gonna blow up?

And it's, like, the empty input, right, immediately realizes there's no choices and it says, well, look, there's nothing to print other than that empty string. What if I give it a single character string? Right? I get that string back. I'm like, okay, gives me a little bit of inspiration that it made one recursive call, right, and then hit the base case on the subsequent one. Now I start doing better ones.

A and B, and I'm seeing A B B A. Okay, so I feel like, you know, I got this, so if I put a C in the front, and I put the B A behind, then hopefully what I believe is that it's gonna try, you know, C in the front, and then it's gonna permute A and B behind it, and then similarly on down. So some simple cases that I can see verifying that it does produce, kind of, the input string as itself, and then it does the back end rearrangement, leaving this in the front, and then it makes the next choice for what can go in the front, and then the back end rearrangement. And kind of seeing the pattern that matches my belief about how the code works, right, helps me to feel good. What happens if I put in something that has double letters in it? So I put A P P L E in there. And all the way back at the beginning, right, I can plot more of them, right, that grows quite quickly right as we add more and more letters, right? Seeing the apple, appel, and stuff like that. There's a point where it starts picking the P to go in the front, and the code as it's written, right, doesn't actually make it a combination for this P and this P really being different. So it goes through a whole sequence of pull the second character to the front, and then permute the remaining four. And then it says, and now pull the third character to the front and permute the remaining four, which turns out to be exactly the same thing. So there should be this whole sequence in the middle, right, of the same Ps repeated twice because we haven't gone over a way to do anything about that, right? So – but it is reassuring to know that it did somehow didn't get, you know, confused by the idea of there being two double letters. [Inaudible] if I do this – if I just say A B A, right? Something a little bit smaller to look at, right? A in the front. A in the front goes permuted, B in the front, and then it ends up permuting these two ways that ends up being exactly the same, and then I get a duplicate of those in the front. So right now, it doesn't know that there's anything to worry about in terms of duplicates? What's a really easy way to get rid of duplicates? Don't think recursively, think – use a set. Right? I could just stuff them in a set, right? And then if it comes across the same one again it's like, yeah, whatever. So it would still do the extra work of finding those down, but would actually, like, I could print the set at the end having coalesced any of the duplicates. To actually change it in the code, it's actually not that hard either. The idea here is that for all of the characters that remain, right, and sometimes what I want to choose from is of the remaining characters uniqued, right? Pick one to move to the front. So if there's three more Ps that remain in rest, I don't need to try each of those Ps individually in the front, right? They'll produce the same result – pulling one and leaving the other two behind is completely irrelevant. So an easy way to actually stop it from even generating them, is when looking at the character here is to make sure that it is – that it doesn't duplicate anything else in the rest. And so probably the easiest way to do that is to either pick the first of the Ps or the last of the Ps, right, and to recur on and ignore the other ones. So, for example, if right here I did a find on the rest after I – do you see any more of these? And if you do, then skip it and just let those go. Or, you know, do the first. Don't do the remaining ones. You can either look to the left of look to the right and see if you see any more, and if so, skip the, you know, early or later ones depending on what your strategy is. Any questions about permute here?

Student:

[Inaudible].

Instructor (Julie Zelenski):So the [inaudible] can be just – look down here, right, it just looks like that, right? This is a very common thing. You'll see this again, and again, and it tends to be that the outer call, right, it tends to have this sort of this, you know, solve this problem, and then it turns out during the recursive calls you need to maintain some state about where you are in the problem. You know, like, how many letters you moved, or what permutation you've built so far, or where you are in the maze, or whatever it is you're trying to solve.

And so typically that wrapper call is just gonna be setting up the initial call in a way that has the initial form of that state present that the client to the function didn't need to know about. It's just our own housekeeping that we're setting up. Seems almost kind of silly to write down the function that has just line that just turns it into, basically, it's just exchanging – setting up the other parameters.

I am going to show you the other kind of master patter, and then we're gonna go on to kind of use them to solve other problems. This is the one that was already alluded to, this idea of a combinations. Instead of actually producing all of the four character strings that involve rearrangements of A B C D, what if I were to [inaudible] in kind of the subgroups, or the way I could chose certain characters out of that initial input, and potentially exclude some, potentially include some?

So if I have A B C, then the subsets of the subgroups of that would be the single characters A B and C. The empty string A B and C itself the full one, and then the combinations of two, A B, A C, and B C. Now, in this case we're gonna say that order doesn't matter. We're not – whereas permutations was all about order, I'm gonna use – I'm gonna structure this one where I don't care. If it's A B or B A I'm gonna consider it the same subset. So I'm just interested in inclusion. Is A in or out? Is B in or out? Is C in or out?

And so the recursive strategy we're gonna take is exactly what I have just kind of alluded to in my English description there, is that I've got an input, A B C. Each of those elements has either the opportunity of being in the subset or not. And I need to make that decision for everyone – every single element, and then I need to kind of explore all the possible combinations of that, right? When A is in, what if B is out? When A is in, what if B is in? So the recursion that I'm gonna use here is that at each step of the way, I'm gonna separate one element from the input, and probably the easiest way to do that is just to kind of take the front most element off the input and sort of separate it into this character by itself and then the remainder.

Similarly, the way I did with permute, and then given that element I have earmarked here, I can try putting it in the current subset or not. I need to try both, so I'm gonna make two recursive calls here, one recursive call where I've added it in, one recursive call where I haven't added it in. In both cases, right, I will have removed it from the rest, so what's being chosen from to complete that subset always is a little bit smaller, a little bit easier. So this is very, very much like the problem I described as the chose problem. Trying to choose four people from a dorm to go to flicks was picking Bob and then – [inaudible] to Bob and not Bob, and then saying, well, Bob could go, in which I need to pick three people to go with him, or Bob could not go and I need to pick four people to go without Bob.

This is very much that same pattern. Two recursive calls. Identify one in or out. The base case becomes when there's nothing left to check out. So I start with the input A B C – A B C D let's say. I look at that first element – I just need to pick one. Might as well pick the front one, it's the easy one to get to. I add it to the subset, remove it from the input, and make a recursive call. When that recursion completely terminates, I get back to this call, and I do the same thing again.

Remaining input is B C D again but now the subset that I've been building doesn't include. So inclusion exclusion are the two things that I'm trying. So the subset problem, right, very similar in structure to the way that I set up permutations, right, as I'm gonna keep track of two strings as I'm working my way down the remainder in the rest, right, things that I haven't yet explored so far is what characters I've chosen to place into the subset that I'm building. If I get to the end where there's nothing left in the rest, so there's no more choices to make, then what I have in the subset is what I have in the subset, and I go ahead and print it.

Student:

What would be the simplest way to do that?

Instructor (Julie Zelenski):So probably the simplest way, like, if you said, oh, I just really want it to be in alphabetical order, would be to put them in a set, right, and then have the set be the order for you.

Student:So you said order doesn't matter?

Instructor (Julie Zelenski):Oh, you did care about how they got ordered.

Student:So, like, let's say you didn't want B C D to equal C D B.

Instructor (Julie Zelenski):So in that case, right, you would be more likely to kind of add a permutation step into it, right? So if B C D was not the same thing as A B C, right, it would be, like, well I'm gonna chose – so in this case, right, it always – well the subsets will always be printed as kind of a subsequence. So – and let's say if the input was the alphabet, just easy way to describe it, all of the subsets I'm choosing will always be in alphabetical order because I'm always choosing A in or not, B in or not.

If I really wanted B Z to be distinct from Z B, then really what I want to be doing at each step is picking the next character to go, and not always assuming the next one had to be the next one in sequence, so I would do more like a permute kind of loop that's like pick the next one that goes, remove it from what remains and recur, and that I need that separate step we talked about of – and in addition to kind of picking, we also have to leave open the opportunity that we didn't pick anything and we just kind of left the subject as is, right, so we could [inaudible] or not.

And so permute always assumes we have to have picked everything. The subset code would also allow for some of them just being entirely skipped. So we pick the next one, right, and then eventually stopped picking.

Student:[Inaudible] just in your wrapper function then [inaudible] put a for loop or something like that, right? When you're through changing your string?

Instructor (Julie Zelenski):Yeah, you can certainly do that, like in a permute from the outside too, right. So there's often very, you know, multiple different ways you can get it the same thing whether you want to put it in the recursion or outside the recursion, have the set help you do it or not, that can get you the same result.

So let me try to identify what's the same about these to try to kind of back away from it and kind of move just to see how these are more similar than they are different, right, even though the code ends up kind of being – having some details in it that – if you kind of look at it from far away these are both problems that are about choice. That the recursive calls that we see have kind of a branching structure and a depth factor that actually relates to the problem if you think about it in terms of decisions, that in making a permutation your decision is what character goes next, right? In the subset it's like, well, whether this character goes in or not that the recursive tree that I was drawing that it shows all those calls, the depths of it represents the number of choices you make.

Each recursive call makes a choice, right? A yes, no, or a next letter to go, and then recurs from there. So I make, you know, one of those calls, and then there's N minus 1 beneath it that represent the further decisions I make that builds on that. And so, in the case of permutation, once I've picked the, you know, N minus 1 things to go, there's only one thing left, right? And so in some sense the tree is N because I have to pick N things that go in the permutation and then I'm done.

In the subsets, it's also N, and that's because for each of the characters I'm deciding whether it's in or out. So I looked at A and decided in or out. I looked at B and decided in or out. And I did that all the way down. That was the life of the input. The branching represents how many recursive calls were made at each level of the recursion. In the case of subsets, it's always exactly two. In, out, all the way down, restarts at 1, branches to 2, goes to 4, goes to 8, 16, and so on.

In the permute case, right, there are N calls at the beginning. I have N different letters to choose from, so it's a very wide spread there, and that at that next level, it's N minus 1. Still very wide. And N minus 2. And so the overall tree has kind of an N times N minus 1 times N minus 2 all the way down to the bottom, which the factorial function – which grows very, very quickly.

Even for small inputs, right, the number of permutations is enormous. The number of subsets is to the end in or out, right, all the way across. Also, a very, you know, resource intensive problem to solve, not nearly as bad as permutation, but both of them, even for small sizes of N, start to become pretty quickly intractable. This is not the fault of recursion, right, these problems are not hard to solve because we're solving them in the wrong way.

It's because there are N factorial permutations. There are [inaudible] different subsets, right? Anything that's going to print to the N things, or N factorial things is going to do N factorial work to do so. You can't avoid it. There's a big amount of work to be done in there. But what we're trying to look at here is this idea that those trees, right, represent decisions. There's some decisions that are made, you know, a decision is made at each level of recursion, which then is kind of a little bit closer to having no more decisions to make. You have so many decisions to make, which is the depth of the recursion. Once you've made all those decisions, you hit your base case and you're done.

The tree being very wide and very deep makes for expensive exploration. What we're gonna look at is a way that we can take the same structure of the problem, one that fundamentally could be exhaustive, exhaustive meaning tried every possible combination, every possible rearrangement and option, and only explore some part of the tree. So only look around in some region, and as soon as we find something that's good enough.

So in the case, for example, of a search problem, it might be that we're searching this space that could potentially cause us to look at every option, but we're also willing to say if we make some decisions that turn out good enough, that get us to our goal, or whatever it is we're looking for, we won't have to keep working any farther. So I'm gonna show you how we can take an exhaustive recursion problem and turn it into what's called a recursive backtracker.

So there's a lot of text on this slide but let me just tell you in English what we're trying to get at. That the idea behind permutations or subsets is that at every level there's all these choices and we're gonna try every single one of them. Now imagine we were gonna make a little bit less a guarantee about that. Let's design the function to return some sort of state that's like I succeeded or I failed. Did I find what I was looking for? At each call, I still have the possibility of multiple calls of in out, or a choice from what's there. I'm gonna go ahead and make the choice, make the recursive call, and then catch the result from that recursive call, and see whether it succeeded.

Was that a good choice? Did that choice get me to where I wanted to be? If it did, then I'm done. I won't try anything else. So I'll stop early, quite going around the for loop, quit making other recursive calls, and just immediately [inaudible] say I'm done. If it didn't – it came back with a failure, some sort of code that said it didn't get where I want to do, then I'll try a different choice. And, again, I'll be optimistic. It's a very optimistic way of doing stuff. It says make a choice, assume it's a good one, and go with it. Only when you learn it didn't work out do you revisit that decision and back up and try again. So let me show you the code. I think it's gonna make more sense, actually, if I do it in terms of looking at what the code looks like. This is the pseudo code at which all recursive backtrackers at their heart come down to this pattern.

So what I – I tried to be abstract [inaudible] so what does it mean to solve a problem, and what's the configuration? That depends on the domain and the problem we're trying to solve. But the structure of them all looks the same in that sense that if there are choices to be made – so the idea is that we cast the problem as a decision problem. There are a bunch of choices to be made. Each [inaudible] will make one choice and then attempt to recursively solve it.

So there's some available choices, in or out, or one of next, or where to place a tile on a board, or whether to take a left or right turn and go straight in a maze. Any of these things could be the choices here. We make a choice, we feel good about it, we commit to it, and we say, well, if we can solve from here – so we kind of update our statement so we've made that term, or, you know, chosen that letter, whatever it is we're doing.

If that recursive call returned true then we return true, so we don't do any unwinding. We don't try all the other choices. We stop that for loop early. We say that worked. That was good enough. If the solve came back with a negative result, that causes us to unmake that choice, and then we come back around here and we try another one. Again, we're optimistic. Okay, left didn't work, go straight. If straight doesn't work, okay, go right. If right didn't work and we don't have any more choices, then we return false, and this false is the one that then causes some earlier decision to get unmade which allows us to revisit some earlier optimistic choice, undo it, and try again.

The base case is hit when we run out of choices where we've – whatever configuration we're at is, like, okay, we're at a dead end, or we're at the goal, or we've run out of letters to try. Whatever it is, right, that tells us, okay, we didn't – there's nothing more to decide. Is this where we wanted to be? Did it solve the problem? And I'm being kind of very deliberate today about what does it mean [inaudible] update the configuration, or what does it mean for it to be the goal state because for different problems it definitely means different things. But the code for them all looks the same kind of in its skeletal form.

So let me take a piece of code and turn it into a recursive backtracker with you. So I've got recursive permute up here. So as it is, recursive permute tries every possible permutation, prints them all. What I'm interested in is is this sequence a letters an anagram. Meaning, it is – can be rearranged into something that's an English word.

Okay. So what I'm gonna do is I'm gonna go in and edit it. The first thing I'm gonna do is I'm gonna change it to where it's gonna return some information. That information's gonna be yes it works, no it didn't. Okay? Now I'm gonna do this. I'm gonna add a parameter to this because I – in order to tell that it's a word I have to have someplace to look it up. I'm gonna use the lexicon that actually we're using on this assignment.

And so when I get to the bottom and I have no more choices, I've got some permutation I've assembled here in – so far. And I'm going to check and see if it's in the dictionary. If the dictionary says that that's a word then I'm gonna say this was good. That permutation was good. You don't need to look at any more permutations. Otherwise I'll return false which will say, well, this thing isn't a word. Why don't you try again?

I'm gonna change the name of the function while I'm at it to be a little more descriptive, and we'll call it is anagram. And then when I make the call here [inaudible] third argument. I'm not just gonna make the call and let it go away. I really want to know did that work, so I'm gonna say, well, if it's an anagram then return true. So if given the choice I made – I've got these letters X J Q P A B C, right? It'll pick a letter and it'll say, well if, you know, put that letter in the front and then go for it.

If you can make a word out of having made that choice, out of what remains, then you're done. You don't need to try anything else. Otherwise we'll come back around and make some of the further calls in that loop to see if it worked out. At the bottom, I also need another failure case here, and that comes when the earlier choices, right – so I got, let's say somebody has given me X J, and then it says, given X J, can you permute A and B to make a word?

Okay, so now I'm going to make my second recursive call. I say I've placed one queen, now there's three more queens to go. Why don't we go ahead and place the queens that remain to the right of this. And so the next recursive call comes in and says, if you can place the queens given the decision I've already made, then tell me yes, and then I'll know all is good.

So it looks at the bottommost row, and it says, oh, no, that won't work, right? There's a queen right there. It looks at the next one and then sees the diagonal attack. Okay. Moves up to here and says, okay, that's good. That'll work, right? Looks at all of them and it's okay. So now it says, okay, well I've made two decision. There's just two to go. I'm feeling good about it. Go ahead and make the recursive call.

The third call comes in, looks at that row, not good, looks at that row, not good, looks at that row, not good, looks at that row, not good. Now this one – there weren't any options at all that were viable. We got here, and given the earlier decisions, and so the idea is that, given our optimism, right, we sort of made the calls and just sort of moved on. And now we've got in the situation where we have tried all the possibilities in this third recursive call and there was no way to make progress. It's gonna hit the return false at the bottom of the backtracking that says, you know what, there was some earlier problem.

There was no way I could have solved it given the two choices – or, you know, whatever – we don't even know what choices were made, but there were some previous choices made, and given the state that was passed to this call, there's no way to solve it from here. And so this is gonna trigger the backtracking. So that backtracking is coming back to an earlier decision that you made and unmaking it. It's a return false coming out of that third call that then causes the second call to try again.

And it goes up and it says okay, well where did I leave off? I tried the first couple of ones. Okay, let's try moving it up a notch and see how that goes. Then, again, optimistic, makes the call and goes for it. Can't do this one. That looks good. And now we're on our way to placing the last queen, feeling really comfortable and confidant, but discovering quickly, right, that there was no possible.

So it turns out this configuration with these three queens, not solvable. Something must be wrong. Back up to the most immediate decision. She knows it doesn't unmake, you know, earlier decisions until it really has been proven that that can't work, so at this point it says, okay, well let's try finding something else in this column. No go. That says, okay, well that one failed so it must be that I made the wrong decision in the second column.

Well, it turns out the second column – that was the last choice it had. So in fact it really was my first decision that got us off to the wrong foot. And now, having tried everything that there was possible, given the queen in the lower left in realizing none of them worked out, it comes back and says, okay, let's try again, and at this point it actually will go fairly quickly. Making that initial first decision was the magic that got it solved.

And then we have a complete solution to the queens. We put it onto eight, and let it go. You can see it kind of checking the board, backing up, and you notice that it made that lower left decision kind of in – it's sticking to it, and so the idea is that it always backs up to the most recent decision point when it fails, and only after kind of that one has kind of tried all its options will it actually back up and consider a previous decision as being unworthy and revisiting it.

In this case that first decision did work out, the queen being in the lower left. It turns out there were – you know, you saw the second one had to kind of slowly get inched up in the second row. Right? It wasn't gonna work with the third row. It tried that for a while. Tried the fourth row for a while. All the possibilities after that, but eventually it was that fifth row that then kind of gave it the breathing room to get those other queens out there.

But it did not end up trying, for example, all the other positions for the queen in the first row, so it actually – it really looked at a much more constrained part of the entire search tree than an exhaustive recursion of the whole thing would have done. The code for that –whoops – looks something like this. And one of the things that I'll strongly encourage you to do when you're writing a recursive backtracking routine, something I learned from Stuart Regis, who long ago was my mentor, was the idea that when – trying to make this code look as simple as possible, that one of the things you want to do is try to move away the details of the problem.

For example, like, is safe – given the current placement of queens, and the row you're trying, and the column you're at, trying to decide that there's not some existing conflict on the board with the queen already being threatened by an existing queen just involves us kind of traipsing across the grid and looking at different things. But putting in its own helper function makes this code much easier to read, right?

Similarly, placing the queen in the board, removing the queen from the board, there are things they need to do. Go up to state and draw some things on the graphical display. Put all that code somewhere else so you don't have to look at it, and then this algorithm can be very easy to read. It's like for all of the row. So given the column we're trying to place a queen in, we've got this grid of boolean that shows where the queens are so far, that for all of the rows across the board, if, right, it's safe to place a queen in that row and this column, then place the queen and see if you can solve starting from the column to the right, given this new update to the board.

If it worked out, great, nothing more we need to do. Otherwise we need to take back that queen, unmake that decision, and try again. Try a higher row. Try a higher row, right. Again, assume it's gonna work out. If it does, great. If it doesn't, unmake it, try it again. If we tried all the rows that were open to us, and we never got to this case where this returned true, then we return false, which causes some previous one – we're backing up to a column behind it. So if we were currently trying to put a queen in column two, and we end up returning false, it's gonna cause column one to unmake a decision and move the queen up a little bit higher.

If all of the options for column one fail, it'll back up to column zero. The base case here at the end, is if we ever get to where the column is past the number of columns on the board, then that means we placed a queen all the way across the board and we're in success land. So all this code kind of looks the same kind of standing back from it, right, it's like, for each choice, if you can make that choice, make it. If you solved it from here, great, otherwise, unmake that choice.

Here's my return false when I ran out of options. There's my base case – it says if I have gotten to where there's no more decisions to make, I've placed all the queens, I've chosen all the letters, whatever, did I – am I where I wanted to be? There's no some sort of true or false analysis that comes out there about being in the right state. How do you feel about that? You guys look tired today, and I didn't even give you an assignment due today, so this can't be my fault, right?

I got a couple more examples, and I'm probably actually just gonna go ahead and try to spend some time on them on Monday because I really don't want to – I want to give you a little bit more practice though. So we'll see. We'll see. I'll do at least one or two more of them on Monday before we start talking about pointers and linked lists, and so I will see you then. But having a good weekend. Come and hang out in Turbine with me.