💻
Grokking Algorithm
  • Chapter 1: Big O notation & Binary Search
  • Chapter 2: Selection Sort
  • Chapter 3: Recursion
  • Chapter 4: QuickSort
  • Chapter 5: Hash Tables
  • Chapter 6: Breadth-first Search
  • Chapter 7: Dijkstra's Algorithm
  • Chapter 8: Greedy Algorithm
  • Chapter 9: Dynamic Programming
  • Chapter 10: K-nearest neighbors
  • Chapter 11: Next?
Powered by GitBook
On this page

Was this helpful?

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])
PreviousChapter 7: Dijkstra's AlgorithmNextChapter 9: Dynamic Programming

Last updated 5 years ago

Was this helpful?