Summary
Software development is a career that attracts people from all backgrounds, and Python in particular helps to make it an approachable occupation. Because of the variety of paths that can be taken it is becoming increasingly common for practitioners to bypass the traditional computer science education. In this episode David Kopec discusses some of the classic problems that he has found most useful to understand in his work as a professor and practitioner of software engineering. He shares his motivation for writing the book "Classic Computer Science Problems In Python", the practical approach that he took, and an overview of how the contents can be used in your day-to-day work.
Announcements
- Hello and welcome to Podcast.__init__, the podcast about Python and the people who make it great.
- When you’re ready to launch your next app or want to try a project you hear about on the show, you’ll need somewhere to deploy it, so take a look at our friends over at Linode. With 200 Gbit/s private networking, scalable shared block storage, node balancers, and a 40 Gbit/s public network, all controlled by a brand new API you’ve got everything you need to scale up. Go to pythonpodcast.com/linode to get a $20 credit and launch a new server in under a minute. And don’t forget to thank them for their continued support of this show!
- And to keep track of how your team is progressing on building new features and squashing bugs, you need a project management system designed by software engineers, for software engineers. Clubhouse lets you craft a workflow that fits your style, including per-team tasks, cross-project epics, a large suite of pre-built integrations, and a simple API for crafting your own. Podcast.__init__ listeners get 2 months free on any plan by going to pythonpodcast.com/clubhouse today and signing up for a trial.
- Visit the site to subscribe to the show, sign up for the newsletter, and read the show notes. And if you have any questions, comments, or suggestions I would love to hear them. You can reach me on Twitter at @Podcast__init__ or email hosts@podcastinit.com)
- To help other people find the show please leave a review on iTunes, or Google Play Music, tell your friends and co-workers, and share it on social media.
- Join the community in the new Zulip chat workspace at pythonpodcast.com/chat
- Your host as usual is Tobias Macey and today I’m interviewing David Kopec about his recent book "Classic Computer Science Problems In Python"
Interview
- Introductions
- How did you get introduced to Python?
- Can you start by discussing your motivation for creating this book and the subject matter that it covers?
- How do you define a "classic" computer science problem and what was your criteria for selecting the specific cases that you included in the book?
- What are your favorite features of the Python language, and which of them did you learn as part of the process of writing the examples for this book?
- Which classes of problems have you found to be most difficult for your readers and students to master?
- Which do you consider to be most relevant/useful to professional software engineers?
- I was pleasantly surprised to see introductory aspects of artificial intelligence included in the subject matter that you covered. How did you approach the challenge of making the underlying principles accessible to readers who don’t necessarily have a background in the related fields of mathematics?
- What are some of the most interesting or unexpected changes that you had to make in the process of adapting your examples from Swift to Python in order to make them appropriately idiomatic?
- By aiming for an intermediate audience you free yourself of the need to incorporate fundamental aspects of programming, but there can be a wide variety of experiences at that level of experience. How did you approach the challenge of making the text accessible while still being accurate and engaging?
- What are some of the resources that you would recommend to readers who would like to continue learning about computer science after completing your book?
Keep In Touch
- @davekopec on Twitter
- Website
Book Discount And Giveaway
- Use code podinit19 to get 40% off all Manning products
Picks
- Tobias
- David
Links
- Classic Computer Science Problems in Python
- Classic Computer Science Problems in Swift
- Dart For Absolute Beginners
- Dart
- Swift
- Manning Publications
- Apress
- Python Data Classes
- Python Type Hints
- Recursion
- A* Search Algorithm
- Neural Network
- Champlain College
- Burlington, VT, USA
- HyperLoop
- Data Structures And Algorithms In Python by Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser
- MyPy
- PyTorch
- Minimax
- Dartmouth College
- Big O Notation
The intro and outro music is from Requiem for a Fish The Freak Fandango Orchestra / CC BY-SA
Hello, and welcome to podcast dot in it, the podcast about Python and the people who make it great. When you're ready to launch your next app or want to try a project you hear about on the show, you'll need somewhere to deploy it. So say hi to our friends over at Linode. With 200 gigabit private networking, scalable shared block storage, node balancers, and a 40 gigabit public network, all controlled by a brand new API, you've got everything you need to scale up. Go to python podcast.com/linode, l I n o d e, to get a $20 credit and launch a new server in under a minute. And don't forget to thank them for their continued support of this show. And if you're like me, then you need a simple and easy to use tool to keep track of all of your projects.
Some project management platforms are too flexible, leading to confusion of workflows and days' worth of setup, and others are so minimal that they aren't worth the cost of admission. After using Clubhouse for a few days, I was impressed by the intuitive flow, Going from adding the various projects that I work on to defining the high level epics that I need to stay on top of and creating the various tasks that need to happen only took a few minutes. I was also pleased by the presence of subtasks, seamless navigation, and the ability to create issue and bug templates to ensure that you never miss capturing essential details. Listeners of this show will get a full 2 months for free on any plan when you sign up at python podcast.com/clubhouse.
So help support the show and help yourself get organized today. And don't forget to visit the site at python podcast.com to subscribe to the show, sign up for the mailing list, and read the show notes. And don't forget to keep the conversation going at python podcast.com/chat. Your host as usual is Tobias Macy. And today I'm interviewing David Kopek about his recent book, Classic Computer Science Problems in Python. So, David, could you start by introducing yourself? Hi, Tobias. And let me just say it's an honor to be on the podcast. I'm an assistant professor of computer science and innovation at Champlain College in beautiful Burlington, Vermont.
[00:02:06] Unknown:
And before that, I worked for a few years as a professional software developer, and I've been writing technical books for about 5 years now. This is my 3rd book. And I saw that this is actually an adaptation of 1 that you did
[00:02:19] Unknown:
focused on the Swift programming language as well. So I'm wondering how you found the transition from Swift to Python and if you can talk a bit about how you first got introduced to Python as well. Yeah. Absolutely. So I've been programming since I was a little kid, but I first got introduced to Python when I was in graduate school, which was about 2010.
[00:02:39] Unknown:
And I just found all my classes in graduate school were in Python, and I fell in love with the language in graduate school. I just loved how succinct it was. I loved, the Python philosophy. And then when I graduated, I worked in kinda mobile software development for a few years. And so I was I I was kinda out of Python for that period. I would use it sometimes for scripting or for a small Flask web app. But now being a assistant professor the last few years, teaching computer science, I'm again, teaching some classes in Python. And that kind of brought me back into the Python world. As far as the book goes, so we had the Swift book. It came out in 2018 and it was moderately successful. And the publisher said, you know, it would be great if this book was in Python. And I love Python, so I was excited to do it. I said to them, if we're gonna do it in Python, we really have to do it right. So it has to be idiomatic Python. It has to really be using the latest features of the language. So we put together a team, including the technical editor, the reviewers, the technical proofer.
Were really adept at modern Python. And so it wasn't just me. Obviously, I've been in and out of the Python world, so I wanted to make sure we had a team that knew that we were writing a book that was using all the best and greatest latest features of Python.
[00:03:51] Unknown:
And, I think it's been going great. The book comes out next month, and I'm really excited about it. And so you mentioned that you've been writing technical books for about 5 years now. And I'm wondering if you can discuss your motivation for getting started on that path initially and your particular motivation for creating this book and the subject matter that it covers. And feel free to sort of abstract across this and the Swift book because I'm sure that they have a lot of,
[00:04:18] Unknown:
similar origin story or similar motivations behind them. Absolutely. So my first book was called Dart for Absolute Beginners. It came out in 2014. It was published by a press. And I had become very interested in 2 things that kinda collided there. 1 was computer science education, and so that was a book for people who had no previous programming experience. And at the time, I'm not as into it anymore, but at the time I was really into the Dart programming language and it was just coming out. So just the 1 of the language was coming out. So the the combination of those 2 factors led me to write that book. And, after I wrote that book, I the next book, it was a few years later. It was 2017 that I started on classic computer science problems in Swift.
And my idea there was when I was growing up in the nineties, there were these basic problem books that were still actually a lot of them were from the eighties, and my dad was a computer science professor. And they would be, here's a problem. Here's how you solve it in basic. And that was kind of my introduction to programming, was working through some of those problems in those books. And so I wanted to do something like that for a modern language. And because now I'm in academia, I wanted to make it a little bit more serious so they're not just completely toy problems. They're problems from a computer science curriculum. So I wanted to make a book that was approachable to anyone who's an intermediate programmer, including people who don't have a computer science degree, and I wanted to make sure it was also using the modern languages and using the current feature set of those modern languages. So we did Swift first, and then like we mentioned before we when we ported over to Python, it's largely the same content, but we're trying to make it as idiomatic Python as possible using as many features from the standard library as possible and including features that just came out in the 3.7 release of the language. And was there a particular aspect of 3.7
[00:06:06] Unknown:
in particular that you wanted to bring in that motivated you to use that as opposed to the 3.6 release?
[00:06:15] Unknown:
Yeah. So data classes were 1. We used data classes in a in a couple chapters. And the other big thing, and I'm gonna go into this quite a bit because it was kind of a controversial decision, was using type hints throughout the book. So we use type hints throughout. Type hints have been in the Python language as I'm sure most of your listeners know for a couple releases now, but every release they get a little bit more refined and a little bit easier to use. And so 3.7 has a couple type hints features, that were not in, let's say, 3.5, for example, and there's 1 or 2 that were not in 3.6.
And using type hints was a really controversial decision, I will say that, because there's some Python programmers who are not in love with type hints. And I've learned that through the review process of the book. Every 1 third of the book, they send it out to 10 to 12 external reviewers. The publisher does this manning. And some of those reviewers were like, why did you use type ins? Type ins make the code less Pythonic, harder to read. And I think for a book like this where you're giving problems where you want people to right away be able to easily read the solutions, I think the type ins actually make it more readable because you know what type a function returns at any given time without having to read all the details of it. And you don't have to go read documentation to see that either. So I think the type hints made the book more readable. Most of the reviewers of the book love the type hints and some people even said, you know, there haven't been a lot of Python books yet that use type hints.
And so this is actually a groundbreaking book in that factor. But it was a controversial decision certainly, and I can I definitely understand the point of view of the people who think type hints sometimes make the code less readable by just making it more verbose?
[00:07:58] Unknown:
So it was a controversial decision, but 1 that I'm gonna stand by by, maybe making the book a little bit more unique. Yeah. That's 1 of those arguments that has been going on for as long as there have been programs essentially same as tabs versus spaces or emacs versus VIM or whatever your flame war of choice happens to be for this month. So, it it's good to see that you have an opinion and that you're willing to stick with it. And as far as I'm concerned, that's the most important piece is having the consistency and having a coherent reason behind why you would choose to use a particular approach as opposed to it just being cargo culted and doing it because of some, current popularity regardless of whether or not it's actually a useful feature for your particular purpose.
[00:08:42] Unknown:
Yeah. And for people who purchase the book, in appendix c, we give a quick jump start into type hints. So people have never seen them before, we do give you a very brief introduction in appendix. And we kinda lay out the reasons why you would wanna use them or you wouldn't wanna use them in your own code. And I think on balance, it adds to the readability of this book, But,
[00:09:01] Unknown:
I certainly the book some of the code examples would have been shorter without them. Let's let's say that for sure. And in terms of the primary subject matter that you're covering in the book, the title is classic computer science problems. So I'm curious how you define a problem as being classic. And also if you can give a bit of juxtaposition of computer science as opposed to just standard software development practices, and why a developer working in industry might find value out of learning more about some of these more theoretical and structured aspects of the concepts behind how computers work and mathematical models of programming.
[00:09:42] Unknown:
Absolutely. So let me go into the title a bit. So classic computer science problems in Python. It's a bit of a mouthful. When we say classic problems, what we really mean is the type of problems that somebody would see in a computer science undergraduate curriculum. So it doesn't mean you have to have seen these problems before. That's the whole point of the book, is is that maybe you don't have a computer science degree and you're a self taught programmer, and now you're getting, exposed to them for the first time and understanding why the ways that we solve them might be useful in your own code. But that was our that was our criteria for the book as a whole. It's we wanna have things that are in a typical undergraduate computer science curriculum. Whether you do that in the US or Australia or in Europe, wherever you you take computer science, these are problems you might have seen. And there's some there's some canonical classic examples that probably a lot of your listeners have heard of before, like the Towers of Hanoi or the 8 Queens problem or the knapsack problem. But we went beyond just the classics. We kinda bent the title a little bit to cover just topics that are interesting problem solving techniques that are not something that you're let's say you're a self taught programmer that you might have been exposed to. So let me go through a bit of the contents of the book. So and I'll I'll try to do this as briefly as possible, and it is a bit of a laundry list, but I'll try to be pretty brief about each 1. So we go through in the first chapter basic fundamentals you need like recursion, like manipulating bits directly, like what is a stack. These are kind of fundamental concepts you'd learn in an early programming course in college. Then in the second chapter, we do search algorithms, things like breadth for search, depth for search, and the a star algorithm that if you have something you're searching through, let's say it's a game and you want a player to be able to automatically walk from 1 side to the other side of the map, a star is the algorithm you you would use. It does for all of these topics, it's not that we expect the software developer in the future to write them themselves. They might use a library to do it, but they should at least know how the techniques work so they know which library to pull for. They should know what techniques are available to them in libraries.
In the 3rd chapter, we go into constraint satisfaction problems. That's something like a scheduling problem where you have 2 different people, let's say, 5 different people who need to find a time for a meeting, and so each of those people we would call a variable. The times that they're available, we'd call the domain. And the who needs to be at that meeting, that might be our constraint. And so can we write a solver for a problem like that? A solver that for any given set of variables, any given set of domains, and any set of constraints between them can automatically find a solution. In chapter 4, we do graph algorithms.
So graph algorithms, you can think about, like, transportation networks. So if I have this New York City subway system, how do I find the shortest amount of track I need to link up all the stations? Or how do I find the shortest path to get from 1 station to another? Graph algorithms are about taking real world problems, abstracting them away into nodes that have edges between them. In our subway system example, that would be, like, the stations and the routes between the stations. And how can we then use that abstract model to to solve the problem? In the 5th chapter, we go into genetic algorithms, that's literally using the idea of evolution in computing. So how do we solve a problem by modeling it using natural selection?
Pretty interesting. It has a bio a real biological basis. Chapter 6 is about k means clustering. This is I have a bunch of data and I wanna break it up into groups. We call those groups clusters. Can we can the computer really automatically figure out what are the logical groups that this data can be broken up into? Chapter 7 is on neural networks, and that's a huge topic right now, of course, being used for everything from image recognition to speech recognition. We don't get into such advanced neural networks in the chapter. We do a really simple 1, that that's a classification problem of, of wines and of flowers. So given some data of some flowers, can we automatically classify what kind of flower each bits of that data you probably represents?
So we we do a really simple example, and it gives you a really brief intro to this really large topic that hopefully just piques your interest to wanna explore it more. And chapter 8, we cover adversarial search. That's search for, like, a 2 player game, like chess or checkers or connect 4 is the 1 we do in the book. So how do you write an AI that will play checkers perfectly or near perfectly? And then in the last chapter, we discovered some miscellaneous problems that didn't really fit anywhere else, but there were also what we would call classic. So it's broad. It's a really broad book, and I'm sorry for the really long answer, but it's not a deep book. I should be clear about that. It's there's none in none of these topics do we get into a ton of mathematical depth, do we get into a ton of every single feature that you can do with this topic? It's a broad book. It gives you a taste of each of these topics and then you might wanna explore more. But the point is if to go back to your original question, if you're a software developer
[00:14:39] Unknown:
and you're not even familiar with these topics or these problem solving techniques, then you're missing out because there might be a problem that you come across in your day to day app development world that there's actually already a technique for solving and you just don't know about it. Yeah. That's generally a prime example of where somebody might just reach for a brute force approach that will work fine for a small set of data or a small set of cases. But as soon as the system starts to scale or it needs to start processing more nodes or more data, then everything starts to degrade in terms of performance and that's when it becomes much more of a difficult piece to maintain. And if you had the background understanding of where these different techniques might apply and how to identify which ones to pull from from your tool set as you're reaching these problems, then it definitely can greatly simplify and improve the quality of the software that you're producing as an engineer.
And this would actually be a good point too as well to specifically call out the target audience that you wrote the book for and the characteristics of
[00:15:48] Unknown:
how the book might play into their day to day work? Yeah. Absolutely. So I'd say there's about 3 different target audiences. First of all, before I even get into them, let me just say that I think any intermediate programmer can read the book. You don't need a lot of mathematical background to read the book. But the 3 main target audiences, 1 is professional programmers who kinda wanna refresh on these topics. So maybe you have a CS education, you haven't seen these topics in, like, 10 years, and you just wanna get back up to date or back prepared for, let's say, interview questions because, you know, a lot of these topics come out come up in interviews, but they might also help you in your day to day software development as we mentioned. The next group I'd say is self taught programmers.
So programmers who don't have a CS education and who never got exposed to these topics in the first place. This is supposed to be a really approachable broad book who which will introduce you to a lot of these topics in a short amount of time without you having to invest in a ton of prerequisite education. So any intermediate programmer who's self taught should be able to pick up the book and and pretty much read it. And then the last group would be computer science students. So I teach at a school that has a very applied computer science curriculum, so we're not very heavy on theory. And this book, I think, is great for students in programs like that, where, maybe a lot of the classes are more focused on software developments for your career rather than some of the theoretical basises of computer science.
And this is gonna give you some of that theory in a very approachable way. So I think those are our 3 different target audiences. I'd say probably the largest target audience, what I've been seeing from the reviewers, is the self taught programmers who were never exposed to these computer science topics,
[00:17:29] Unknown:
in a formal way. And another thing that I'll call out from the different categories of problems that you cover in the book is the graph problems and graph traversal issues. And in day to day software engineering, graphs are everywhere. And 1 of the most notable places is in dependency graphs for the software that you're building where you pull in 1 package, and then it has secondary dependencies and tertiary dependencies and just trying to figure out the resolution. And then that also gets into constraints where there are different version requirements. So having an understanding of how that package manager is actually determining which versions and which packages you need to install, and then being able to do some analysis of that, and then also how that plays out in your software of the dependency graphs of API calls and how it traverses various modules and then the external dependencies that you're pulling in, it can be very valuable just from understanding what's actually happening in the call stack of your program as it's being executed.
Absolutely. Couldn't agree with that more. I'll I'll admit that I haven't read through the book in its entirety. So I'm curious if as you're presenting these different problem types, such as the graph traversal algorithms or a star for search spaces, do you try to bring it into a typical type of problem that a, working programmer might encounter as part of their day to day so that they can have that more concrete link in their mind as to, oh, I'm running into this particular case of problem. So that means that I might want to look at these particular set of algorithms
[00:19:07] Unknown:
to help improve the efficacy of my program? So to be honest with you, because it's classic problems, a lot of these problems are kind of toy problems. So they're not necessarily although the techniques are applicable, of course, to real world problems, the actual problems that we solve in the book are mostly toy problems for illustrative purposes. That being said, at the end of every chapter, we have a section called real world examples, and we talk about how the problem solving techniques that you learned in that chapter are being applied in the real world for very serious problems. Like, you brought up a star. A star is often used in video games for figuring out the path for computer controlled, character to traverse the map.
So every chapter we point out something like that. We point out here's here's a real world application where this technique is being used, but the actual problems themselves for the most part are toy problems, which makes them easier to reason about and sometimes can make them a little bit more interesting. For example, you brought up the graph algorithms chapter, and I actually love that chapter because in that chapter, we go through Elon Musk's idea for the Hyperloop network across the United States. So we figure out, okay. If we wanted to build out the Hyperloop between all of the major cities in the United States, what algorithm can we use to figure out the least amount of track that we'd have to lay?
What algorithm can we use to figure out the least number of stops to get from, some major city to some other major city? So, yeah, I try to make some of the problems fun in the book so they're not just, like, the kind of grind that sometimes we find in software development. I think it's something that we're a little whimsical, and some of them, of course, are just classic. So, if there's a problem like the missionaries and cannibals, for example, that has been taught in CS curriculums for, like, a 100 years. Well, CS curriculums for 30 years, but in schools for a 100 years. We we always try to include problems when we knew that these were problems that are what people would think of as classic. And going back again to how the book appeals to the target audiences,
[00:21:11] Unknown:
the fact that it is using actual software as the language for communication makes it a lot more accessible because there have been a number of times where I pick up a book to try and dig into some algorithms practice or learn a bit more about some of these different CS fundamentals, and it's just throwing a lot of proofs and math. And that is generally a pretty quick turn off for a large number of people who aren't already wired to be thinking that way. So if software is already the language that you think in, then having the problems presented in that manner makes it much easier to be able to actually comprehend and gain value from a book written in that manner. Right. This book is extremely code centric,
[00:21:51] Unknown:
so we're constantly going through code from the beginning of the chapter to the end of the chapter. We are not trying to write a textbook here. So this is not a data structures and algorithms textbook, and that's 1 of the biggest misconceptions that people have when they they first hear about the book is they think, oh, this is gonna be like a data structures and algorithms textbook. It's not there's not almost any proofs in the whole book. There's minimal mathematical notation because, again, we wanted to make a broad book that was approachable to almost any intermediate programmer. So you need a very, very small mathematical background coming into the book. There are some chapters where you do need at least some basics. So, for example, for the k means chapter or the genetic algorithms chapter, you need to know some very basic things about statistics, like what is a standard deviation and how do you calculate an average. But those are things that most people saw in high school math, So not nothing too crazy.
I would say the most mathematically intense chapter is the neural networks chapter. It's chapter 7. We again try to make the math, as approachable as possible, but there is just a small amount of calculus that you have to know to be able to do back propagation when, building a neural network. So most readers, if you're if you're not interested in that, you can skip the chapter. If you don't know calculus that well, you can still probably read the chapter and kind of get the gist of how a neural network works, but that is only 1 out of 9 chapters, and I'd say the other 8 out of 9 chapters really require nothing beyond a high school mathematics background. And let me just add 1 more thing. You know, 1 of the reasons that people get turned off, I think, by data structures and algorithms textbooks, which again this is not, is they'd simply get bored. I mean, some of the topics in data structures and algorithms textbooks are so drawn out like sorting. Right? A data structures and algorithms textbook, almost always the first or second chapter is on sorting. And you you do sorting, like, 5 different ways. You do bubble sort, insertion sort, merge sort, quick sort, and you're just like, okay. I get it. Like, sorting, there's a lot of different ways to do it, and some are more efficient than others. And it's so drawn out, and it it turns people off like you said. So we we tried to make these chapters pretty succinct.
We tried to make the problems pretty engaging, and like I said, some of them are even whimsical. And we tried to really make the barrier to entry in terms of the math knowledge you need to get started minimal. Yeah. And for somebody who is looking for a textbook
[00:24:11] Unknown:
approach to data structures and algorithms, there is 1 that I read that was focused on Python as the, implementation language that was actually very to follow
[00:24:30] Unknown:
to follow. So I'll add a link to the 1 that I did enjoy into the show notes for anybody who's looking for that. Great. Yeah. Yeah. And I would just add to that also that, you know, I think that they vary quite a bit. So there are some data structures and algorithms textbooks that are just wonderfully written and there are some that, even though they're quite popular, are really not that accessible to somebody without a lot of time to study. And this book, Class of Computer Science Problems in Python, might be your entryway, your gateway to getting more interested in these topics and then wanting to pick up 1 of those books. But it's not I wanna emphasize to listeners again, it's not a data structures and algorithms textbook. And in terms
[00:25:08] Unknown:
of writing this book in Python, what are your favorite features of the language, and which of them did you learn as part of the process of writing the examples for this book and anything new that you came across that you didn't already have,
[00:25:24] Unknown:
experience in? Absolutely. So 1 of the things I've always loved about Python is how succinct it is. The same program in another language is almost always shorter in Python. And that's great when you're trying to illustrate algorithms because you take an algorithm and you have the pseudo code for it or you write out the steps in English, and then when you convert it into Python, it's almost just as readable. So I wouldn't say that it's not a super specific thing, but I'd say that the readability and succinctness of Python really made it a beautiful language for this book. When we were translating the book from Swift to Python, 1 of the most interesting things was actually how much code we could remove. And the reason for that is that Python standard library is just so much richer than Swift's standard library.
So on 1 hand, of course, we were trying to make the book as Pythonic as possible. So we were going through and we were doing some some of the problems we were writing completely from scratch, some of them we were we were reporting over from Swift. But on the other hand, we were just kinda surprised how little we actually had to write sometimes, which is because some of the things that we had to do by hand in the Swift book I'll give you an example. 1 example is permutation generation. So when you have an array, let's say, how do you or a list in Python. When you have a list in Python, how do you find all the different combinations of orderings for that list? There's really simple 1 liners from the standard library for doing that.
And in Swift, we had to write out, you know, a couple functions to do that, and we had to explain how all those functions work. And was that maybe useful in in of itself to explain how they work? Maybe. But that wasn't the focus of the chapter, and so there was a couple areas like that throughout the book where we could just eliminate significant sections of code because we were getting the answers for free from the standard library. In terms of what I had to learn as I was writing the book, like I said, I've been kinda in and out of the Python world for a decade now. When we decided to do the book, we and we put the team together, we had to make sure that we were being as up to date and Pythonic as possible, of course. And the big controversial decision, like I mentioned, was type ins. So that's what I had to spend a lot of time making sure I was really up to date on, was how do we do type hints properly in Python 3.7?
What have been the latest developments in type hints? And we used the type checker mypy to to check all the code in the book as we wrote it, and all of that was a great learning experience. I will say I think type hints in Python add value, that's why I use them, but I do think there's still some improvement to be made. And there are some PEPs that have just not yet been implemented that are gonna make type hints a little bit easier as as Python continues to evolve. But there are some parts of writing type hints today in Python that are just a little more complicated than they really need to be. Yeah. 1 of those in my view of how they how the type ins are currently
[00:28:14] Unknown:
accessible is the assignment operators for variable assignment where, at least up until recently, I can't remember if it made it into 3.7 or not, but you had to add the type hint as a code comment and then have mypy or whatever other type checker use that to determine what the variables type should be, aside from the being passed in as part of the function definition and using the function annotations for being able to specify those type ins. So being able to have the type assignment operators as part of the variable instantiation, I think, will definitely iron out a bit of the kinks in the Python type,
[00:28:55] Unknown:
in the Python typing story. Yes. And that actually has been fixed. So that that was something that was fixed in a very recent Python recent version of Python. Don't know if that was 3.6 or 3.7, but in 3.5, certainly, you did have to put it in a comment, which just seems like, okay. I'm typing my code, and then suddenly I have to put something about my code in the comment. Felt kinda weird, but they have fixed that. And
[00:29:16] Unknown:
in terms of people who have read your book and early reviewers, what have been some of the feedback as far as particular classes of problems that they have found to be most useful and most interesting and also those which they have found to be most difficult? Well, in terms of most useful, I've been a little surprised. I thought it would be 1 of the later chapters where people
[00:29:39] Unknown:
were just not familiar with the topic before, but it's actually been chapter 2 and chapter 3. Chapter 2 is on search, and chapter 3 is on constraint satisfaction problems. I thought these early chapters okay. Most reading people reading the book probably have seen this somewhere in their software development history, and so this will be a refresher for them. Maybe they'll learn something new about the topic, but probably the later topics will be the ones they're more excited about. But, actually, I've gotten a lot of feedback that those first few chapters have contained real insights and moments for people reading them. A lot of people apparently are not familiar with a star.
A star is such a useful algorithm. Anytime you need to search through a space, a star is probably gonna be your most efficient way of searching through it. And, so just reading those first few chapters has actually had the most positive feedback. But in terms of the most difficult chapter, it's definitely the neural networks chapter, and that's chapter 7. And, again, as we mentioned earlier, that's probably because of the mathematical background that you do need to to really understand that chapter completely. There's a lot of tutorials online that are like, let's write a neural network in Python in 13 lines of code, and I've even seen 1. I think I saw 1 that was 8 lines of code.
And, yeah, you can write, like, a really, really toy neural network in 8 or 13 lines of code using NumPy. But what we wanted to do was write, let's say, a little bit more than that, a couple hundred lines of code, but really illustrate how a neural network works instead of use some, some tricks to to hide that and do it in as few lines of code as possible. So it is kind of, it's the most intense chapter. It's the most mathematical chapter, but it will definitely give you more of an insight into how new neural networks work than 1 of those
[00:31:26] Unknown:
writing neural network in 10 lines of code tutorials. And for practicing software engineers or anybody who plans to work in in the industry, particularly going into the near to midterm future, that's definitely information that will become increasingly valuable because artificial intelligence and machine learning are starting to creep into a large majority of software projects, whether it's via being consumed as an API or being incorporated as part of the software system that you're building and deploying or being part of just, you know, just general understanding of how these types of systems are working. So AI and machine learning definitely aren't going away, and they're just becoming increasingly popular and relevant and necessary for somebody who is working in software and wants to be able to continue to improve and progress in their career.
[00:32:19] Unknown:
Absolutely. And, you know, it's not like you're gonna read this book and then you're gonna implement your own neural network from scratch, and that's true for any of the topics. It's not like you're gonna go and and write 1 of these techniques from scratch in your project. You're more likely gonna use an off the shelf library. If you're doing neural networks, you're probably gonna use something like PyTorch. You're not probably gonna go write your own neural network. In fact, I would advise you not to do that, that'd be a very bad idea to write your own neural network, but you need to know when that problem solving technique is applicable to the problem that you have at hand. And so reading this book will give you an understanding of how these techniques work and what classes of problems you can use them to solve, and that's really the value here. It's not that you're gonna go write your own version of scikit learn or of PyTorch.
It's that you're gonna know what when to use scikit learn and when to use a certain algorithm from scikit learn. And you are by actually because we implement everything from scratch, you're gonna actually understand a little bit about how scikit learn works.
[00:33:19] Unknown:
And what the limitations are as well because particularly with a lot of the hype around machine learning and AI, it's easy to think, oh, I just throw this out of problem and everything will magically be solved, where if you are getting a more fundamental view of how these neural networks and the topologies are built and how the data propagates through them, you can get a much more intuitive sense of what it's actually capable
[00:33:44] Unknown:
of and what it's not capable of so that you know when to reach for a different tool. Absolutely. I I mean and that's 1 of the fundamental problems we have right now is that there's a lot of hype and people kinda think you can throw a certain technique just at any kind of problem, and that's, of course, not the case. And hopefully, this book will give you some insight into when the technique actually is appropriate.
[00:34:06] Unknown:
And so as far as some of the other topics in the book, I don't know if you want to dig a bit more into some of the specifics of things like adversarial search and some of the,
[00:34:18] Unknown:
genetic algorithms and use cases for both of those different classes of problem? Sure. So let's talk about adversarial search a bit. So that's covered in chapter 8 of the book, and what we do in that chapter is we build an AI that can play tic tac toe, and then we build an AI that can play connect 4. So we go from a very simple game to a slightly more complex game. We use an algorithm in that chapter called minimax, and minimax has kind of been the de facto algorithm for implementing board game AIs since the 19 fifties.
And what's cool about it is we use the same exact algorithm for both Tic Tac Toe and Connect 4, and you could plug that algorithm into a game of checkers or a game of chess, and it can, with a couple modifications, work just as well pretty much. So you really start to understand how does a computer play chess? How does a computer play connect for? How does a computer play tic tac toe? And it's simpler than you might think. So I think people who read that chapter might be a little surprised. Now in really recent times, we're talking just the last year or 2, there started to be machine learning type approaches that have started to surpass minimax in games like Go and chess.
But, still the majority of chess engines and board game AIs are implemented using minimax. And so it's it's a really fun 1 to learn. Couple of the others you mentioned, genetic algorithms. That's 1 that people are kinda like, that sounds weird, right? How are we gonna use genetics when we when we're writing an algorithm? Well, the idea is what if we take different solutions to the problem and we've kind of put them into a natural selection type of environment where the solutions that seem a little better to the problem, we're gonna let we're gonna evolve them a little bit by making slight modifications to how they solve the problem, and then we'll let them have children. We might cross over a couple of the different solutions, combine some aspects of each of them, and have some new potential solutions, and then do the same thing over and over again. And over time, we see how close do we get to a solution or do we get close to a solution.
The surprising thing is they can actually work for a large number of problems, but it's usually not the first technique you reach for. So genetic algorithms are something you reach for when nothing else that you've tried really will work because, fundamentally, like in real evolution, there's a bit of randomness. Right? When you do a mutation to a gene in the real world, right, you don't know what's what that mutation is gonna cause. Well, when you make a random change to a potential solution to a programming problem, you don't know if that's gonna be a positive mutation or a negative mutation. So because there's some randomness, it's not certain that a genetic algorithm will ever solve any particular problem.
But, if you can't run out of ideas and you can't think of another way to solve the problem, a genetic algorithm might be a decent approach to try. You also mentioned what we cover in chapter 3, which is constraint satisfaction problems, and that is let let me give you a couple of the problems we we actually solve in that chapter because there's a few really classic ones that people have some some people probably heard of and other people will say, you know, that that sounds like a pretty easy thing to understand. So one's the Australian map coloring problem. You have the regions of Australia on a map and you don't want any 2 regions that are next to each other to be painted on the map with the same color.
Well, in terms of how we formulate that as a constraint satisfaction problem, we say the variables are the regions of Australia, so we call each of the regions a variable. And we say the domains of those variables, so what are the possible answers? In other words, what are the possible right values for those variables are the colors, so what colors can we paint each region? And then the constraint is that any region that's next to another region can't have the same color. Well, we write a solver that doesn't specifically know any of that knowledge. All it knows is how to solve a constraint satisfaction problem and it can solve that problem and it can solve several other problems that also have variables, domains, and constraints. I'll give you 2 other examples.
Another classic one's the 8 queens problem. If I have a chessboard and I wanna put 8 different queens on the chessboard, where can I place them so that no 2 queens are attacking each other? The variables are the queens. What are their positions on the chessboard? The domains are the possible positions, of each of those queens. And the constraint is that no 2 queens can be attacking 1 another when they're placed. Last 1 I'll give you, send more money. Another classic problem that, you might have heard a lot of listeners might have heard about. You have, it's called a cryptorhythmic tick problem because we have the words send and more lined up with 1 another. So it's like an addition problem where you've send on the first line, more on the second line, and money on the third line. So money is the the equal sign. Right? The solution to adding the word send plus more. Each of the letters represents a digit. So at the beginning of the problem, you don't know what any of those digits are, but anytime you see an e, maybe that represents a 4. Every time you see a s, maybe that represents a 9, whatever it is. And can we use again a constraint satisfaction problem solver to solve that problem? The answer is yes. The variables are the various different letters. The domains are the digits 0 through 9 that each of the the letters could represent. And the constraint is that when I fill in a, domain value for each of the variables that the equation send plus more equals money comes up with a solution, that's correct mathematically.
So there's 3 totally different problems, but here we have a technique, constraint satisfaction problem solving, that can solve any of them without the algorithm that we write for that technique having to know anything about any of the specific problems. So people find that pretty interesting. And another
[00:40:03] Unknown:
constraint problem that a lot of people have probably encountered is in the realm of scheduling, whether that's people or computational resources, particularly with the rise of popularity of Kubernetes and being able to schedule workloads across multiple instances where each set of services has a particular range of requirements in terms of compute capacity, storage, memory, and you just have these pool of resources that's not necessarily evenly broken up across the different instances that Kubernetes is managing. So that's another area where being able to solve for constraints would be useful.
[00:40:38] Unknown:
Absolutely. And I'll give you an even simpler scheduling constraint satisfaction problem. Every time you go in Google Calendar and you look at your colleagues and you say, yes, Google Calendar, please find the next available meeting slot for me to have with with these specific colleagues. That's a constraint satisfaction
[00:40:54] Unknown:
problem, in scheduling. And so for anybody who wants to dig deeper into any of these problem areas and computer science techniques in general, what are some of the resources that you would recommend? So after you get a taste of these computer science topics from
[00:41:12] Unknown:
classic computer science problems in Python, you might want to get a more formal introduction to them because, again, we don't cover a lot of the math and we don't cover some of the proofs. So you might wanna check out a textbook. Some of the textbooks are really good. The most definitive textbook that everyone will say, this is like the classic book in this area, It's called introduction to algorithms, and it's so definitive. People don't even refer to the authors by their full names, just by the acronym, CLRS. So if you ever see that in a, forum post or on Hacker News or something, CLRS refers to this book called introduction to algorithms. It's a really, really great reference.
A more approachable book is Algorithms by Robert Sedgwick and Kevin Wayne, and it's often used in college courses to teach algorithms. It is unfortunately in Java, but it I still think it's a really easy book to read even if you don't have a lot of Java background. There are some Python specific algorithms books. I'm not as familiar with them. But, Tobias, maybe you said earlier that there's 1 or 2 that that you recommend, so maybe we come back to that. But, for the artificial intelligence side of the equation, the most definitive textbook on that is called Artificial Intelligence, A Modern Approach, and it is used in college classrooms around the world.
Again, it's a great reference if you want something a little bit more approachable, there's a book called Artificial Intelligence in the 21st Century. It's by Steven Lucci, and actually my late father, Danny Kopec, has written a few years ago, and it's just a little more readable. And then the last thing I'll recommend is the Khan Academy algorithms course. It's actually by Tom Corman and Devin Balcom, 2 professors I had at Dartmouth when I was in, graduate school. And I think it's a really great course for people who have no prior experience in algorithms. It it will teach you what is big o notation, which maybe you've heard about and you were puzzled by.
It'll teach you some of the fundamental techniques you need to analyze algorithms, and you'll actually implement them live while you do the course. So it's pretty interactive as well. So I think all of those are great next steps after class computer science problems in Python.
[00:43:13] Unknown:
Yeah. And as you mentioned, I do have a specific textbook that I can recommend. I don't have the title handy at the top of my mind, so I'll add it to the show notes for anybody who's curious. And are there any other aspects of your work on this book or your experience with teaching computer science or just some general advice for people who are getting into this area either as a refresher or as a new entrant that you would like to discuss further before we close out the show?
[00:43:41] Unknown:
Well, I'll I'll mention 3 things. 1 is if you read the book, absolutely download the source code from the GitHub repository that goes with the book. There's no reason to not have that code ready to run and so that you can play around with it as you're reading. Number 2 is I think it's great to contribute to open source projects related to these areas even if you don't have a ton of experience. There's a lot of GitHub repositories that are solutions to classic algorithm problems, and there's I've seen several of them in Python. I think trying to make a contribution to to 1 of those repositories is gonna force you to think algorithmically.
And, also, it's gonna look good on your GitHub profile, so why not? And the last thing I'll say is just teaching these topics over the last few years at the college level, it's okay if they don't make sense the first time. If you read 1 of these chapters, especially, let's say, a hard 1 like the neural networks chapter. Right? And the first time you read through it, you kinda sorta understand the gist of parts of it, but parts of it don't make sense the first time you read it, that's totally okay. It's not supposed to be something where you see it once and then, okay. Now I know how to use this problem solving technique perfectly.
Each of these techniques takes practice actually using it on actual problems to really understand. And so my last piece of advice would really be just to code. Don't just read code. I mean and that doesn't just mean necessarily just code the solutions in the book as you read. Try coding your own solutions to your own problems that use these techniques.
[00:45:09] Unknown:
That's the way you really learn them. Right. Well, for anybody who wants to get in touch with you and follow the work that you're up to, I'll have you add your preferred contact information to the show notes. And for anybody who's interested, there will be a 40% off discount giveaway so that there will be 4 copies available for people to enter into and, get a free copy. So I'll have details for that in the show notes as well. And so with that, I'll move us into the pics. And this week, I'm going to choose a WordPress plugin that I've been using recently to redesign the site called Elementor, which makes it very easy to have a nice drag and drop interface for just dropping different component blocks onto the site because, well, I'm perfectly happy writing Python code in the back end. I am not a front end designer, so this makes it easy for me to put together a site that actually looks nice and is functional. So, definitely worth checking out if you're running WordPress anywhere. And so with that, I'll pass it to you, David. Do you have any picks this week? I've got a couple picks. 1 is the website nestev.com,
[00:46:16] Unknown:
n e s dev.com. Recently, I got interested in implementing a Nintendo Entertainment System Emulator, and this site just has so many resources for anyone interested in doing that. And the people there are so friendly. Their forums, I mean, they helped me out so much as I was writing the emulator, and it couldn't be a nicer group of folks who really know their stuff. The other 1 is I love the TV show The Curse of Oak Island, and I don't want it to go off the air. So everyone should watch The Curse of Oak Island on the History Channel. Alright. Well, thank you very much for taking the time today to talk about your work on the book and your experience
[00:46:51] Unknown:
of helping to educate people on computer science problems. So thank you for that. I look forward to reading the book on my own, and I hope you enjoy the rest of your day. Thanks so much for having me, Tobias.
Introduction and Guest Introduction
Transition from Swift to Python
Motivation for Writing the Book
Python 3.7 Features and Type Hints
Defining Classic Computer Science Problems
Target Audience for the Book
Real World Applications of Algorithms
Python Features and Learning Experiences
Feedback from Early Reviewers
Adversarial Search and Genetic Algorithms
Constraint Satisfaction Problems
Further Resources and Recommendations
Final Advice and Closing Remarks