Greedy
A Greedy Algorithm chooses the best local option
What is a Greedy Algorithm? đ¤
A Greedy Algorithm always takes the best possible local option available.
Greedy is Good? đ¤Š
A Greedy algorithm is very useful when choosing between clear right and wrong choices that do not change throughout the algorithms completion.
Greedy will workđ
Choosing a career based on total salary
Choosing a meal based on the biggest size
Choosing a product based on price
Greedy will Not workđ¤Ž
Choosing a career based on happiness
Choosing a meal based on taste
Choosing a product based on quality
đ¤Lets Create A Wall Street Trading Botđ¤
The wall street trading bot is using a simple Greedy algorithm which is: Buy Low & Sell High. With this greedy algorithm the trading bot plans to maximize profit. To give the bot a chance against all of the wall street "Bulls". The bot will be given the next five days of stock prices for a specific company.
Stock prices for the next 5 days
$11, $8, $18, $4, $12
Trading Algorithm đ¤
Buy Today
if the Price Increases Tomorrow
Sell Today
if the Price Decreases Tomorrow
Sample Trading đ
Next 5 Days = $11, $8, $18, $4, $12
Transaction Logs of Botđ¤
$11 = Nothing
$08 = Buys
$18 = Sells
$04 = Buys
$12 = Sells
Profit = 18-8 + 12-4 = $16
đĻThis strategy is the best possible option for this problem but can break down on different types of problemsđĻ
đšī¸Lets Make a Super Mario Bros Algorithmđšī¸
The Greedy algorithm is trying to beat the Super Mario game as fast as possible. The algorithm must obey the rules we set. Algorithm Rules:
Mario always runs forward
Mario always jumps on or over enemies
Mario always jumps over obstacles
The greedy part of the algorithm is always "greedily" moving forward, this was chosen because it seems to be the fastest way to complete the level.
Goodđž
Simple strategy
Easy to implement
Mario will complete levels fast
Bad đŠ
Mario will Not find
Secrets
Bonus content
Faster solutions are possible with shortcuts
Uglyâ ī¸
Unforeseen circumstance can make the game unbeatable
Unique enemy (Bowser)
Can Not defeat using normal jump attacks
Unique level (Swim)
Can Not navigate using normal controls
Unique puzzle (collect keys)
Can Not win without doing something
đ°A Greedy Algorithm can be short sightedđ°
Last updated