Greedy Algorithms Explained

preview_player
Показать описание
Welcome to another video! In this video, I am going to cover greedy algorithms. Specifically, what a greedy algorithm is and how to create a greedy algorithm. I'll also show you some examples of greedy algorithms.

📄 Resources 📄

⭐️ Timestamps ⭐️
00:00 | Overview
01:28 | What Are Greedy Algorithms?
04:02 | Greedy Algorithm Properties
05:42 | Fractional Knapsack Problem
15:03 | Knapsack Problem

◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️
💰 Courses & Merch 💰

🔗 Social Medias 🔗

🎬 My YouTube Gear 🎬

💸 Donations 💸
◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️◼️

⭐️ Tags ⭐️
- Tech With Tim
- Greedy Algorithm
- Examples
- Knapsack Problem
- Fractional Knapsack Problem
- Algoexpert

⭐️ Hashtags ⭐️
#TechWithTim #GreedyAlgorithms
Рекомендации по теме
Комментарии
Автор

transforming the 0 into 1 was too greedy :)

evgizr
Автор

I already had the answer to optimal solution but only because this is EXACTLY what you do in your head when you are comparing prices at a grocery store. Maximizing the value/size ratio to stay within a certain limit (your grocery budget).

Rebeljah
Автор

Hi Tim. Today is my birthday. I love your content

sumukhjagirdar
Автор

Tim, please more videos like this. 20-30 videos of Greedy algorithms then 20-30 videos of Dynamic programming, then Divide and Conquer - this is the real programming: Django, Flask, React everyone can learn fast, but Algorithms are more important.

Автор

this is just explain for "Fractional Knapsach Problem" solved by "Greedy Algorithms", there are many more Problems we can use "Greedy" to resolve.
but this clip is good at explaining so well done.

futhedude
Автор

Nice video, also a good example because I actually understood on my own the greedy algorithm of the fractional knapsack problem. Keep making videos about algorithms !

ofiryaffe
Автор

why isn't it 4, 3, 2, 0 for a sum of 9? at 3:12

whyisknighttaken
Автор

Hello .
I am new to this topic - however with your explanation and some maths background this is easy topic to understand.
Excellent explanation.
Tim you are doing a superb job- keep it up.

ashleydean
Автор

3:12
you said: we select 0 but how can you get 1 then 😕😁😢

khimleshgajuddhur
Автор

Hi Tim can we expect more questions on algoexpert?

Raghav
Автор

You always upload a video on the topic I wanna learn haha. (btw idk if you knew this but fresca in arabic means a type of sweet snacks :D )

dominator
Автор

We're greedy more algorithms in future 🔥

codeaperture
Автор

Thank you very much!!
I'll try implementing this in a c++ program.

yvanbrunel
Автор

Tons of thanks.. I hope you will continue to more algorithms

rl
Автор

This is really useful Tim, but you might want to be slightly more careful with the numbers you say and write on the screen lol. A couple of times you misspoke or mis-wrote.

sunitmody
Автор

Do a series on Metaheuristics, the video simplifies alot what I know is a very difficult subject, not all problems are small enough to solve like this in code or have simple heuristics to solve. I am interested in more videos on this kind of algorithms of optimization.

pedrorequio
Автор

funny thing is 18 is also the optimal solution for non-fractional units, isn't it? A lucky example :p

cuteflygon
Автор

I'm all in for an algorithm series from Tim ! I'll even pay for that!!

Cookie-mvhg
Автор

I would like to see contents on dynamic programming too tim

aravindhang
Автор

def algorithm(items, capacity):
ratio = sorted([(size, value, value / size)
for size, value in items], key=lambda tup: tup[2], reverse=True)
total_size = total_value = 0
for size, value, _ in ratio:
new_size = total_size + size
if new_size > capacity:
break
total_size = new_size
total_value += value
else:
return total_value
return total_value + (capacity - total_size) / size * value


items = ((22, 19), (10, 9), (9, 9), (7, 6))
capacity = 25

print(algorithm(items, capacity))

korsik