ENSPIRING.ai: Unveiling the Power of Algorithms: From Basics to Mastery
The video begins with an explanation of the fundamental elements of computer science by Professor David J. Malan from Harvard University, focusing on how Algorithms provide structured solutions to problems. It uses relatable day-to-day examples like making peanut butter sandwiches to explain simple Algorithms in a way that is understandable to audiences without a computer science background. Professor Malan illustrates Algorithms' significance, showing that from routines like making lunches to complex tasks like computer programming, everything involves a sequence of instructions, thus emphasizing the role of precision in crafting effective Algorithms.
The discussion progresses to intermediate and advanced concepts through interactive segments with various students, illustrating methods such as sorting and searching within Algorithms. Demonstrations include exploring the efficiency of bubble sort and binary search, enabling viewers to grasp how Algorithms optimize tasks by dividing them into manageable steps. Through hands-on examples, the video bridges practical and technical aspects, explaining clearly how Algorithms operate within both digital and physical realms, influencing social media recommendations, search engine outputs, and everyday technologies.
Main takeaways from the video:
Please remember to turn on the CC button to view the subtitles.
Key Vocabularies and Common Phrases:
1. Algorithm [ˈælgəˌrɪðəm] - (n.) a set of rules or steps to solve a problem or execute a task.
Algorithm is a list of instructions to tell people what to do, or like a robot what to do.
2. Precision [prɪˈsɪʒən] - (n.) the quality of being exact and accurate.
Precision. Being very, very correct with your instructions is so important in the real world.
3. Recursive [rɪˈkɜːrsɪv] - (adj.) relating to a process that repeats using its own output as input.
Recursive algorithm is essentially an algorithm that uses itself to solve the exact same problem again and again.
4. Optimization [ˌɒptɪmaɪˈzeɪʃən] - (n.) the action of making the best or most effective use of resources.
The role of the algorithm is the optimization algorithm that helps you find the best model or the best description of a data set.
5. Inefficient [ˌɪnɪˈfɪʃənt] - (adj.) not achieving maximum productivity; failing to make the best use of resources.
Because that would be a crazy long list when you're just trying to search the data.
6. Neural networks [ˈnʊrəl ˈnetwɜːrks] - (n.) computing systems inspired by biological neural systems that are designed to recognize patterns.
...topics like Neural networks and Machine learning, which really describe taking as input things like what you watch.
7. Machine learning [məˈʃiːn ˈlɜːrnɪŋ] - (n.) a type of artificial intelligence where computers evolve behavior based on data received.
...like alpha Zero, for example, or Alpha Star. Or there are a lot of, you know, like, fancy new Machine learning agent.
8. Computational [ˌkɒmpjuˈteɪʃənəl] - (adj.) related to the use of computers for processing information.
...Artificially intelligent, if I may, because presumably there's not someone at TikTok or any of these social media companies...
9. Deterministic [ˌdɪtɜːrmɪˈnɪstɪk] - (adj.) processes that are predictable and determined by pre-existing conditions.
When these Algorithms were more deterministic and more procedural...
10. Alchemy [ˈælkəmi] - (n.) a seemingly magical process of transformation or creation.
Large language models is still in the point of what might be called alchemy...
Unveiling the Power of Algorithms: From Basics to Mastery
Hello, world. My name is David J. Malan, and I'm a professor of computer science at Harvard University. Today, I've been asked to explain Algorithms in five levels of increasing difficulty. Algorithms are important because they really are everywhere, not only in the physical world, but certainly in the virtual world as well. And in fact, what excites me about Algorithms is that they really represent an opportunity to solve problems. And I dare say, no matter what you do in life, all of us have problems to solve.
So I'm a computer science professor, so I spend a lot of time with computers. How would you define a computer for them? Well, a computer is electronic, like a phone, but it's a rectangle, and you like, kid type, like, tick, tick, tick, and you work on it. Nice. Do you know any of the parts that are inside of a computer? Um, no. Can I explain a couple of them to you? Yeah. So, like, inside of every computer is some kind of brain, and the technical term for that is cpu or central processing unit.
And those are the pieces of hardware that know how to respond to those instructions, like moving up or down or left or right. Knows how to do math, like addition and subtraction. And then there's at least one other type of hardware inside of a computer called memory, or ram, if you've heard of this. I know memory because you have to memorize stuff. Yeah, exactly. And computers have even different types of memory. They have what's called ramdhenne, random access memory, which is where your games, where your programs are stored while they're being used.
But then it also has a hard drive or a solid state drive, which is where your data, your high scores, your documents. Once you start writing essays and stories in the future, it stays permanently. Stays permanently. So even if the power goes out, the computer can still remember that information. It's still there because the computer can't just delete all the words itself. Hopefully not, because your fingers could only do that. You have to use. Use your finger to delete all the stuff. Exactly.
Have you heard of an algorithm before? Yes. Algorithm is a list of instructions to tell people what to do, or like a robot what to do. Yeah, exactly. It's so just step by step instructions for doing something, for solving a problem, for instance. Yeah. So, like, if you have a bedtime routine, then at first you say, I get dressed, I brush my teeth, I read a little story, and then I go to bed. All right, well, how about another algorithm? Like, what do you tend to eat for lunch? Any types of sandwiches you like? I eat peanut butter.
Let me get some supplies from the cupboard here. So, should we make an algorithm together? Yeah, why don't we do it this way? Why don't we pretend like I'm a computer or maybe I'm a robot, so I only understand your instructions, and so I want you to feed me, no pun intended, an algorithm. So step by step instructions for solving this problem. But remember, Algorithms, you have to be Precise. You have to give the right instructions. The right instructions. Just do it for me.
So, step one was what? Open the bag. Okay. Opening the bag of bread. Stop. Grab the bread and put it on the plate. Grab the bread and put it on the plate. Take all the bread back and put it back in there. So that's like an undo command, little control z. Okay, take one bread and put it on the plate. Take the lid off the peanut butter. Okay. Take the lid off the peanut butter. Put the lid down. Okay. Take the knife. Take the knife.
Put the blade inside the peanut butter, and spread the peanut butter on the bread. I'm gonna take out some peanut butter, and I'm gonna spread the peanut butter on the bread. I put a lot of peanut butter on because I love peanut butter. Oh, apparently. I thought I was messing with you here, but I think you're fine, apparently happy with this. Put the knife down, and then grab one bread and put it on top of the second bread. Sideways. Sideways. Like, put it flat. Flat ways. Okay. And now done. You're done with your sandwich. Should we take a delicious bite? Yep, let's take a bite. Okay. Here we go.
What would be the next step? Be here. Clean all this mess up. Clean all this mess up. Right. We made an algorithm, step by step instructions for solving some problem. And if you think about now how we made peanut butter and jelly sandwiches, sometimes we were imprecise. You didn't give me quite enough information to do the algorithm correctly, and that's why I took out so much bread. Precision. Being very, very correct with your instructions is so important in the real world, because, for instance, when you're using the World Wide Web and you're searching for something on Google or bing, you want to do the right thing. Exactly.
So, like, if you type in just Google, then you won't find the answer to your question. Pretty much everything we do in life is an algorithm, even if we don't use that fancy word to describe it. Because you and I are sort of following instructions, either that we came up with ourselves or maybe our parents told us how to do these things. And so those are just Algorithms. But when you start using Algorithms in computers. That's when you start writing code. What do you know about Algorithms? Nothing really, at all, honestly. I think it's just probably a way to store information in computers.
And I dare say, even though you might not have put this word on it, odds are you executed as a human. Multiple Algorithms today. Even before you came here today, what were a few things that you did? I got ready. Okay, and get ready. What does that mean? Brushing my teeth, brushing my hair, getting dressed. Okay. So all of those, frankly, if we really dove more deeply, could be broken down into step by step instructions. And presumably your mom, your dad, someone in the past sort of programmed you as a human to know what to do. And then after that, as a smart human, you can sort of take it from there and you don't need their help anymore.
But that's kind of what we're doing when we program computers. Something maybe even more familiar nowadays. Like, odds are you have of a cell phone, your contacts, or your address book. But let me ask you why that is. Like, why does Apple or Google or anyone else bother alphabetizing your contacts? I just assumed it would be easier to navigate. What if your friend happened to be at the very bottom of this randomly organized list? Like, why is that a problem? Like, he or she is still there. I guess it would take a while to get to while you're scrolling.
That in of itself is kind of a problem, or it's an inefficient solution to the problem. So it turns out that back in my day, before there were cell phones, everyone's numbers from high schools were literally printed in a book. And everyone in my town and my city, my state, was printed in an actual phone book. Even if you've never seen this technology before, how would you propose verbally to find John in this phone book? I would just flip through and just look for the j's, I guess.
Yeah. So let me propose that we start that way. I could just start at the beginning, and step by step, I could just look at each page. Looking for John. Looking for John. Now, even if you've never seen this here technology before, it turns out this is exactly what your phone could be doing in software. Like someone from Google or Apple or the like, they could write software that uses a technique in programming known as a loop. And a loop, as the word implies, is just sort of do something again and again, what if, instead of starting from the beginning and going one page at a time, what if I.
Or what if your phone goes like two pages or two names at a time would this be correct, do you think? Well, you could skip over John, I think. In what sense? If he's in one of the middle pages that you skipped over. Yeah. So sort of accidentally and frankly, with like 50 50 probability, John could get sandwiched in between two pages. But does that mean I have to throw that algorithm out altogether? Maybe you could use that strategy until you get close to the section and then switch to going one by one. Okay, that's nice. So you could kind of like go twice as fast, but then kind of pump the brakes as you near your exit on the highway, or in this case near the j section of the book.
And maybe alternatively, if I get to like a, b, c, d, e, f, g, h, I, j, k. If I get to the k section, then I could just double back like one page just to make sure John didn't get sandwiched between those pages. So the nice thing about that second algorithm is that I'm flying through the phone book like two pages at a time. So, two, four, 6810, twelve. It's not perfect, it's not necessarily correct, but it is if I just take like one extra step. So I think it's fixable.
But what your phone is probably doing, and frankly, what I, and like my parents and grandparents used to do back in the day, is we'd probably go roughly to the middle of the phone book here. And just intuitively, if this is an alphabetized phone book in English, what section am I probably going to find myself in? Roughly? Okay, so I'm in the k section. Is John gonna be to the left or to the right? Yeah.
So John is gonna be to the left or the right. And what we can do here, though your phone does something smarter, is tear the problem in half, throw half of the problem away. Being left with just 500 pages now. But what might I next do? I could sort of naively just start at the beginning again. But we've learned to do better. I can go roughly to the middle here and then do it again.
Yeah, exactly. So now maybe I'm in the e section, which is a little to the left. So John is clearly going to be to the right. So I can again tear the problem poorly in half, throw this half of the problem away. And I claim now that if we started with 1000 pages, now we've gone to 500, 250, now we're really moving quickly. And so eventually I'm hopefully dramatically left with just one single page, at which point John is either on that page or not on that page. And I can call him roughly how many steps might this third algorithm take if I started with 1000 pages, then went to 500, 200, and 5125?
Like, how many times can you divide 1000 in half? Maybe ten? That's roughly ten, because in the first algorithm, looking again for someone like Zoe, in the worst case, might have to go all the way through 1000 pages. But the second algorithm, you said was 500, maybe 501, essentially the same thing, so twice as fast. But this third and final algorithm is sort of fundamentally faster because you're sort of dividing and conquering it in half, in half and half, not just taking one or two bytes out of it at a time.
So this, of course, is not how we used to use phone books back in the day, since otherwise they'd be single use only. But it is how your phone is actually searching for Zoe, for John, for anyone else, but it's doing it in software. Oh, that's cool. So here we happen to focus on searching Algorithms, looking for John in the phone book. But the technique we just used can indeed be called divide and conquer, where you take a big problem and you divide and conquer. That is, you try to chop it up into smaller, smaller, smaller pieces, a more sophisticated type of algorithm, at least depending on how you implement it, something known as a Recursive algorithm.
Recursive algorithm is essentially an algorithm that uses itself to solve the exact same problem again and again, but chops it smaller and smaller and smaller, ultimately. Hi, my name is Patricia. Patricia, nice to meet you. Where are you a student at? I'm starting my senior year now at NYU. Oh, nice. And what have you been studying the past few years? I studied computer science, data science. If you were chatting with a non cs, non data science friend of yours, how would you explain to them what an algorithm is?
Some kind of systematic way of solving a problem, or a set of steps to solve a certain problem you have. So you probably recall learning topics like binary search versus linear search and the like. So I've come here complete with a actual chalkboard with some magnetic numbers on it here. Like, how would you tell a friend to sort these? I think one of the first things we learned was something called bubble sort. It was kind of like focusing on, like, smaller, like, bubbles, I guess I would say, like, of the problem, like, looking at, like, smaller segments rather than, like, the whole thing at once.
What is, I think, very true about what you're hinting at is that bubble sort really focuses on, like, local small problems. Rather than taking a step back, trying to fix the whole thing, let's just fix the obvious problems in front of us. So, for instance, when we're trying to get from smallest to largest, and the first two things we see are eight followed by one. This looks like a problem. Cause it's out of order. So what would be the simplest? Fix the least amount of work we can do to at least fix one problem. Just like, switch those two numbers.
Cause one is obviously smaller than eight. Perfect. So we just swap those two. Then you would switch those again. Yeah. So that further improves the situation. And you can kind of see it that the one and the two are now in place. How about eight and six? Switch it again. Switch those again. Eight and three, switch it again. And conversely, now the one and the two are closer to, and coincidentally, are exactly where we want them to be.
So, are we done? No. Okay, so obviously not. But what could we do now to further improve the situation? Go through it again. But you don't need to check the last one anymore because we know that number is bubbled up to the top. Yeah, because eight has indeed bubbled all the way to the top. So, one and two, yeah, keep it as is.
Okay. Two and six, keep it as is. Okay. Six and three, then you switch it. Okay, we'll switch or swap those. Six and four, swap it again. Okay, so, four and six and seven, keep it. Okay. Seven and five, swap it. Okay. And then I think, per your point, we're pretty darn close. Let's go through once more. One and two, keep it. Two, three, keep it.
Three, four, keep it. Four, six, keep it. Six, five, and then switch it. All right, we'll switch this. And now, to your point, we don't need to bother with the ones that already bubbled their way up. Now, we are 100% sure it's sorted. Yeah. And certainly the search engines of the world, Google and Bing and so forth, they probably don't keep web pages in sorted order, because that would be a crazy long list when you're just trying to search the data. But there's probably some algorithm underlying what they do, and they probably similarly, just like we do a bit of work upfront to get things organized, even if it's not strictly sorted in the same way, so that people like you and me and others can find that same information.
So how about social media? Can you envision where the Algorithms are in that world? Like, maybe, for example, TikTok, the for you page? It's kind of like. Cause those are recommendations, right? It's sort of like Netflix recommendations, except more constant, because it's just like every video you scroll, it's like that's a new recommendation, basically, and it's based on what you've liked previously, what you've saved previously, what you search up. So I would assume there's some kind of algorithm there, kind of figuring out what to put on your for you page.
Absolutely. Just trying to keep you presumably more engaged. So the better the algorithm is, the better your engagement is. Maybe the more money the company then makes on the platform and so forth. So it all sort of feeds together. But what you're describing really is more Artificially intelligent, if I may, because presumably there's not someone at TikTok or any of these social media companies saying, if Patricia likes this post, then show her this post. If she likes this post, then show her this other post.
Because the code would sort of grow infinitely long, and there's just way too much content for a programmer to be having those kinds of unconditionals, those decisions being made behind the scenes. So it's probably a little more Artificially intelligent. And in that sense, you have topics like Neural networks and Machine learning, which really describe taking as input things like what you watch, what you click on, what your friends watch, what they click on, and sort of trying to infer from that instead. What should we show Patricia or her friends next? Okay. Yeah, that makes the distinction more, makes more sense now.
Yeah. I am currently a fourth year PhD student at NYU. I do robot learning. So that's half and half. Robotics and Machine learning. Sounds like you've dabbled with quite a few Algorithms. So how does one actually research Algorithms or invent Algorithms? The most important was just trying to think about Inefficiencies and also think about connecting threads. The way I think about it is that algorithm, for me, is not just about the way of doing something, but it's about doing something efficiently. Learning Algorithms are practically everywhere now.
Google, I would say, for example, is learning every day about, like, oh, what articles, what links might be better than others and re ranking them. There are Recommender systems all around us, right? Like content feeds and social media or, you know, like YouTube or Netflix. What we see is in a large part determined by this kind of learning algorithm. Nowadays, there's a lot of concerns around some applications of Machine learning and like deepfakes, where it can kind of learn how I talk and learn how you talk, and even how we look and generate videos of us.
We're doing this for real. But you could imagine a computer synthesizing this conversation eventually. But how does it even know what I sound like and what I look like and how to replicate that. All of this learning Algorithms that we talk about, right? A lot, like, what goes in there is just lots and lots of data. So data goes in, something else comes out. What comes out is whatever objective function that you optimize for. Like, where's the line between Algorithms that, like, play games with and without AI?
I think when I started off my undergrad, the current AI Machine learning was not very much synonymous. And even in my undergraduate in the AI class, they learned a lot of classical Algorithms for gameplays. Like, for example, the eight star search, right? That's a very simple example of how you can play a game without having anything learned. This is very much, oh, you are at a game state. You just search down, see what are the possibilities, and then you pick the best possibility that it can see versus what you think about when you think about Arya's gameplay. Like the alpha Zero, for example, or Alpha Star.
Or there are a lot of, you know, like, fancy new Machine learning agent I that are even, like, learning very difficult games like go. And those are learned agents, as in, they are getting better as they play more and more games. And as they get more games, they kind of refine their strategy based on the data that I've seen. And once again, this high level abstraction is still the same. You see a lot of data, and you'll learn from that. But the question is, what is objective function that you're optimizing for? Is it winning this game? Is it forcing a tie? Or is it like opening a door in a kitchen?
So, if the world is very much focused on supervised, unsupervised reinforcement learning, now, like, what comes next? 510 years? Where's the world going? I think that this is just gonna be more and more. I don't want to use the word encroachment, but that's what it feels like of Algorithms into our everyday life. Like, even when I was taking the train here, right, the trains are being routed with Algorithms, but this has existed for, you know, like, 50 years probably.
But as I was coming here, as I was checking my phone, those are different Algorithms. And, you know, they're kind of getting all around us, getting there with us all the time. They're making our life better most places, most cases. And I think that's just going to be a continuation of all of those. And it feels like they're even in places you wouldn't expect. And there's just so much data about you and me and everyone else online. And this data is being mined and analyzed and influencing things we see in here.
It would seem so. There is sort of a counterpoint, which might be good for the marketers, but not necessarily good for you and me. As individuals, we're human beings, but for someone, we might be just a pair of eyes who are carrying a wallet and are there to buy things. But there is so much more potential for this Algorithms to just make our life better without changing much about our life. I'm Chris Wiggins. I'm an associate professor of applied mathematics at Columbia.
I'm also the chief data scientist of the New York Times. The data science team at the New York Times develops and deploys Machine learning for newsroom and business problems. But I would say the things that we do mostly, you don't see, but it might be things like personalization Algorithms or recommending different content. And do data scientists, which is rather distinct from the phrase computer scientist, do data scientists still think in terms of Algorithms as dry magic? A lot of it? Oh, absolutely, yeah. In fact. So, in data science and academia, often the role of the algorithm is the optimization algorithm that helps you find the best model or the best description of a data set.
In data science and industry, the goal often is centered around an algorithm, which becomes a data product. So a data scientist in industry might be developing and deploying the algorithm, which means not only understanding the algorithm and its statistical performance, but also all of the software engineering around systems integration, making sure that that algorithm receives input that's reliable and has output that's useful, as well as, I would say, the organizational integration, which is, how does a community of people, like the set of people working at the New York Times, integrate that algorithm into their process?
Interesting. And I feel like AI based startups are all the rage, and certainly within academia, are there connections between AI and the world of data science and the Algorithms that they're in? Can you connect those dots? For you're right, that AI is a field has really exploded. I would say particularly many people experienced a chatbot that was really, really good. Today, when people say AI, they're often thinking about Large language models, or they're thinking about generative AI, or they might be thinking about a chatbot.
One thing to keep in mind is a chatbot is a special case of generative AI, which is a special case of using Large language models, which is a special case of using Machine learning generally, which is what most people mean by AI. You may have moments that are what John McCarthy called look ma no hands results, where you do some fantastic trick and you're not quite sure how it worked. I think it's still very much early days, Large language models is still in the point of what might be called alchemy, and that people are building Large language models without a real clear, a priori sense of what the right design is for a right problem.
Many people are trying different things out, often in large companies, where they can afford to have many people trying things out, seeing what works, publishing that, instantiating it as a product, and that itself is part of the scientific process, I would think, too, yeah, very much. Well, science and engineering, because often you're building a thing and the thing does something amazing. To large extent, we are still looking for basic theoretical results around why deep Neural networks generally work. Why are they able to learn so well? They're huge, billions of parameter models, and it's difficult for us to interpret how they are able to do what they do.
And is this a good thing, do you think, or an inevitable thing, that we the programmers, we the computer scientists, the data scientists who are inventing these things can't actually explain how they work? Because I feel like friends of mine in industry, even when it's something simple and relatively familiar, like autocomplete, they can't actually tell me, like, why that name is appearing at the top of the list. Whereas years ago, when these Algorithms were more deterministic and more procedural, you could even point to the line that made that name bubble up to the top.
So is this a good thing, a bad thing, that we're sort of losing control? Perhaps in some sense, of the Algorithms, it has risks. I don't know that I would say that it's good or bad, but I would say there's lots of scientific precedent. There are times when an algorithm works really well and we have finite understanding of why it works, or a model works really well, and sometimes we have very little understanding of why it works the way it does. And classes I teach certainly spend a lot of time on fundamentals, Algorithms that have been taught in classes for decades now, whether, whether it's binary search, linear search, bubble sort, selection sort, or the like.
But if we're already at the point where I can pull up chat GPT, copy paste a whole bunch of numbers or words and say, sort these for me, does it really matter how chat GPT is sorting it? Does it really matter to me, as the user, how the software is sorting it? Like, do these fundamentals become more dated and less important, do you think? Now you're talking about the ways in which code and computation is special case of technology, right? So for driving a car, you may not necessarily need to know much about organic chemistry, even though if the organic chemistry is how the car works, right?
So you can drive the car and use it in different ways without understanding much about the fundamentals. So, similarly, with computation, we're at a point where the computation is so high level, right, as you can import scikit learn, and you can go from zero to Machine learning in 30 seconds. It's depending on what level you want to understand the technology, where in the stack, so to speak, it's possible to understand it and make wonderful things and advance the world without understanding it at the particular level of somebody who actually might have originally designed the actual optimization algorithm.
I should say, though, for many of the optimization Algorithms, there are cases where an algorithm works really well and we publish a paper, and there's a proof in the paper, and then years later, people realize actually that proof was wrong, and we're really still not sure why that optimization works, but it works really well, or it inspires people to make new optimization Algorithms. So I do think that the goal of understanding Algorithms is loosely coupled to our progress in advancing grade Algorithms, but they don't always necessarily have to require each other.
And for those students, especially, or even adults, who are thinking of now steering into computer science, into programming, who were really jazzed about heading in that direction up until, for instance, November of 2021, when all of a sudden, for many people, it looked like the world was now changing. And now maybe this isn't such a promising path, this isn't such a lucrative path anymore. Are LLMs are tools like chat GPT reason not to perhaps steer into the field?
Large language models are a particular architecture for predicting, let's say, the next word or a set of tokens. More generally, the algorithm comes in when you think about how is that LLM to be trained, or also how to be fine tuned. So the P of GPT is a pre trained algorithm. The idea is that you train a large language model on some corpus of text, could be encyclopedias or textbooks or what have you, and then you might want to fine tune that model around some particular task or some particular subset of texts.
So both of those are examples of training Algorithms. So I would say people's perceptions of artificial intelligence has really changed a lot in the last six months, particularly around November of 2022, when people experienced a really good chatbot. The technology, though, had been around already before. Academics had already been working with chat, GPT-3 before that, and GPT-2 and GPT one. And for many people, it sort of opened up this conversation about what is artificial intelligence.
And what could we do with this? And what are the possible good and bad? Right? Like any other piece of, of technology, Kranzberg's first law of technology. Technology is neither good nor bad, nor is it neutral. Every time we have some new technology, we should think about its capabilities and the good and the possible bad. As with any area of study, Algorithms offer a spectrum from the most basic to the most advanced.
And even if right now the most advanced of those Algorithms feels out of reach, because you just don't have that background, with each lesson you learn, with each algorithm you study, that endgame becomes, comes closer and closer, such that it will, before long, be accessible to you, and you will be at the end of that most advanced spectrum.
Education, Technology, Innovation, Algorithms, Artificial Intelligence, Machine Learning
Comments ()