> For the complete documentation index, see [llms.txt](https://haroldyin.gitbook.io/grokking-algorithm/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://haroldyin.gitbook.io/grokking-algorithm/chapter-8-greedy-algorithm.md).

# 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.

  ```python
  arr = [1, 2, 2, 3, 3, 3]

  result = set(arr)

  print(result) =>set([1, 2, 3])
  ```
