Latest / Talk Python To Me / #211: Classic CS problems in Python
Transcript
- 0:00Many of you studied computer science at a university to get into programming and your careers.
- 0:04I bet most of you came through some self-study or some sort of backdoor into the industry.
- 0:09I count myself among that crowd.
- 0:11This is one of the true bright spots of our industry that we can earn our way in
- 0:16without necessarily going and getting formal college degrees.
- 0:19But sometimes that academic formalism would come in handy.
- 0:23That's where David Kopec's book is a great resource.
- 0:25It's an approachable and quick introduction to computer science,
- 0:29and that's our topic on this episode.
- 0:30This is Talk Python To Me, episode 211, recorded March 3rd, 2019.
- 0:36Welcome to Talk Python To Me, a weekly podcast on Python,
- 0:52the language, the libraries, the ecosystem, and the personalities.
- 0:55This is your host, Michael Kennedy.
- 0:58Follow me on Twitter where I'm @mkennedy.
- 1:00Keep up with the show and listen to past episodes at talkpython.fm.
- 1:03And follow the show on Twitter via at Talk Python.
- 1:06This episode is brought to you by Microsoft.
- 1:08Be sure to check out what they're offering during their segments.
- 1:11It really helps support the show.
- 1:14Hey, everyone.
- 1:15Before we get to our interview with David, I want to share some super exciting news.
- 1:18You've probably heard about our 100 Days of Code with Python course.
- 1:22Well, Bob, Julian, and I are back with another 100 Days of Code course.
- 1:27This time, it's all about the web.
- 1:29We've created a course called 100 Days of Web in Python.
- 1:32And it's a similar style course, but it covers so many of the web technologies that you might be interested in.
- 1:39Want to learn about async?
- 1:40That's in there.
- 1:41Want to learn about Django?
- 1:43It's in there.
- 1:44How about API Star, Flask, Pyramid, SQLAlchemy, database migrations, on and on and on.
- 1:51Service functions, all that stuff, it's in there.
- 1:53So if you're interested in the web and you want to really get started, you owe it to yourself to check out the 100 Days of Web in Python.
- 1:59Just visit training.talkpython.fm and you'll find it right in the course section.
- 2:04Now, let's talk to David.
- 2:05Dave, welcome to Talk Python.
- 2:07Hi, Michael.
- 2:08It's a pleasure to be here.
- 2:09It's great to have you here.
- 2:10You've written a really cool book and you're talking about some great problems in computer science that I think will be beneficial to almost everyone listening, regardless of their experience level.
- 2:20So I'm super excited to talk to you about that.
- 2:23Of course, before we do, though, let's start with your story.
- 2:25How did you get into programming in Python?
- 2:26Well, my dad was a computer science professor.
- 2:29So I started programming when I was a little kid.
- 2:32He taught me basic.
- 2:33I first got into Python when I was in graduate school.
- 2:36So I was doing my master's degree at Dartmouth and all the classes were in Python.
- 2:41So I thought, wow, I better become an expert in Python.
- 2:43And I quickly got up to speed and really fell in love with the language.
- 2:47I loved it for its succinctness more than anything, how you could write a program in Python and it would really look similar to the pseudocode that you maybe originally saw in an algorithm.
- 2:57Yeah, I do think that's a really great aspect of it.
- 2:59What languages did you learn before?
- 3:01You said basic in the early ages, but you probably learned something in between.
- 3:04Basic in the early ages, then I was really into Java when I was a teenager.
- 3:08And then I got into Objective-C when I got interested in developing for the Mac.
- 3:12I'd been all around the block, if you will, and then in graduate school, got into Python.
- 3:16Yeah, interesting.
- 3:17Objective-C is a different language as well.
- 3:21I'm just thinking, you know, coming from Java to Python, right?
- 3:23Like it's, there's a lot of symbol differences.
- 3:25Did that strike you as strange or did you find it refreshing?
- 3:28I found it refreshing.
- 3:30I found how succinct it is, again, really refreshing.
- 3:32I mean, Java has this notorious reputation for being verbose.
- 3:36So does Objective-C.
- 3:37A lot of people get scared off by Objective-C's very verbose syntax.
- 3:41So Python was a breath of fresh air.
- 3:43I feel the same way.
- 3:44It's pretty awesome.
- 3:45Okay.
- 3:45So what do you do today?
- 3:47You went to grad school and you started computer science.
- 3:49You're passing the baton to the younger generation.
- 3:52Well, yeah, I worked as a software developer for a few years and now, yeah, I'm an assistant
- 3:56professor of computer science.
- 3:57So kind of following in my dad's footsteps a little bit.
- 4:00Yeah, that sounds like a really fun job.
- 4:02You get all these new people who are excited about programming and work with them for a couple
- 4:06of years and bring them along, right?
- 4:07It's really exciting to see people having those aha moments when they first really grasp a
- 4:11concept.
- 4:12And so, yeah, it's a job that's really gratifying and a lot of fun.
- 4:15Yeah, that's cool.
- 4:16What's your favorite course to teach?
- 4:17I like teaching iOS development.
- 4:19Maybe your Python listeners won't like me saying that, but that's one of my favorite
- 4:22classes to teach.
- 4:23Yeah.
- 4:23Well, it's just such an exciting platform, right?
- 4:26There's just so many inputs, right?
- 4:29Like there's GPS and altitude and even with regular programming, a lot of times you don't
- 4:35get that device feel.
- 4:37But with iOS and I guess Android as well, you do, right?
- 4:39Yeah, absolutely.
- 4:40Another fun class is emerging languages.
- 4:42We kind of explore languages that are still on the periphery of industry and just becoming
- 4:46more popular.
- 4:47And that's really exciting because it keeps me fresh.
- 4:49Yeah, absolutely.
- 4:50What are some of the languages that are emerging?
- 4:52So this semester we're doing Go, Swift and Clojure.
- 4:56And so some people might be like, oh, those are those have already been around for a little
- 5:00bit.
- 5:00They're all around 10, five to 10 years old.
- 5:03And, you know, if you think about a computer science curriculum, it moves a lot slower than
- 5:08industry moves.
- 5:09So these are languages that aren't usually taught in college or university level.
- 5:13Yeah.
- 5:13It's pretty cool that you're covering those.
- 5:14All right.
- 5:15So let's talk about the main topic.
- 5:18These classic computer science problems.
- 5:20You wrote a couple of books around classic computer science problems.
- 5:24We'll touch on the books and more on the main ideas from them.
- 5:27But let's just start with, you know, what makes a computer science problem classic?
- 5:33Well, for the purposes of the book, we thought about a classic problem as one that somebody
- 5:39who has a bachelor's degree in computer science would probably be familiar with.
- 5:43So what have been taught in the college classrooms for the past, you know, 30 or 40 years, as long
- 5:49as computer science programs have pretty much been around.
- 5:52So if you go to somebody who has a CS degree, they probably heard about one of these problems.
- 5:58Okay.
- 5:58So that's our basis.
- 5:59But then we had to also expand that into a whole book.
- 6:02So we also just went over problem solving techniques that we think anyone who works in
- 6:08software development, whether they have a CS degree or not, should be familiar with.
- 6:12And then we're using problems to illustrate those classic problem solving techniques.
- 6:16Yeah, I think that's a really great approach.
- 6:18We recently did a beginners and experts episode on the show.
- 6:23Time shifting hasn't released yet.
- 6:25So yeah, there's no way you could have heard it, but it's been recorded and will come out
- 6:28before this one.
- 6:28And we talked about, you know, what is the real, one of the core differences between somebody
- 6:35who's been programming for a long time and somebody who's new, right?
- 6:38Like it takes, you know, a couple of months maybe to jump in and learn a language or learn
- 6:43some important package like Django or SQLAlchemy or something like that.
- 6:47But it seemed like one of the really big challenges a lot of the beginners laid out is you see a
- 6:53problem, you see a whole bunch of APIs and like, how do you even break it down into something
- 6:58you can start to solve, right?
- 7:00These like partitioning problems into something you can think about.
- 7:03Do you think that's a big problem you see with your students?
- 7:06Absolutely.
- 7:06I mean, if you've, you're never even familiar with the problem solving techniques, how are you
- 7:10going to know that you should be applying them?
- 7:12And so that's kind of the purpose of the book.
- 7:13It's very broad in its scope.
- 7:15That's been one of the criticisms of it, frankly, is that it doesn't go deep enough into any of
- 7:19the particular problem solving techniques, but it's not supposed to.
- 7:22It's supposed to be a broad introduction, give you a little bit of a taste of each of them.
- 7:26And then maybe you know enough about them to know when they should be applied, but you're
- 7:30not necessarily an expert in any of them just by reading the book.
- 7:33Yeah, that makes a lot of sense.
- 7:34One thing to think about is it feels to me like these classic problems, regardless whether they're
- 7:40in your book or I think back to when I saw some of these, I don't have a CS degree.
- 7:45I have a math degree, but I have what's like roughly a minor in CS.
- 7:51My university didn't have CS or minors at all, really, but same idea.
- 7:56And so when I saw these, and it feels like the ones you covered as well a lot here, I think
- 8:02it's pretty typical, is it's very much focused on algorithms, data structures, and so on.
- 8:07It's not like, here's how we're going to render a web page or generate a data-backed rest and
- 8:14point or things like that, right?
- 8:16It's not about GUIs, and it's more focused on what is the core problem, what are the right
- 8:22algorithms and data structures and ways of thinking about it to solve it, right?
- 8:26That's absolutely true.
- 8:27On the other hand, at the end of every chapter, we include a small section called real-world
- 8:32applications.
- 8:33And it tries to bring them back into the day-to-day software development world.
- 8:37So how are people in apps that you're probably familiar with actually using these techniques
- 8:41to solve problems?
- 8:42I think a lot of us as software developers, we get into a mode of kind of API plumbing, where
- 8:48we end up kind of just hooking up other people's libraries, hooking up APIs together, and we get
- 8:54a little bit away from the problem-solving parts of software development.
- 8:57And for people who felt like they've been in kind of that API plumbing mode for too long,
- 9:02maybe they'll find this book a little refreshing.
- 9:04Yeah, I think they will as well.
- 9:06So who do you think should study this kind of stuff, right?
- 9:09I mean, you talked about the API plumbing, and sometimes people will make the distinction
- 9:14between coders and software developers.
- 9:16I'm not really sure I like that.
- 9:18But should everybody really understand these algorithms deeply?
- 9:22Who should really pay attention to this, do you think?
- 9:24I think anyone who's a software developer should be familiar with these problem-solving techniques.
- 9:28This book is actually geared for people who don't have a CS degree.
- 9:32It's to introduce those concepts that you missed out on.
- 9:35By being a programmer and not having that CS education, giving you a basis to understand
- 9:40what everyone else is talking about when they talk about something like a neural network or
- 9:43genetic algorithm.
- 9:44What is that stuff?
- 9:46And when should you actually be using a technique like that?
- 9:48So I really think it's a broadly applicable set of topics that everyone should at least be
- 9:53familiar with.
- 9:54Again, it doesn't mean you need to be an expert.
- 9:56It doesn't mean you need to go do four years of study.
- 9:58But when you run into a problem in your software development day job, or even if you're just
- 10:03doing software development as a hobby, you should know what tools are available to you to solve
- 10:07it.
- 10:07Right.
- 10:07Even simple stuff like, oh, that should be a dictionary or that should be a set versus a
- 10:11list.
- 10:11Yeah, absolutely.
- 10:12Yeah, for sure.
- 10:14Okay.
- 10:15Well, one of the things I really liked about your presentation of all these classic computer
- 10:20science problems was one, it was in Python, but it was in modern Python.
- 10:25And I mean, really modern Python, not like, oh, it was three, five or something, right?
- 10:29You, you really made proper use of a lot of the cool new features.
- 10:33Yeah, that was a goal.
- 10:35You know, we put together a team when we started the Python version of the book that and we said,
- 10:39we need to have a team that's really familiar with the latest techniques, because we want
- 10:43this book to hopefully be evergreen for a few years.
- 10:46We want people to feel like if they buy it two years from now, it's using fairly modern
- 10:50Python.
- 10:50So we decided from the beginning, we're going to do Python 3.7.
- 10:54And, you know, really cutting edge stuff.
- 10:55And we're actually going to use features from Python 3.7.
- 10:58Things like data classes, things like recent additions to type hints.
- 11:04And I will say that especially the decision to use type hints was a very controversial one
- 11:10amongst the reviewers of the book.
- 11:13So Manning has a pretty extensive review process.
- 11:15Every one of their books goes through three sessions of external expert reviewers looking
- 11:21at the material.
- 11:22And there were a couple of reviewers every time who said, you know what, I feel like the type
- 11:26hints are not standard Python.
- 11:28They're really a fad or they're really just something that takes away from the succinctness
- 11:33of the language, which, like I mentioned before, is something I love about the language, how
- 11:36succinct it is.
- 11:37And I kind of agree.
- 11:38You know, obviously your code does look a little more bulky with all the type hints inside of
- 11:42it.
- 11:42On the other hand, we wanted to do where we thought the puck might be going.
- 11:47And type hints are becoming more popular.
- 11:50And there definitely is some value that they add, and arguably in terms of readability, knowing
- 11:55right away what a function is going to return is a nice thing.
- 11:58without having to read through it.
- 11:59And we took a bit of a gamble on it.
- 12:03And I hope that for people who are interested in type hints, this book might be a gateway into
- 12:07getting even more interested in them.
- 12:09I think so.
- 12:09You know, I'm personally a big fan of type hints in Python.
- 12:14I think they can go overboard.
- 12:16I think they can make the code look too bulky.
- 12:18But there's something really powerful about just sprinkling a few of them here and there
- 12:25and then having your editor, your IDE, whatever, just come to life knowing exactly what you're
- 12:30working with.
- 12:31And even catching errors and mistakes.
- 12:33That's pretty powerful.
- 12:34Yeah, absolutely.
- 12:35I mean, the ability to use something like mypy and know ahead of time where some of your
- 12:39errors lie before you get to runtime is really great.
- 12:43When it comes to self-documenting your code, there's also a big advantage with type hints,
- 12:47which is you right away know what these parameters are supposed to be.
- 12:52You right away know what this function is supposed to return.
- 12:55It can make your comments a little less bulky.
- 12:57So you're kind of trading off a little bit of bulkiness in the code for maybe a little
- 13:01bit of less need to be so explicit in your comments.
- 13:05Right.
- 13:05Yeah.
- 13:05If you say something's a Boolean, you don't need to describe in the comments, hey, this
- 13:09is a Boolean.
- 13:09It's like, well, colon Boole, we're good.
- 13:11Exactly.
- 13:12Yeah.
- 13:12Yeah.
- 13:12It's pretty interesting.
- 13:13So reading through your examples, though, you know, when I think of like, why do I care
- 13:19about type hints?
- 13:19I care about them mostly for the reason, like personally, I care about them for the reason
- 13:24that I laid out, which is I love how it makes the editors like PyCharm and VS Code really
- 13:30help you a lot.
- 13:32Right.
- 13:33It helps you deeply understand the types you've been passed around and give you autocomplete
- 13:37and stuff like that.
- 13:38Or error, you know, sort of PEP 8 type error checking.
- 13:40It's like 8 type error checking.
- 13:42There's mypy, which you mentioned, which was really instrumental in helping Dropbox convert
- 13:47like a million lines of Python 2 to Python 3, which I thought is an interesting use.
- 13:51But the third one that I realized looking through your stuff is,
- 13:54it's really nice when you have just static text, not in an editor, right?
- 14:00It's just sitting there on the page.
- 14:01I don't have a command click go to definition to see what's happening on this function.
- 14:06But it, you know, if you put the type hints right there, you're like, oh, well, this is
- 14:10returning a list of ints.
- 14:11So I don't need to go and like try to find out where that was in the writing.
- 14:16I can just see that's a list of ints and go with that.
- 14:18That's pretty cool.
- 14:19Yeah, absolutely.
- 14:20I mean, that's supposed to be the goal is that it's more readable.
- 14:22Now, when you first see them, and if you're not used to them, I think it is actually less
- 14:27readable.
- 14:27And it takes some time to get used to.
- 14:29So I think it's a fair criticism of those reviewers that for some people, the type hints
- 14:35do actually make the code at first glance less readable, especially if you're not familiar
- 14:39with them.
- 14:39We did include a short appendix, appendix C to the book that kind of gives you a crash
- 14:43course in type hints.
- 14:44But it's really just a matter of spending time with them to really start to gain the benefits
- 14:51of the readability, I think.
- 14:52Yeah, it does take a little bit of getting used to.
- 14:55You know, two things I actually learned, even though I'm a big advocate and fan, I use the
- 14:59type annotations a lot.
- 15:00One of the things that I saw that you were using, a couple of things that were pretty cool.
- 15:06One, you were using from future import annotations, Dunder future annotation.
- 15:11That's kind of a new feature coming for type hints, right?
- 15:14Want to tell people about that?
- 15:15Yeah, absolutely.
- 15:16So if you have, for lack of a better word, recursive type hints, so a type hint that refers to the
- 15:21type inside of it, up to version 3.7 and this new annotations feature added to under Dunder
- 15:28future, you would have to actually put it in as a string in quotes.
- 15:34And if you now import annotations, you can actually just put the type as its actual type
- 15:40name without putting it in quotes, which is how the language will work in the future.
- 15:43But for now, we have to have that in future.
- 15:46Yeah, there's always this limitation where like, it's super common to have a class that interacts
- 15:51with itself, right?
- 15:53Exactly.
- 15:54You know, like I've got a class, maybe it has a static method, and it's going to take another
- 15:58one.
- 15:58Like just for comparison, like, is this instance of me less than another instance of me?
- 16:03If you want to put that in type annotations, that was really tricky to understand what to
- 16:06do without this new future version of stuff.
- 16:10Because the class technically wasn't finished being defined yet.
- 16:12So you couldn't say the name of it within like the functions or the properties or whatever.
- 16:16Yeah, absolutely.
- 16:17Yeah, interesting.
- 16:18Another one that I thought was interesting is the ability to define a generic type.
- 16:23I literally had never seen that or tried that.
- 16:26But you have a lot of data structures that you're defining to be generic, like a generic
- 16:30of T, like bracket, bracket.
- 16:32Yeah, absolutely.
- 16:32That's interesting.
- 16:33Yeah, we're trying to make all the code in the book as generic as possible.
- 16:36And let me use that term more broadly than just the type in specific version of it.
- 16:40We want to write algorithms that can work for many different problems.
- 16:44We don't want to code them so specifically that they're only solutions to the one problem at
- 16:49hand.
- 16:49We want them to be techniques that you could then just drop in the same method, the same
- 16:53class, and use it in a totally different program.
- 16:55So in most languages, we have something called generic programming.
- 17:00So in Java, you have generics.
- 17:02In C++, you have templates.
- 17:04In type hints in Python, you have the generic type, which is similar to those other two methods
- 17:09in those other languages.
- 17:10It's a way of saying, you know, I don't know exactly what type I'm going to be using in this
- 17:15problem.
- 17:16So here's a type that can fit in for any type.
- 17:20And that is what a generic type is.
- 17:23It's a, I don't know yet what the type is, but at runtime, we're going to figure out what
- 17:27the type is.
- 17:28Yeah, it's interesting.
- 17:29It's like the list of int or list of string type of feature that you can get from if you
- 17:36import it from typing.
- 17:37But you can more broadly, you can make it for your own types.
- 17:39That's cool.
- 17:39Yes, you said data classes, f strings, all the good stuff, right?
- 17:43I just want to give a shout out to the cool sticker I saw at PyCascades recently.
- 17:47They had a sticker for new versions of Python and said, F quote, yes, exclamation mark quote.
- 17:54So F yes.
- 17:55It was beautiful.
- 17:56Yeah.
- 17:56I mean, there's so many different ways to do string interpolation in Python and f-strings
- 18:01are just so beautiful compared to the older ways.
- 18:03They are for sure.
- 18:05This portion of Talk Python is sponsored by Microsoft and Visual Studio Code.
- 18:10Visual Studio Code is a free, open source, and lightweight code editor that runs on Mac,
- 18:15Linux, and Windows with rich Python support.
- 18:17Download Visual Studio Code and install the Python extension to get coding with support for
- 18:22tools you love like Jupyter, Black Formatting, Pilot, pytest, and more.
- 18:25And just announced this month, you can now work with remote Python code bases using the new Visual
- 18:31Studio Code remote extensions.
- 18:33Use the full power of Visual Studio Code when coding in containers, in Windows subsystem for
- 18:38Linux, and over SSH connections.
- 18:40Yep, that's right.
- 18:41Auto completions, debugging, the terminal, source control, your favorite extensions.
- 18:45Everything works just right in the remote environment.
- 18:48Get started with Visual Studio Code now at talkpython.fm/Microsoft.
- 18:54One thing I wanted to ask you about is you've done this book in Python,
- 18:58understanding these classic computer science programs, and you've done the same problems,
- 19:03not the exact same book, but basically the same problems, right?
- 19:06In Swift, because you had a classic science problems in Swift as well.
- 19:10I'd love to get your thought on comparing those two experiences.
- 19:13Absolutely.
- 19:13So most people would not be surprised that the Python version was more succinct,
- 19:19and a lot of people would not be surprised that the Python standard library
- 19:23is a lot richer than the Swift standard library.
- 19:26And so there were actually parts of the code.
- 19:29First of all, when we were doing the Python book, we wanted the book to be, of course,
- 19:33totally Pythonic.
- 19:34So we put together a team of reviewers and also the technical editor that were really
- 19:39experienced Python programmers who were making sure that we were not just porting over the
- 19:44Swift book and it was still looking like Swift in Python.
- 19:46We wrote most of the problems again from scratch.
- 19:49But there were situations where there was whole methods from the Swift book that we could totally
- 19:56eliminate in the Python book because those techniques already exist in the standard library.
- 20:01And so while in the book, we only basically use the Python standard library, we don't use any
- 20:06external libraries.
- 20:07That still meant that we were able to eliminate whole sections of code that just don't exist in
- 20:14the Swift standard library.
- 20:15As far as the languages go, I mean, Swift has been inspired by Python in some of its syntax.
- 20:20So there are actually parts of it that look surprisingly similar.
- 20:24But as a whole, like I mentioned, the Python code is certainly more succinct.
- 20:28I'd say the Python code is probably more readable as a whole.
- 20:32And working with the two languages, Swift is a moving target, right?
- 20:35Swift, every version of Swift, there's sometimes some breaking syntax changes and it can be kind
- 20:41of annoying.
- 20:41It's starting to stabilize the last couple of years.
- 20:43Python, of course, is an extremely mature language with extremely mature tooling.
- 20:48And so that was, of course, a pleasure as a book writer.
- 20:51You don't want to be writing code that is going to be obsolete a year from now.
- 20:55So that was, you know, much more fun on working, not having to think about that when writing
- 21:01the Python book.
- 21:02Yeah.
- 21:02You know, I don't think it would be a major difference just remembering, reading through
- 21:06all the solutions you have.
- 21:08But one of the big differences with Swift is it's one of the most statically typed, safest
- 21:14of all the languages that I've worked with, at least.
- 21:17Because, you know, not only does it have a type system, it has things like these are read-only
- 21:23reference variables and all sorts of stuff like that, right?
- 21:26Like the constant or like nullable.
- 21:29You have to explicitly say a type is nullable or it can never be the equivalent of none and
- 21:34things like that.
- 21:34Did that make a big difference or not so much?
- 21:37I think it does for the reader.
- 21:39I think because there's a lot of cognitive overhead that goes with all of those safety
- 21:43features.
- 21:44So having to always think about, should this be an optional?
- 21:46Oh, if this isn't optional, do I have to unwrap it here?
- 21:50That's the type of stuff you have to constantly think about in Swift.
- 21:52And in Python, your mind is a little more free.
- 21:55So it actually makes the code more readable and easier to think about when you don't have
- 22:00to think about all those safety features.
- 22:02I think Swift code takes longer to write than Python code.
- 22:05It might be safer at runtime, but it also takes, I think, less time to read Python code than Swift
- 22:11code as well, because you're not reading through all of those hoops you have to jump through
- 22:15for safety.
- 22:15Yeah, that's my sense from my limited experience as well.
- 22:18All right.
- 22:18Let's dig into some of these classic problems.
- 22:21And I would say you start off all of your problems with this one as well.
- 22:25But I would say one of the most mind-bending ideas of problem solving when you first come
- 22:32into properly study programming rather than just like, oh, here's a loop and here's a variable.
- 22:38I'll make it work is recursion.
- 22:40Absolutely.
- 22:41It's just like, wait, how does this work?
- 22:44There's no loops, but we're going across a set or something crazy like that, right?
- 22:48Yeah.
- 22:48Recursion is something that does bend your mind the first time you see it.
- 22:52And it requires a new way of thinking.
- 22:55The crazy thing is there's whole programming languages that are based around recursion.
- 22:58I mean, if you look at some of the functional programming languages, they don't even have
- 23:01loops.
- 23:01Anytime you want to repeat yourself, you have to do recursion.
- 23:05Recursion is not a technique you want to apply every time you program.
- 23:08Recursion is a technique you want to apply when it makes more sense to you.
- 23:12Because any problem that you can solve recursively, you can also solve iteratively.
- 23:17So you can also solve using loops.
- 23:19So they really are two different ways of just repeating yourself.
- 23:23But it's a question of which one makes more sense to you in your mind when you're abstracting away
- 23:28the problem and thinking about how you want to solve it.
- 23:30So there are situations where even though a loop might actually be more performant, which it often
- 23:36is in a language like Python, the recursive way of approaching the problem is more similar to how you
- 23:44might have written it down on paper, let's say.
- 23:45Right.
- 23:46Or maybe it perfectly matches the data structure you're trying to interact with, right?
- 23:50If I have like a tree data structure or something hierarchical, that's often really easy to work
- 23:55with in a recursion way.
- 23:56Because, you know, the recursion step is take one of the sub elements and work on it as if it
- 24:01was the whole thing until you're out of sub elements, right?
- 24:03Absolutely.
- 24:04And we sometimes call structures like that even recursive data structures.
- 24:07Absolutely.
- 24:08Yeah, for sure.
- 24:09And this one, the example was a Fibonacci sequence, of which I'm also a fan for these little demos
- 24:15that's complicated enough, but not super complicated.
- 24:17It's nice to work with.
- 24:18So you said, all right, well, let's try to solve the Fibonacci sequence problem with recursion
- 24:22because, well, the first two numbers are either 0 and 1 or 1 and 1, depending on who you ask.
- 24:28And then it's you add those two together.
- 24:30So you have, you know, F of N is just F of N minus 1 plus F of N minus 2.
- 24:36And it's super easy to do recursion.
- 24:38But it turns out that recursion kind of goes a little bit crazy in its naive way.
- 24:43For example, Fibonacci at 20 using recursion does 21,891 calls.
- 24:49That's a lot.
- 24:50So you said, well, the reason is we keep asking the same question again and again.
- 24:54What is a Fibonacci at 10?
- 24:55And if you want 11, you ask, you know, that the same subsequence a whole bunch of times, right?
- 25:00Right.
- 25:00So then you get into memoization, which is a funky word, but a very cool technique.
- 25:05Yeah.
- 25:05Very good for performance.
- 25:06Absolutely.
- 25:07I mean, yeah, the Fibonacci sequence is for listeners who aren't familiar with it is each of the numbers is the sum of the previous two numbers.
- 25:14So it goes 0, 1, 1, then 1 plus 1 is 2, then 2 plus 1 is 3, then 3 plus 2 is 5, etc.
- 25:21Right.
- 25:21And so how can if you actually write that recursively, it looks incredibly similar to how we just defined it.
- 25:28We just said it's the sum of the previous two numbers.
- 25:30So recursively, you can actually write, take the Fibonacci number of the previous one, n minus 1, and add it to the Fibonacci number of two ago.
- 25:39So Fibonacci of n minus 2.
- 25:41It's actually like two lines of code, maybe three lines of code in Python.
- 25:45That's, like you mentioned, not very performant because you do all of those recursive calls many, many, many times when you do a large number.
- 25:53And we show in the book how you kind of go through a tree of them.
- 25:57So we go through six different ways of solving the problem, each of them getting a little bit more performance or just doing it in a slightly different way.
- 26:05One way to solve the problem is with memoization.
- 26:08In memoization, you actually store results that you've already computed so that if you need to compute them again, you can just look them up.
- 26:16That's basically the idea.
- 26:18It's a fancy word for a really simple idea, which is basically just let's store results that we've already come up with.
- 26:24And then we can just look them up instead of having to calculate them again.
- 26:27So in Python, it's super easy to do that.
- 26:29You can do that using a dictionary.
- 26:31You can just store in a dictionary.
- 26:32Here's a previous result for a certain set of parameters.
- 26:35In the case of Fibonacci sequence, it's just a single parameter.
- 26:38Which Fibonacci number are we trying to look up?
- 26:40We can just store that in a dictionary.
- 26:42There's also a built-in facility in Python called LRU cache.
- 26:47And this is from the functools package.
- 26:49And you can use that to automatically store the result of a function so that the next time the function is called, we just auto look in that cache for what the last result is.
- 27:00So that's a little tip from the Python standard library that can just make a huge performance difference for all kinds of different mathematical calculations because you're not going to have to do them again.
- 27:11They're just already going to be stored for you.
- 27:13Or anything that can be cached, basically.
- 27:15Right.
- 27:16So you put the LRU cache decorator on your function.
- 27:19And that function could be computing Fibonacci numbers.
- 27:22Or it could be going to a database and making complicated queries.
- 27:26But you're like, well, if this is however old or maybe this rarely, rarely changes between runs of the app, you only need to ask the database once.
- 27:34And then you hold on to the answer, right?
- 27:36Yeah, absolutely.
- 27:37And that's one of the things I love is when we're able to teach something that's actually an important computer science topic, memoization.
- 27:43But we're also teaching you something about the Python standard library that easily in your day-to-day software development can really save you a ton of performance cost.
- 27:51Yeah.
- 27:51I agree.
- 27:53Super, super nice.
- 27:54Final takeaway.
- 27:55Well, I guess I talked about there being 21,000 function calls for Fibonacci at 20.
- 27:59If you use memoization, it's 39.
- 28:01Right.
- 28:01Even so, directly implementing it with generators and just a straight loop is still much faster.
- 28:07Right.
- 28:08Then it's just 20.
- 28:08So it's literally just every single one.
- 28:11Let's say we're doing Fibonacci number of 20.
- 28:13We just have to do basically going around the loop 20 times, one for each number in the sequence.
- 28:18So that's a situation where, yeah, iterative, which is loops, is actually more performant than recursive.
- 28:24And that you'll often find is the case.
- 28:27Even though recursion is a really cool technique, usually it's actually faster to do things with loops in Python.
- 28:32It's more about optimizing for understanding versus performance, which maybe understanding is better at first, unless it really matters.
- 28:40Exactly.
- 28:40Yeah.
- 28:41So, you know, one thing I wanted to ask you about, like, when I learned about the yield concepts and these generator ideas and whatnot, like, that's pretty mind-blowing.
- 28:51And would that almost be its own sort of classic CS problem is these lazy deferred execution types of things?
- 28:58You know, maybe it should be.
- 29:00I mean, we should have covered it as such in the book.
- 29:02We don't go into it in a huge amount of detail.
- 29:04We kind of assume the reader is familiar with generators and maybe we shouldn't have.
- 29:08And, you know, that's something I should have prefaced our whole conversation with is we wrote the book for intermediate to advanced Python programmers.
- 29:15So it's really not appropriate for people who are just learning Python for the first time.
- 29:20We already assume that you've been doing Python development for probably a couple of years before you pick up this book.
- 29:26So we don't go into explaining every detail of generators.
- 29:31And, you know, now that I think about it, maybe we should have because even some intermediate and advanced programmers are not always familiar with them.
- 29:37I think it's okay.
- 29:37But I do think this idea of solving problems with generators, it's just so powerful and just unlocks a lot of potential for interesting pipelines and other types of execution with, you know, like, usually simpler code.
- 29:51Yeah, absolutely.
- 29:52It's a non-generated version.
- 29:53So, yeah, pretty interesting.
- 29:54So another area that you focused on was data representation.
- 29:58And in a pretty simple form, not like, is this a pointer rich data structure or is sparse or things like that.
- 30:05But, you know, you focused on trying to represent DNA, right?
- 30:09I think is what it is.
- 30:11You had codons and stuff like that.
- 30:12Actually, it was just the amino acids at first.
- 30:15So you're just like, well, how do we store this?
- 30:18We could store it as a string.
- 30:20And, you know, the AC, T, G, each one could be a string.
- 30:24And that would be pretty large in terms of representing data.
- 30:27You could store it as integers, but even integers are not very efficient in Python.
- 30:31So then you started working with bits and bytes, right?
- 30:34Yeah.
- 30:34So, you know, oftentimes we don't even think about how some, what we think are really simple bits of data are going to be stored.
- 30:41So your first inkling when you're thinking, how should I store the letters A, C, T, and G to represent DNA might be, why don't I just store them as strings, right?
- 30:51Because those are letters.
- 30:52So that makes sense.
- 30:53Letters can be parts of strings.
- 30:56But actually, you know, if you only have four different things that you want to store, you can do that with just two bits of information per thing.
- 31:04Because two bits can represent up to four different numbers, right?
- 31:08And so each of those four different numbers could represent one of those four letters.
- 31:13And so if for a string, we're going to end up storing approximately eight bits for every character.
- 31:19So eight bits for A, eight bits for T, et cetera.
- 31:23And if we do it as a number and we can actually just store two bits for A, two bits for T, that's actually a 75% space savings.
- 31:31Just from thinking about the fact that, oh, I actually don't need that many different possibilities that a string provides for this type of data.
- 31:40So it sounds like common sense.
- 31:42It is common sense.
- 31:43But we don't even think about that sort of thing a lot of the time.
- 31:46And so we're wasting a lot of data.
- 31:47It's not obvious at all.
- 31:48Yeah.
- 31:48In something low level like C, you talk explicitly about the data types very, very carefully.
- 31:55This is a four byte integer.
- 31:56That's a two byte integer.
- 31:57But even integers in Python are like 28 bytes each for like the number zero.
- 32:03Well, yeah.
- 32:04But at least the number zero to 256 are, you know, flywheel pre-allocated.
- 32:09So they're shared.
- 32:10But, you know, normal numbers take up a lot of space because they're really embedded within these PyObjects.
- 32:15Right.
- 32:15Things that are tracked by Python with reference counting and all that.
- 32:18And we're not saying that you should always be doing this, right?
- 32:21Maybe it actually is a lot more convenient a lot of the time to just use strings.
- 32:24And you absolutely should do that.
- 32:26But if you're not even aware that there was a better way or there was a more at least space efficient way,
- 32:32maybe there's a situation where you're not storing kilobytes of data, but you're storing gigabytes or terabytes of data.
- 32:39And you could have actually been saving 75% of the space.
- 32:41Well, wow.
- 32:42Maybe it's relevant then.
- 32:43So, again, it's just something we want to make people aware of.
- 32:46We're not saying you should always be finding the absolute most efficient way to store everything.
- 32:50Right.
- 32:50Or you have a RESTful API that's exchanging JSON.
- 32:54And you're like, you know, if we wrote this in straight TCP packets and we just did this bitwise storage, we could drop, you know, the traffic by 95% or something.
- 33:06Sure. I mean, but that sounds really painful.
- 33:08And that doesn't sound like something I'd rather just exchange the JSON, I think, most of the time.
- 33:13Yeah. I'm thinking of like places where, you know, PayPal has an API that's called like several billion times a day.
- 33:21And it needs really, really low.
- 33:22Like, it's got to be pretty far out there.
- 33:25Yeah, absolutely.
- 33:26It's got to be an extreme case before you want to start.
- 33:28Yeah. Going down that road.
- 33:30Yeah, absolutely.
- 33:30All right.
- 33:31So another one that I thought was an interesting one was the Towers of Hanoi, because it's super painful to solve by hand.
- 33:39You know, you sit down and it looks real simple.
- 33:41You've got these three towers that each have these little disks.
- 33:43Disks are bigger as you go down.
- 33:46And the job is to move them from one end to the other end.
- 33:50But the rule is the big ones can't go on top of the little ones.
- 33:52So how do you, you know, what series of operations?
- 33:55It's kind of like the Rubik's Cube type of thing, right?
- 33:58But the solution turns out to be beautifully solved with recursion, right?
- 34:03Right. Yeah.
- 34:03I mean, so it sounds like a really simple problem.
- 34:06So we have three different, let's call them towers.
- 34:09And we have three disks.
- 34:11And we want to move all the disks from one tower to another tower.
- 34:14How can we do that?
- 34:15Well, if you actually try to work it out, it's several steps.
- 34:19And they're not completely obvious when you just look at it.
- 34:22Although it does help to be able to see a model of it.
- 34:24So it's a little hard to describe on a podcast.
- 34:27But what's interesting is that the solution actually just comes down to figuring out two things.
- 34:32One is how do I move a single disk?
- 34:34And the second one is how do I move all the rest of the disks?
- 34:38And that actually lends itself to a really succinct recursive solution.
- 34:44Just a few lines of code.
- 34:45And then it can solve it actually for any number of disks.
- 34:48Not just three, but let's say we had 10 disks.
- 34:50Well, we can actually solve that by just knowing how to solve the first disk.
- 34:54And then having some step that we do for moving all the rest of the disks.
- 34:59So it's kind of mind-blowing when you actually see how succinct it is to solve it for any number of disks recursively.
- 35:07And I don't think we can explain it wonderfully on the podcast.
- 35:12But I guess people will just have to take our word for it.
- 35:15It is really, really interesting.
- 35:17Like the last move is obvious.
- 35:19You just move the disk over.
- 35:21It's kind of mind-blowing.
- 35:22And I do think it's a perfect application of this idea of how recursion really nicely fits these things.
- 35:29Because I think it would be really tough to implement that with loops and just, you know, mutable data structures and whatnot.
- 35:35Yeah, absolutely.
- 35:36So one that I thought was really nice tying together algorithms and data structures in a way that's kind of mind-blowing, to be honest, was maze traversal.
- 35:46Yeah, you know, there's so many different ways to traverse a maze.
- 35:48And this is actually a really good practice for people who are going into coding interviews.
- 35:54Because there's a lot of these techniques for solving a maze that often come up in coding interviews.
- 35:59Things like depth-first search, breadth-first search.
- 36:03And then at the end of the chapter, we go into A star, which is actually the most efficient algorithm for finding a path through a maze.
- 36:09But it's remarkable how all of these techniques, when you write them out in code, they're very, very similar.
- 36:16And all you have to actually change between depth-first search and breadth-first search, for example, is the data structure.
- 36:21So in both of those, you're keeping track of where am I going to look next?
- 36:26We call that the frontier.
- 36:27So where are the next places on the grid?
- 36:31Let's say the maze is a grid.
- 36:33Where are the next slots on the grid that I'm going to look at next?
- 36:37In depth-first search, you use a stack.
- 36:41So you just keep going through and you keep adding the next places you're going to look onto the stack.
- 36:46In breadth-first search, you use a queue.
- 36:49And so all the rest of the code stays exactly the same.
- 36:54You don't change a single other thing in your code.
- 36:55You just change, okay, for the frontier, the next places I'm going to look at, I'm going to use a queue instead of a stack.
- 37:01And then the way that we traverse the maze totally changes.
- 37:04In depth-first search, we kind of take a stab at it.
- 37:07We go as far as we can through.
- 37:09And if we hit a wall, we backtrack to the last location.
- 37:12That's probably the way real people would, right?
- 37:14Like if you were put in, as a human, put into a maze, you would just go until you hit a wall.
- 37:18You would probably not apply some breadth-first algorithm, little notebook or whatever, right?
- 37:23Right.
- 37:23Yeah.
- 37:24As human beings, that's how we usually think.
- 37:25I think we kind of think in a depth-first way.
- 37:27But a breadth-first search is super systematic.
- 37:30It says, you know what?
- 37:31Let's first look at the nodes that are one away from where we started.
- 37:34Then let's look at the nodes that are two away from where we started.
- 37:37Then let's look at the nodes that are three away from where we started.
- 37:39And just by changing from a stack to a queue, and for those that don't know, a stack is a data structure where the last item we put in is the first item we take out.
- 37:48And a queue is a data structure where the first item we put in is the first item we take out.
- 37:53Just making that change of data structure, so literally changing one line of code, totally changes how we traverse the maze.
- 37:59And so maze traversal is an awesome way of kind of illustrating the difference between depth-first search and breadth-first search.
- 38:05Yeah, and then so you have the queue, the depth-first one?
- 38:09No, in the breadth-first one.
- 38:10And then you come to A-star, which uses a new data structure, but is also pretty similar in the implementation called a priority queue.
- 38:19Right.
- 38:19I don't believe I've seen a priority queue.
- 38:21Yeah, so this is a place where the Python standard library is pretty cool because the Python standard library has built-in facilities for handling heaps.
- 38:29And a heap is a data structure that's at the basis of a priority queue.
- 38:33What a priority queue does is instead of a stack where we say last thing in, take that thing out first, and a queue where we say first thing in, take that thing out first, with a priority queue we say, let's assign every item we put into the data structure a quote-unquote priority.
- 38:48And when we take things out of the data structure, let's take them out by their priority.
- 38:54So the first thing we take out might be the thing with the highest priority.
- 38:58So we have a way of kind of tagging each element and saying, here's your priority.
- 39:02And then when we pull them out, we're going to efficiently pull them out by their priority.
- 39:06So in A-star search, what we want to have is some kind of heuristic for traversing the maze.
- 39:11Instead of just dumbly saying, oh, what are the next things next to where I am right now?
- 39:16Let's instead say, looking at my next possibilities, which one do I think will get me closest to the goal?
- 39:23And the way we usually do that on a maze is actually just using a straight line.
- 39:29So sometimes called Euclidean distance.
- 39:31Just draw a line from the next places I'm looking at to the goal.
- 39:34And the shortest line, that's probably the one that's getting me closest to where I want to go.
- 39:39And so we can then put all of those next nodes into the priority queue ordered by how long is that line?
- 39:47And how long that line is, is what the priority is.
- 39:50And we just take the ones out that have the shortest lines next.
- 39:52And that gets us to an algorithm that will actually get us very efficiently from the start to the goal.
- 39:59This portion of Talk Python To Me is brought to you by Microsoft.
- 40:02For ultimate developer productivity in the cloud, use Azure extensions for Visual Studio Code.
- 40:07You can deploy and debug your serverless Python apps directly from your editor.
- 40:11On Azure, you can run your Python apps as serverless code on Linux web apps and functions,
- 40:16or on top of managed Kubernetes, and easily connect data from database services, including Postgres and MySQL.
- 40:23You can also use Azure DevOps to create cross-platform builds of your Python packages with hosted macOS, Linux, and Windows build machines.
- 40:31And publish them to Azure Artifacts for your own hosted PyPI feed.
- 40:35Azure DevOps is free for open source projects, and many are using it already.
- 40:39Get started for free at talkpython.fm/Microsoft.
- 40:44You also mentioned this idea of the Manhattan distant metric, where you can't actually walk diagonal on a maze, where it's a grid, or something like that.
- 40:54Right?
- 40:54And you also can't do that in cities where they're laid out on grids.
- 40:57Right?
- 40:57There is no diagonal travel.
- 40:58It's over one, back one.
- 41:00So, like, the diagonal is effectively as long as going, you know, around the border on these things.
- 41:05So, you can also even get a little more accurate with that.
- 41:07Right?
- 41:07Right.
- 41:07So, yeah, the straight line is always the shortest way to get from point A to point B, but straight lines don't always work.
- 41:14Right?
- 41:14So, if we're on a grid where we can only go horizontally and vertically from one spot to another, we actually can use a different heuristic known as the Manhattan distance, which is named after the borough of Manhattan of New York City, where all the streets are on a grid pattern.
- 41:28Right?
- 41:28And so, when you want to walk, you have to walk a certain number of blocks to the right or left, and a certain number of blocks up or down.
- 41:35And if you actually do that calculation on a maze that can only go horizontally and vertically, it's going to give you a better estimation of how long it'll take to get from some location to another location than the straight line will, because it's closer to how you can actually move.
- 41:54Yeah.
- 41:54So, yeah, what I thought was really interesting about the coming together of all of these three, well, the three ways of solving this maze problem, were you have basically the same algorithm, and it's really about the data structure that makes it all work.
- 42:09And that was pretty cool.
- 42:10Yeah.
- 42:10A lot of people have said that's one of their biggest aha moments throughout the book, is where we can go and just change the data structure, and the whole solution, how it actually works, changes, even though the rest of the code doesn't.
- 42:21Yeah, it's super cool.
- 42:22Another area that was pretty interesting was the whole set of constraint problems.
- 42:26So, you have a couple in here that we could touch on, the Australian map coloring, the sin plus more equals money, maybe some more realistic problems after that.
- 42:35Yeah.
- 42:36What's cool about those problems is how we can think about them all together as really one problem-solving technique.
- 42:41So, let me tell you a little bit about the problem.
- 42:43So, the Australian map coloring problem is one where we take all the regions of Australia, and we want to fill each of them in with a color, and we only want to use three colors, let's say red, green, and blue.
- 42:53So, is it possible to find a color that we can put on each region without any of them next to each other having the same color?
- 43:02And the answer is, of course, yes.
- 43:03We see this on maps all the time, right?
- 43:05So, how can we solve this with a computer?
- 43:08Well, one way of thinking about the problem is as a constraint satisfaction problem.
- 43:13And what a constraint satisfaction problem is, is it has three parts to it.
- 43:17It has variables.
- 43:17In the case of this problem, it would be the regions.
- 43:20So, the regions of Australia are our variables.
- 43:22Then a constraint satisfaction problem always has domains.
- 43:25Those are what can we fill in for each of the variables.
- 43:28In this case, that would be red, green, or blue.
- 43:30That's the domain of each of those variables.
- 43:32Each of them has to be one of those values for our solution.
- 43:35And then the last part of constraint satisfaction problem is the constraints.
- 43:39In the case of this problem, the constraint is that any two regions next to each other can't have the same color.
- 43:45So, we actually have a bunch of constraints.
- 43:47We have one for every single set of regions that are next to each other.
- 43:50So, a constraint satisfaction problem solver can solve this problem,
- 43:55but it can also solve any other kind of problem that we can define using variables, domains, and constraints.
- 44:02And so, we can write a constraint satisfaction problem solver just once,
- 44:07and then we can use it for other kinds of problems besides just the Australian map coloring problem,
- 44:11such as the one that you mentioned, SEM plus more equals money.
- 44:15That's a crypt arithmetic problem.
- 44:16It says...
- 44:17Those seem so different.
- 44:18Yeah.
- 44:18And yet, the same problem technique or solution will hit them both, right?
- 44:24So, yeah, tell us about that one.
- 44:25It's really interesting.
- 44:26Yeah, it's totally different.
- 44:27SEM plus more equals money is what we call a crypt arithmetic problem.
- 44:30If you line up the letters S-E-N-D and the letters M-O-R-E,
- 44:35and you said each of these letters is going to represent a digit.
- 44:38So, maybe E is four and, you know, maybe N is five or something like that.
- 44:43And then underneath them, as if it was an arithmetic problem,
- 44:46we put the letters M-O-N-E-Y, money, the word money.
- 44:51And we also say that each of those letters has to be a corresponding digit.
- 44:54What digits can we fill in for each of those letters that will lead to SEM plus more equaling money?
- 45:00Well, if you think about it, it actually is a constraint satisfaction problem again.
- 45:05Here's why.
- 45:05Each of the letters is our variable.
- 45:08So, S might be a variable.
- 45:09E might be a variable.
- 45:10N might be a variable.
- 45:11Each of the possible values of those letters is our domain.
- 45:15So, the digits, zero through nine, are the domain of each of those letters.
- 45:19And here's our constraint.
- 45:20Our constraint is that for whatever digits I fill in for each of those letters,
- 45:24the combination of SEM plus more must equal money.
- 45:28So, again, it's actually a constraint satisfaction problem.
- 45:30But when you first look at it, you might be like,
- 45:32wow, this seems totally different from the map coloring problem.
- 45:34But actually, they're the same kind of problem.
- 45:36Yeah, that's pretty amazing.
- 45:38And once you lay it out like that, it's obvious.
- 45:40But I would never look at those two things and go, yeah, that's the same problem.
- 45:43Right, absolutely.
- 45:44So, that's one of the things I like about studying these classic problems,
- 45:48is they show you this larger symmetry or commonality across different,
- 45:55what seem like different problems.
- 45:56And like, oh, it's a recursion problem.
- 45:58It's a, you know, one of these constraint problems.
- 46:01Or it's a graph problem or something like that.
- 46:03Yeah, it's amazing how many different ways we can apply the same problem solving techniques.
- 46:07So, when you're talking about these techniques, you know, like these constraint algorithms are not
- 46:12particularly new.
- 46:13But you did talk about one being, coming along that is actually new, something called constraint
- 46:19propagation.
- 46:19What's the story there?
- 46:21Well, I wouldn't say it's new, but it's a more advanced way of solving these constraint
- 46:25satisfaction problems.
- 46:26So, in the chapter, we teach you a way called backtracking search.
- 46:30And it's actually a type of depth first search.
- 46:32So, it kind of builds on, this is chapter three of the book, it kind of builds on chapter
- 46:35two's explanation of depth first search.
- 46:37And in backtracking search, it's every time you hit a wall.
- 46:41So, every time we found a way of filling in domains for these variables that solves the
- 46:46constraints, but then it doesn't solve one of them.
- 46:49We go backwards.
- 46:50And we try to find a different fill-in that doesn't lead us into that wall.
- 46:55In constraint propagation, we instead ahead of time try to figure out, okay, I think this
- 47:01is going to work well.
- 47:02And we might still do a backtracking search at the end to make sure it really does work
- 47:06well.
- 47:06But instead of doing it after we've already hit a wall, we try to figure out what's going
- 47:11to work before we hit the wall at the very beginning.
- 47:13We don't actually get into the details of how that works in the book.
- 47:16It's kind of more of an advanced technique.
- 47:18But it's a little more efficient.
- 47:20And so, if you were going to solve this on a really big problem, so a problem that, let's
- 47:25say, had hundreds of variables and hundreds of domains and constraints, then maybe you would
- 47:30want to use something more advanced than the technique we teach in the book.
- 47:33What are some of the real world places where these constraint problems show up?
- 47:37I would say the most common is probably scheduling.
- 47:39So, if you think about a bunch of people want to meet and they have all of them at different
- 47:44availabilities, we could think about the individual people that want to meet as the
- 47:48variables, what their availabilities are as their domains, and who needs to be at that
- 47:53meeting as the constraints.
- 47:55And there's actually real life schedulers that use constraint satisfaction techniques to do
- 48:02scheduling.
- 48:02I can't tell you for sure if that's what Google Calendar uses, for example, but it wouldn't
- 48:06surprise me.
- 48:07Yeah, of course.
- 48:07So, very powerful.
- 48:08And I think the idea of the common technique across non-obvious things is really great with
- 48:13that set of problems.
- 48:14Another one are graph problems.
- 48:17Not parabola, but vertices and edges types of graph theory problems, right?
- 48:24Yeah.
- 48:24And I think this is an area that people who have a math degree or a CS degree are totally
- 48:30familiar with.
- 48:30And sometimes people who are self-taught programmers don't have any experience with.
- 48:35And it's, again, it's something that is applicable to actually a wide range of different problems.
- 48:40And you might not even realize it when you're first seeing it.
- 48:43Because what is a graph?
- 48:45Well, a graph is technically a set of vertices that are connected to each other by edges.
- 48:50And it's really an abstract math concept.
- 48:52But in the real world, we actually see them all the time.
- 48:55So anytime you see a network, that's basically a graph.
- 48:59For example, the subway in New York City, that's a graph.
- 49:02Every one of the stations is a vertice.
- 49:04And edges are the tunnels that connect each of those stations.
- 49:08If you want to lay out electric wire throughout a neighborhood, that's a graph.
- 49:12Each of the houses you need to hook up, that's a vertice.
- 49:14And the line you're going to run from one house to another or to the poles, that's an edge.
- 49:19So we can actually use this concept of just having vertices and edges to represent a huge number
- 49:25of different problems.
- 49:26And what we teach in the chapter is a bunch of different techniques for solving common problems
- 49:32you'd fall into when you want to use these graphs, such as how do I find the shortest path
- 49:37from one vertice to another?
- 49:39Or to put it in the context of what we just mentioned,
- 49:42how do I find the shortest path from one subway station to another subway station?
- 49:46Or how do I use the minimum amount of edges of certain lengths to connect all the different
- 49:54vertices in the context of the electric wire?
- 49:56How do I use as little electric wire as possible to electrify this whole neighborhood?
- 50:02And that's actually the problem that originally inspired some of these algorithms in Czech Republic.
- 50:07They were trying to electrify large parts of Czech Republic.
- 50:10And some mathematicians in Czech Republic in the 1920s and 1930s came up with the algorithms
- 50:15for finding the least amount of electric wire to electrify the country.
- 50:19That's a pretty cool bit of history.
- 50:20I didn't know that.
- 50:21I do like you in there when you're presenting the problem.
- 50:24You talk about the hyperloop and some of the interesting things you might consider.
- 50:29So you have a bunch of connections between the major cities.
- 50:32And you imagine those are hyperloop, Elon Musk, high speed tube things, connecting them.
- 50:38And you said, look, here's the map of the US and here's the cities and maybe the tracks.
- 50:43But throw away the map.
- 50:44Just think of these as connections and the points.
- 50:47And then how do you get from one point to the other?
- 50:50You also said some interesting things like, you know, probably it's longer to make a connection
- 50:54at a city than it is to travel between two cities, given that those things are supposed
- 50:58to travel, you know, supersonic effectively.
- 51:01Right.
- 51:02So that completely changes the way you think about solving the problem, right?
- 51:05Right.
- 51:06I mean, the hyperloop is supposed to be, for people that don't know, this super fast way
- 51:09of going 700 miles per hour in some tubes underground, right?
- 51:13If you're going 700 miles per hour, what do you care about more?
- 51:16How long the routes are?
- 51:17Do you care like that it's a thousand miles from one to another?
- 51:20Or do you care how many stops you're going to have to make along the way?
- 51:24Because it actually might be every time you make a stop, there's a little layover.
- 51:28And that will actually end up taking more time, even if the other route is a longer distance.
- 51:33So we use the hyperloop as a motivating problem to go through a bunch of these different graph
- 51:38algorithms.
- 51:39And one thing we find is that the distance that it takes might not matter as much as how
- 51:45many stops we make along the way for something like the hyperloop.
- 51:49And so there's a different algorithm you'd use for how many stops you want to make versus
- 51:53the route that might have the shortest distance.
- 51:56Right.
- 51:56Just to talk about things like minimum spanning trees, where like maybe what is the minimum
- 52:01amount of money or track or tube you can lay to actually just connect these things,
- 52:05regardless of what sufficient, right?
- 52:08Right.
- 52:08So if we think about every major city in the United States and we want to connect them
- 52:12all, right?
- 52:12How do you actually draw connections between all of them that would use the minimum amount
- 52:18of money to build, let's say, because it's going to be the minimum amount of track that you
- 52:23would have to lay?
- 52:24You know, as a human being, we can solve that pretty easily if there's like five cities,
- 52:29right?
- 52:29We may be even able to solve that if there's 10 cities.
- 52:32When you start thinking about 15 or 20 or 30, you need an efficient way for a computer to
- 52:37do that.
- 52:38And finding the minimum spanning tree is what we call those algorithms.
- 52:41Yeah.
- 52:42It's pretty cool.
- 52:42Another one, another category of problems that you talked about, and they seem to have a lot
- 52:47to do with games like board games and stuff, were the adversarial search problems.
- 52:52So these apply to zero sum, two player, perfect information games, unlike say a poker or something
- 52:59where you don't know what the other player has or can play, right?
- 53:01Right.
- 53:02So a very common thing that people do when they're learning programming is programming tic-tac-toe.
- 53:07It's just, for some reason, it's just something people love to do.
- 53:10Super easy to program tic-tac-toe when you're just saying, okay, player one is going to put X
- 53:15somewhere on the board and player two is going to put O somewhere on the board.
- 53:18That's easy.
- 53:19But what if you want the computer to play tic-tac-toe perfectly?
- 53:22So your first instinct might be, oh, so I'll just hard code that every time there's two
- 53:29things next to each other, have the computer do a block.
- 53:32Or every time there are the boards totally open, have the computer play center.
- 53:37But there's actually an algorithm called Minimax that instead of having to hard code every possible
- 53:42position, we can just have a way of figuring out what the best position is all the time by
- 53:48searching through what the result will be of the opponent's move to the computer's move.
- 53:55And then the result of the best move I can make to the opponent's move back and forth,
- 53:59back and forth till I get to the end of the game.
- 54:01Or sometimes in Minimax, like in a much more complex game than tic-tac-toe, something like
- 54:06chess or checkers, we won't get to the end of the game, but we'll get, let's say, five or
- 54:10six moves into the future.
- 54:11And we can then just see how good is the position at that point.
- 54:14So Minimax is an algorithm that we can use for any game that's basically two players that
- 54:21we can actually look at the whole board at once.
- 54:24And that's what we call perfect information, being able to see all the information about
- 54:28the game at any given time and have a computer play it really, really well.
- 54:32And this is the way that chess engines work, for example.
- 54:35Most of them use Minimax or more advanced variants of it that allow them to play better than any
- 54:40grandmaster in the world.
- 54:41And on a modern computer, you can program yourself a chess engine that'll be any of your friends.
- 54:47Easily.
- 54:49It's not that hard.
- 54:50Yeah.
- 54:50Yeah.
- 54:51You get a little IoT and a camera and some computer vision.
- 54:54They just take it to the tournament and hold it above, right?
- 54:56Yeah, exactly.
- 54:57Yeah.
- 54:58Yeah.
- 54:58It's pretty cool.
- 54:59That's a nice one.
- 55:00Now, I saved the craziest ones to ask you about for last because I looked through the
- 55:05examples and it still is kind of sketchy in my mind, but it's very interesting.
- 55:09That's the whole category of genetic algorithms where you don't really know the solution, but you
- 55:15turn loose a bunch of different algorithms and then they tweak themselves.
- 55:20And they evolve to try to find the solution.
- 55:23Tell us about that.
- 55:24Yeah.
- 55:24So with genetic algorithms, we don't usually know the way to solve the problem.
- 55:29So it might be a problem that's so hard that we don't know any way to efficiently come up
- 55:34with a solution.
- 55:35And so instead, we borrow this idea from nature of trying a lot of different solutions and slightly
- 55:42modifying them when we think they're getting closer to the actual solution.
- 55:47So in the real world, right?
- 55:49We have evolution and natural selection, right?
- 55:52You have some species comes up and it's really well adapted to its environment.
- 55:57So it has more children.
- 55:58And then some other modification to it might actually make it less adapted.
- 56:03So it has less children.
- 56:05And the species that's better adapted is the one that tends to survive over time, right?
- 56:09So it's just applying that same idea to solutions to a problem on a computer.
- 56:13We're saying, oh, I'm going to maybe at first even randomly try a bunch of random different
- 56:17solutions.
- 56:18The ones that seem to work better, oh, I'll let those solutions propagate.
- 56:22I'll modify them slightly.
- 56:24So it's like they're having children.
- 56:26And I'll let those children be the progenitors of the next generation of possible solutions.
- 56:30And the ones that didn't seem to work so well, well, I'm going to let them die.
- 56:34Unfortunately, that's how natural selection works.
- 56:36And so I'll keep hopefully slowly building by making small random modifications closer to
- 56:42an actual solution to the problem.
- 56:44Now, doing anything randomly is never probably going to be your first reach for solution to
- 56:50a problem.
- 56:51When you do something randomly, there's a strong possibility it'll take a really long
- 56:55time to really get to a good solution.
- 56:58So even if you're climbing in the right direction, as we do in genetic algorithms, right?
- 57:03So you only want to use genetic algorithms when you really can't think of any other way to
- 57:08approach this problem.
- 57:09But there are some situations where they work pretty well because we don't know any better
- 57:13way to really solve the problem.
- 57:15Sure.
- 57:15So I understand the idea of letting it evolve, like the algorithm evolve.
- 57:21You tweak it in a little way.
- 57:22But it seems to me like you almost have to give it the algorithm a fixed structure, right?
- 57:29You're going to try to do this with these seven, like almost constants or constraints that you're
- 57:35going to apply.
- 57:36But you're always going to like try to fit this type of calculation or this type of thing
- 57:41to it.
- 57:41Like how much variation can you actually get as these evolve?
- 57:45You're absolutely right.
- 57:46You do have to kind of set some constraints at the front.
- 57:48So for example, if I'm trying to find the solution to a math problem, right?
- 57:54And I have X and Y and X and Y, I need to know what are the right numbers that should fill in for X
- 58:00and Y to solve the math problem, right?
- 58:02It would be really helpful if instead of generating any random numbers at the very start, I put them
- 58:08within a reasonable range.
- 58:09Like if I know just before I start the problem that probably X and Y are going to be between
- 58:14zero and 100, it would be good if I just generated random X and Ys to start out with that are only
- 58:19between zero and 100.
- 58:20Because otherwise I could just go way off in the left field and never get anywhere close to
- 58:25my solution.
- 58:25So you're absolutely right.
- 58:26You have to have some knowledge of the problem to set it up appropriately for a genetic algorithm.
- 58:31Right.
- 58:32So it's not, well, is it possible?
- 58:33I guess let me just ask you that way.
- 58:35That, you know, I start up with an algorithm that says we're going to try to use this equation to
- 58:40match some kind of answer and it evolves itself into using a neural network instead.
- 58:45Oh.
- 58:45It can't make that much of a change, can it?
- 58:47No, it can't make, you know, it's interesting you mentioned that, you know, we do have a chapter
- 58:52in the book on neural networks.
- 58:53Neural networks are the hardest technique we go over in the book.
- 58:56If you want to do something even harder, I have a colleague at work and he works on using
- 59:00genetic algorithms with neural networks.
- 59:02Okay.
- 59:03That's pretty interesting.
- 59:05Yeah.
- 59:05Trying to evolve the neural networks to more accurately solve a certain problem.
- 59:10So yes, it is possible to combine the two techniques, but your listeners should not worry
- 59:15that if you just program a genetic algorithm, it will not morph itself into a neural network.
- 59:19There may be a singularity, but probably not.
- 59:22Not yet.
- 59:22Not for that path.
- 59:23Yeah.
- 59:23Not that way.
- 59:25No.
- 59:25That's cool.
- 59:26So I guess, you know, that covers many of the problems you laid out.
- 59:30There are some other popular ones like the knapsack and traveling salesman problems and
- 59:34some others we didn't cover as well.
- 59:35But there's a lot of cool techniques that I think are worth studying here.
- 59:39Which one is your favorite?
- 59:40So I would say that I actually like the graph problems best because we're doing something there
- 59:46that is motivated by a real world problem, which is building out a transportation network
- 59:51throughout the whole chapter.
- 59:53One thing that people might be a little suspicious of is that the book is full of toy problems,
- 59:59right?
- 59:59And that is true.
- 1:00:00A lot of the problems in the book are problems that are a little fanciful.
- 1:00:05They're not necessarily something that you're going to come across on a day-to-day basis because
- 1:00:10we have to have problems small enough that you can actually learn all of them in a fairly
- 1:00:15short chapter, right?
- 1:00:16We can't get into all the details of a really sophisticated problem, unfortunately, in a book
- 1:00:21of this length and this broad.
- 1:00:24So a lot of them are kind of toy problems.
- 1:00:25It's more about learning the techniques that you use on these toy problems and how they
- 1:00:29might apply to your real world problems.
- 1:00:31In the graph problem chapter, I think right away you can see how that problem is similar
- 1:00:35to a lot of real world problems.
- 1:00:37All the time, we're trying to figure out what's the most efficient way to traverse some kind
- 1:00:41of network.
- 1:00:42If you're working in even API plumbing, you might have a bunch of nodes that you need
- 1:00:47to hit.
- 1:00:48And what's the most efficient way to traverse hitting all those nodes in a certain order?
- 1:00:52That lends itself maybe to a graph problem.
- 1:00:55So the graph problem chapter, I really love just because it's so immediately applicable.
- 1:00:59Yeah, that's a good one.
- 1:01:00So one of the things that was evident to me was that choosing the right data structure was
- 1:01:06really important and learning the algorithms is good.
- 1:01:10But I think also knowing the data structures, maybe it's even more important in some ways.
- 1:01:14So for people who maybe are self-taught, what are some of the most important data structures?
- 1:01:19And where do you think they might have holes that they don't realize are blind spots that
- 1:01:24they should go check out?
- 1:01:25Well, if you're programming in Python, you got to be really, really familiar with lists and
- 1:01:29with dictionaries.
- 1:01:30I mean, if you're not at least an expert in those two, you're not using Python to its full
- 1:01:35extent because they are just so all over the language and all over the standard
- 1:01:40library.
- 1:01:40So you should at a minimum be familiar with lists and dictionaries.
- 1:01:44Now, then there's more abstract data structures that are built on top of those.
- 1:01:48Everyone should be familiar with stacks and queues, which are built on top of lists.
- 1:01:52And again, those are, like we mentioned earlier, structures that the first thing I put into them
- 1:01:56might be the first thing I get out in the case of a queue, or the last thing I put into
- 1:02:00them is the first thing I take out in the case of a stack.
- 1:02:04Everyone should be familiar with those two.
- 1:02:06Then we get into some that are a little bit more esoteric, like a priority queue.
- 1:02:10They're really useful to know about in certain applications or certain algorithms that are
- 1:02:15pretty useful algorithms like A-star, which we talked about earlier, that you can't implement
- 1:02:19without them.
- 1:02:20So you might not use them every day, but there are situations where it's good to be at least
- 1:02:25familiar with them.
- 1:02:26We don't do a lot of work in the book with trees, which some people might find surprising.
- 1:02:31But I'd say that's a common hole that people have is not being familiar with how to build
- 1:02:36a tree and how to structure a tree.
- 1:02:37And, you know, one thing people use this book for sometimes I've heard in the Swift book as
- 1:02:42well is preparing for interviews.
- 1:02:44Unfortunately, I think unfortunately, a lot of programming interviews have become very kind
- 1:02:49of algorithmic problem solving.
- 1:02:50I think knowing all these data structures will help you a lot when doing those interviews.
- 1:02:55And so I'd recommend everyone be familiar with stacks, queues, priority queues, trees, of
- 1:03:01course, lists and dictionaries.
- 1:03:03Everyone who programs in Python should be an expert on dictionaries.
- 1:03:05I'm sure you'd agree.
- 1:03:06I do.
- 1:03:06I definitely agree that, you know, the dictionaries especially show up not just where you use them,
- 1:03:12but they also show up as foundational things, right?
- 1:03:15Like for the backing, holding all the fields and attributes of a class, for example.
- 1:03:19So super, super important.
- 1:03:20Yeah.
- 1:03:21So I guess one other question along those lines is people are excited about this topic.
- 1:03:26Maybe they get your book.
- 1:03:27Where else could they go?
- 1:03:28I mean, are there good MOOCs like Carnegie Mellon or something like that?
- 1:03:33Or where should they go?
- 1:03:34I'll point out a few different resources.
- 1:03:35So first of all, I should say this book is not a textbook.
- 1:03:39So it doesn't teach you a lot of the math behind these algorithms.
- 1:03:42It doesn't teach you big O notation.
- 1:03:44It uses big O notation a little bit, but it doesn't really go into a lot about it.
- 1:03:48So we really wanted to make it a really approachable book.
- 1:03:51So we kept the math to a minimum.
- 1:03:52We even tried to keep the math to a minimum in chapters like the neural networks chapter
- 1:03:56and the k-means clustering chapter.
- 1:03:58These more kind of AI chapters, machine learning chapters, because we wanted the book to be approachable.
- 1:04:03That said, that means that we're not really giving you the full story.
- 1:04:07And so if you really want to get the full story, there's a couple textbooks I'd recommend.
- 1:04:11One is Algorithms by Sedgwick and Wayne.
- 1:04:14That's a really common college textbook on algorithms and data structures.
- 1:04:19And it is probably the most approachable, in my opinion, of the textbooks.
- 1:04:23It's really well written.
- 1:04:24Unfortunately, it's in Java, not in Python.
- 1:04:26So that kind of sucks.
- 1:04:28But it's still a really easy, readable textbook.
- 1:04:31The classic textbook in this area is called Introduction to Algorithms by Corman and his
- 1:04:36co-authors, CLRS, it's sometimes called.
- 1:04:39That is a really good textbook.
- 1:04:41It's more reference quality material.
- 1:04:43Some people say it's a little bit less approachable than just the Algorithms book by Sedgwick.
- 1:04:48In terms of online resources, strongly would recommend the Algorithms course on Khan Academy.
- 1:04:54Again, unfortunately, it's in JavaScript, not in Python.
- 1:04:57But having looked at a bunch of these resources, I really think for new learners, that's a really
- 1:05:01strong course on Khan Academy.
- 1:05:03If you want to get more into the machine learning type of stuff we talked about in the book, like
- 1:05:07K-means clustering and neural networks, then the machine learning course on Coursera taught
- 1:05:12by Andrew Ng has become kind of a standard that a lot of people go through.
- 1:05:16And it's very high quality.
- 1:05:19And unfortunately, again, it's in MATLAB slash Octave instead of Python.
- 1:05:24I don't think there are a couple Python textbooks and data structures and algorithms.
- 1:05:29None of them have become, let's say, classics.
- 1:05:32So I can't individually recommend any of them.
- 1:05:35I'm also not immediately familiar with all of them.
- 1:05:38But I do think most of these resources for anyone who's been doing a year or two of Python,
- 1:05:43you'd be quickly able to read most of the ones that we mentioned.
- 1:05:47Right.
- 1:05:47Okay.
- 1:05:47Well, that sounds great.
- 1:05:48Well, Dave, I think we're getting pretty low on our time.
- 1:05:51So we've used it about up and talking about all these great things.
- 1:05:54So I guess we'll have to leave it here.
- 1:05:55But let me ask you the two questions before we call it a show.
- 1:05:59If you're going to write some Python code, what editor do you use?
- 1:06:03I'm all about PyCharm now.
- 1:06:04Big fan.
- 1:06:05Right on.
- 1:06:05Me too.
- 1:06:06And then notable PyPI package, even though, ironically, you didn't really use many of them
- 1:06:11in your examples.
- 1:06:12What's maybe one folks haven't heard of that they should know about?
- 1:06:15Well, I don't know.
- 1:06:16People are familiar with it, I'm sure.
- 1:06:17scikit-learn.
- 1:06:18I think scikit-learn just has so much functionality built in.
- 1:06:21And let me just add, you know, the purpose of reading a book like this is not that you're
- 1:06:26going to go implement all of these techniques yourself.
- 1:06:28It's so that you're going to know which open source library to include in your project.
- 1:06:33We don't expect you to go implement scikit-learn yourself.
- 1:06:36But when you use scikit-learn, which of the algorithms from it should you be using?
- 1:06:39Yeah, it makes a lot of sense.
- 1:06:40Yeah.
- 1:06:41You don't want to go and reinvent 10 years of lots of work, right?
- 1:06:45It's like reinventing NumPy.
- 1:06:46You wouldn't do it, but understanding what's happening is really good.
- 1:06:48Exactly.
- 1:06:48Yeah.
- 1:06:49Cool.
- 1:06:49All right.
- 1:06:50Well, final call to action.
- 1:06:51People want to get more into learning these algorithms and data structures and these classic
- 1:06:55problems.
- 1:06:56What do they do?
- 1:06:56Well, you can get the book from Manning.
- 1:06:58Manning's a publisher, manning.com.
- 1:07:00And I think you're going to be offering a promo code for your listeners.
- 1:07:02It's called Classic Computer Science Problems in Python.
- 1:07:05It's also going to be available on Amazon starting at the beginning of April.
- 1:07:08Okay.
- 1:07:09Sounds great.
- 1:07:10Well, Dave, thank you for being on the show.
- 1:07:13It was great to talk to you about all these things.
- 1:07:14There's a bunch of cool stuff you put together here.
- 1:07:16Thanks a lot for having me, Michael.
- 1:07:17It was a real pleasure.
- 1:07:18You bet.
- 1:07:18Bye.
- 1:07:19This has been another episode of Talk Python To Me.
- 1:07:23Our guest on this episode was David Kopec, and it's been brought to you by Microsoft.
- 1:07:27If you're a Python developer, Microsoft has you covered.
- 1:07:31From VS Code and their modern editor plugins, to Azure Pipelines for continuous integration,
- 1:07:36and serverless Python functions on Azure.
- 1:07:38Check them out at talkpython.fm/Microsoft.
- 1:07:42Want to level up your Python?
- 1:07:45If you're just getting started, try my Python Jumpstart by Building 10 Apps course.
- 1:07:49Or if you're looking for something more advanced, check out our new async course that digs into
- 1:07:54all the different types of async programming you can do in Python.
- 1:07:57And of course, if you're interested in more than one of these, be sure to check out our
- 1:08:01Everything Bundle.
- 1:08:02It's like a subscription that never expires.
- 1:08:04Be sure to subscribe to the show.
- 1:08:06Open your favorite podcatcher and search for Python.
- 1:08:09We should be right at the top.
- 1:08:10You can also find the iTunes feed at /itunes, the Google Play feed at /play,
- 1:08:15and the direct RSS feed at /rss on talkpython.fm.
- 1:08:19This is your host, Michael Kennedy.
- 1:08:21Thanks so much for listening.
- 1:08:22I really appreciate it.
- 1:08:24Now get out there and write some Python code.
- 1:08:25I'll see you next time.
- 1:08:26Bye.
- 1:08:26Bye.
- 1:08:26Bye.
- 1:08:26Bye.
- 1:08:27Bye.
- 1:08:27Bye.
- 1:08:27Bye.
- 1:08:27Bye.
- 1:08:27Bye.
- 1:08:27Bye.
- 1:08:27Bye.
- 1:08:27Bye.
- 1:08:27Bye.
- 1:08:27Bye.
- 1:08:28Bye.
- 1:08:28Bye.
- 1:08:28Bye.
- 1:08:28Bye.
- 1:08:28Bye.
- 1:08:28Bye.
- 1:08:28Bye.
- 1:08:28Bye.
- 1:08:28Bye.
- 1:08:29Bye.
- 1:08:29Bye.
- 1:08:29Bye.
- 1:08:29Bye.
- 1:08:29Bye.
- 1:08:29Bye.
- 1:08:29Bye.
- 1:08:30Bye.
- 1:08:30Bye.
- 1:08:30Bye.
- 1:08:30Bye.
- 1:08:30Bye.
- 1:08:30Bye.
- 1:08:30Bye.
- 1:08:30Bye.
- 1:08:30Bye.
- 1:08:30Bye.
- 1:08:30Bye.
- 1:08:30Bye.
- 1:08:30Bye.
- 1:08:30Bye.
- 1:08:31Bye.
- 1:08:31Bye.
- 1:08:31Bye.
- 1:08:31Bye.
- 1:08:32Bye.
- 1:08:32Bye.
- 1:08:32Bye.
- 1:08:32Bye.
- 1:08:32Bye.
- 1:08:32Bye.
- 1:08:32Bye.
- 1:08:32Bye.
- 1:08:32Bye.
- 1:08:32Bye.
- 1:08:32Bye.
- 1:08:32Bye.
- 1:08:33Bye.
- 1:08:33Bye.
- 1:08:33Bye.
- 1:08:33Bye.
- 1:08:34Bye.
- 1:08:34Bye.
- 1:08:34Bye.
- 1:08:34Bye.
- 1:08:34Bye.
- 1:08:34Bye.
- 1:08:34Bye.
- 1:08:34Bye.
- 1:08:34Bye.
- 1:08:35Bye.
- 1:08:35Bye.
- 1:08:35Bye.
- 1:08:35Bye.
- 1:08:36Bye.
- 1:08:36Bye.
- 1:08:36Bye.
- 1:08:36Bye.
- 1:08:36Bye.
- 1:08:36Bye.
- 1:08:36Bye.
- 1:08:37Bye.
- 1:08:37Bye.
- 1:08:37Bye.
- 1:08:37Bye.
- 1:08:37Bye.
- 1:08:37Bye.
- 1:08:37Bye.
- 1:08:38Bye.
- 1:08:38Bye.
- 1:08:38Bye.
- 1:08:39Bye.
- 1:08:39Bye.
- 1:08:39Bye.
- 1:08:39Bye.
- 1:08:39Bye.
- 1:08:39Bye.
- 1:08:39Bye.
- 1:08:39Bye.
- 1:08:40Bye.
- 1:08:40Bye.
- 1:08:40Bye.
- 1:08:41Bye.
- 1:08:41Bye.
- 1:08:41Bye.
- 1:08:41Bye.
- 1:08:41Bye.
- 1:08:41Bye.
- 1:08:42you
- 1:08:42you
- 1:08:43you
- 1:08:43Thank you.
- 1:08:45Thank you.