Editing
Approximation Algorithms
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== <span style="color: #FFFFFF;">Applying</span> == '''Modeling 'The Greedy Knapsack' (Approximating the best way to pack a bag):''' <syntaxhighlight lang="python"> def greedy_knapsack(items, capacity): """ Items = [(value, weight), ...] Picks the 'Best Ratio' first. """ # Sort by 'Value per Weight' (The Greedy Choice) sorted_items = sorted(items, key=lambda x: x[0]/x[1], reverse=True) bag = [] current_weight = 0 total_value = 0 for val, wt in sorted_items: if current_weight + wt <= capacity: bag.append((val, wt)) current_weight += wt total_value += val return f"Bag Value: {total_value} | Weight: {current_weight}/{capacity}" # Case: Value/Weight items my_items = [(100, 10), (60, 20), (120, 30)] # (Val, Wt) print(greedy_knapsack(my_items, 50)) </syntaxhighlight> ; Approximation Landmarks : '''The 'Bin Packing' Problem''' β How to fit "Boxes into a Truck" or "Ads onto a Webpage." Approximation algorithms ensure that "Minimum Space is Wasted." : '''Network Design''' β How "Internet Providers" lay fiber-optic cables. They use "Steiner Tree" approximations to connect "Every City" with the "Minimum amount of cable." : '''Deep Learning (SGD)''' β The way "AIs" learn (Stochastic Gradient Descent) is an "Approximation." We don't find the "Perfect Brain," we "Approximate" one that "Works well enough" through billions of tiny tweaks. : '''Scheduling''' β How "Airlines" manage thousands of flights and crews. Since the "Perfect Schedule" is impossible to calculate, they use "Local Search" to "Refine" a good schedule until it is "Almost Perfect." </div> <div style="background-color: #8B4500; color: #FFFFFF; padding: 20px; border-radius: 8px; margin-bottom: 15px;">
Summary:
Please note that all contributions to BloomWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
BloomWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information