algorithm-notes
  • Preface
  • Outline
    • Asymptotic-Analysis
    • Divide-and-Conquer (DnC)
      • Overview
      • Multiplication
      • DnC Strategy
      • Master Method
    • Randomization
      • Overview
      • Discrete Probability
      • Randomized Algorithms
      • Reservoir Sampling
    • Sorting
      • Overview
      • Selection Sort
      • Bubble Sort
      • Insertion Sort
      • Shell Sort
      • Merge Sort
      • Heap Sort
      • Quick Sort
      • Non-Comparison Sort
    • Graph Algorithms
      • Overview
      • Minimum Spanning Tree
      • Shortest Path
      • Topological Sort
    • Tree
      • Overview
      • Balanced Search Tree
        • AVL Tree
        • Red-Black Tree
        • B Tree
      • Heap
      • Disjoint Set
      • Threaded Binary Tree
      • Segment Tree
    • Searching
      • Overview
      • Binary Search
      • Graph Search
      • Hash Table
      • String Search
    • Dynamic Programming
      • Overview
      • Fibonacci Numbers
      • LCS problem
    • Greedy Algorithms
      • Overview
Powered by GitBook
On this page
  • Activity Selection Problem
  • Table of Contents

Was this helpful?

  1. Outline

Greedy Algorithms

PreviousLCS problemNextOverview

Last updated 6 years ago

Was this helpful?

Using dynamic programming in most of the scenarios could be an overkill for optimization problems. A more efficient and simpler method could be adopted instead, which is . It will choose the best move in each step of solving sub-problems, in other words, a local optimal solution is made every time and hopefully it leads to the global optimal solution at the end.

Activity Selection Problem

Assume there are n activities {a1, a2, ..., an} that all use the same room which is only available for one activity at a time. Each activity has a starting time si and a ending time fi. If two activities have no overlapping time frames then they are compatible, and a maximal compatible set of activities is required to compute at the end.

It is reasonable to solve this problem using dynamic programming approach with optimal substructure and solution scheme. However, there is an easy way to conquer this problem using approach.

Intuitively, an activity is chosen that ends the first and spare as much time as possible for the rest of activities (there might be other greedy approaches, this only serves as an example). After the first greedy choice is made, the sub-problem needs to be considered that finding compatible activities following and by continuing doing so until the set is empty.

Table of Contents

Though few scenarios can adopt greedy approaches, there are some proven interesting example problems solved using greedy approach:

  • - classic knapsack problem with revision that items can be fractioned.

  • - an efficient way to compress binary data by variable length coding.

greedy algorithms
greedy
Fractional Knapsack
Huffman Coding