(And I mean in real life, not only for coding interviews!)
You are probably using them already, even if you don't know it, so let's explore how they work and —more importantly— when they don't.
🧵👇
Here is the gist of a greedy algorithm: it builds a solution using the best option at every single step.
Here is the intuition (for when they work): "if we make the optimal option at every step, we will end up with the optimal solution overall."
👇
An example:
How do you make 73 cents using the least amount of coins? In the US, you will do the following:
▫️2 x 25 cents
▫️2 x 10 cents
▫️3 x 1 cent
At every step, I selected the larger denomination that fit.
This was a greedy solution. It's also the optimal solution.
👇
Another example:
You want to maximize the number of movies you can watch at the theater. You know the start and end time of each movie.
Using a greedy algorithm you can get the optimal solution: at every step watch the movie that ends the earliest.
👇
Greedy algorithms are intuitive and very simple to implement.
However, they always don't give you the optimal solution!
Before deciding on whether a greedy algorithm is what you want, you need to understand whether your solution is optimal or not!
👇
Imagine that we want to find the path on the tree that produces the largest sum.
A greedy algorithm will select 10 + 20 + 40 for a total of 70.
However, the optimal solution is 10 + 1 + 100 for a total of 111!
Here, greedy is not good.
👇
The Knapsack is another classic problem where a greedy approach will not give you the optimal solution.
By the way, this problem is a classic! You want to look at it because you'll hear about Knapsack all the time. Here is the link: en.wikipedia.org/wiki/Knapsack_…
👇
Let me give you a few more examples where a greedy approach is used with optimal results:
1. Mojo 🔥 went open-source 2. Claude 3 beats GPT-4 3. $100B supercomputer from MSFT and OpenAI 4. Andrew Ng and Harrison Chase discussed AI Agents 5. Karpathy talked about the future of AI
...
And more.
Here is everything that will keep you up at night:
Mojo 🔥, the programming language that turns Python into a beast, went open-source.
This is a huge step and great news for the Python and AI communities!
With Mojo 🔥 you can write Python code or scale all the way down to metal code. It's fast!
The best real-life Machine Learning program out there:
"I have seen hundreds of courses; this is the best material and depth of knowledge I've seen."
That's what a professional Software Engineer finishing my program said during class. This is the real deal.
I teach a hard-core live class. It's the best program to learn about building production Machine Learning systems.
But it's not a $9.99 online course. It's not about videos or a bunch of tutorials you can read.
This program is different.
It's 14 hours of live sessions where you interact with me, like in any other classroom. It's tough, with 30 quizzes and 30 coding assignments.
Online courses can't compete with that.
I'll teach you pragmatic Machine Learning for Engineers. This is the type of knowledge every company wants to have.
The program's next iteration (Cohort #8) starts on November 6th. The following (Cohort #9) on December 4th.
It will be different from any other class you've ever taken. It will be tough. It will be fun. It's the closest thing to sitting in a classroom.
And for the first time, the next iteration includes an additional 9 hours of pre-recorded materials to help you as much as possible!
You'll learn about Machine Learning in the real world. You'll learn to train, tune, evaluate, register, deploy, and monitor models. You'll learn how to build a system that continually learns and how to test it in production.
You'll get unlimited access to me and the entire community. I'll help you through the course, answer your questions, and help with your code.
You get lifetime access to all past and future sessions. You get access to every course I've created for free. You get access to recordings, job offers, and many people doing the job you want to do.
No monthly payments. Ever.
The link to join is in the attached image and in the following tweet.
The link to join the program:
The cost to join is $385.
November and December are the last two iterations remaining at that price. The cost will go up starting in January 2024.
Today, there are around 800 professionals in the community.ml.school
Live sessions and recordings:
Sessions are live, and I recommend every student to attend if they can.
But we also record every session, and you get access to the recordings. You can watch them whenever you want.
We also have 2 office hours. They are optional but a lot of fun!