Chapter 8: Greedy Algorithm
In technical terms: at each step you pick the locally optimal solution, and in the end you’re left with the globally optimal solution.
greedy algorithms don’t always work.
A set is like a list, except that each item can show up only once in a set. Sets can’t have duplicates.
NP-complete problems
NP-complete problems have no known fast solution.
If you have an NP-complete problem, your best bet is to use an approximation algorithm.
Greedy algorithms are easy to write and fast to run, so they make good approximation algorithms.
arr = [1, 2, 2, 3, 3, 3] result = set(arr) print(result) =>set([1, 2, 3])
Last updated
Was this helpful?