Table of Contents

Chapter 4

Greedy Algorithm: builds up a solution in small steps, choosing a decision at each step myopically to optimize some underlying criterion.

4.1 Interval Scheduling: The Greedy Algorithm Stays Ahead

Designing a Greedy Algorithm

Potential Designs:

  1. Always Select the Available Request that Starts Earliest: a very long request that starts the earliest is not the most optimal
  2. Accept the Request that Requires the Smallest Interval of Time: accepting a short interval in the middle, may prevent the acceptance of two other requests
  3. For each request, cont the number of requests that are not compatible: accept the request that has the fewest noncompatible requests; more complicated but could work
  4. Accept First the Request That Finishes First: maximize the time left to satisfy other requests

Analyzing the Algorithm

R: set of requests that we have neither accepted nor rejected yet A: done the set of accepted requests O: optimal set of interval

A is a compatible set of requests

Proofs:

For all indices r ⇐ k, we have f(ir) ⇐ f(jr)

The greedy algorithm returns an optimal set A

Implementation and Running Time:

Extensions

A Related Problem: Scheduling All Intervals

Many identical resources available: goal is to schedule all the requests using as few resources as possible

Proof: Depth of a set of intervals is the maximum number that passes over any single point on the time-line

Designing the Algorithm d = depth of the set of intervals

Analyzing the Algorithm


Personal Thoughts

We reviewed many of these concepts in class before Feb Break, so the section made a lot of sense. However, because there are a lot of symbols and equations, it was harder to understand than when it was taught in class. Overall, the concepts were pretty clear though. Readability: 6.5 Interesting: 7

4.2 Scheduling to Minimize Lateness: An Exchange Argument

The Problem

Designing the Algorithm

Analyzing the Algorithm

Extensions


Personal Thoughts

Similar to the section above, we reviewed many of these concepts in class before Feb Break, so the section made a lot of sense. For some reason, I did find this Greedy algorithm easier to follow than the previous one. We have reviewed the example of the classroom scheduling multiple times in class, so that is very clear to me. Readability: 8.5 Interesting: 8

4.4 Shortest Paths in a Graph

The Problem

Designing the Algorithm

Analyzing the Algorithm

Implementation and Running Time

—-

Personal Thoughts

This section provided more clarity to the class discussion on Dijkstra's algorithm. However, I did still struggle to understand the whole algorithm in action. I think with more examples and practice, the algorithm will actually be very simple to understand. Further, running through the algorithm with an example will help solidify why we want to use a priority queue. Readability: 6.5 Interesting: 6

4.5 The Minimum Spanning Tree Problem

The Problem

Designing Algorithms

  1. Start without any edges, insert edges from E in order of increasing cost; only insert an edge if it does not create a cycle. Otherwise, discard.
  2. Prim's Algorithm: start with a root node s, try to grow greedily from s, each time we simply add the node that can be attached as cheaply as possible to the partial tree we already have; grow S by one node, adding the node v that minimizes the “attachment cost”
  3. Kruskal's Algorithm: start with a full graph, begin deleting edge in order of decreasing cost. Delete edges as long as it does not disconnect the graph.

Analyzing the Algorithms

Implementing Prim's Algorithm

Extensions


Personal Thoughts

This section was not overly hard to understand. A lot of the concepts were straightforward and we discussed them thoroughly in class. Not surprisingly, the part I struggled with was understanding the various proofs in this section. This section was more proof-heavy than some of the other sections, so that made the section a little more dense. Readability: 6 Interesting: 6

4.6 Implementing Kruskal's Algorithm: The Union-Find Data Structure

Consider a scenario in which a graph evolves through the addition of edges: Fixed population of nodes that grows over time by having edges appear between certain pairs of nodes.

Data structure called Union-Find to store a representation of the components in a way that supports rapid searching and expansion.

The Problem

A Simple Data Structure for Union-Find

A Better Data Structure for Union-Find

Further Improvements

Implementing Kruskal's Algorithm


Personal Thoughts

Just like the last section, this section was pretty reasonable to understand. We did go through this material in class, so that helped. The data operations were pretty simple, though there was a lot of variability in implementation style, which was a little confusing to keep track of. Overall, not too bad though! Readability: 6.5 Interesting: 6.5

4.7 Clustering

The Problem

Designing the Algorithm

Analyzing the Algorithm


Personal Thoughts

This section was not bad, because it was very general information. The nitty gritty details that I'm sure are related to clustering were not really covered. The overall idea of clustering makes a lot of sense and the basic algorithm was not complicated to follow (especially since it built off of the last section's Kruskal's Algorithm). I am looking forward to seeing more examples/applications of clustering. Readability: 7 Interesting: 7

4.8 Huffman Codes and Data Compression

The Problem

Designing the Algorithm

Huffman's Algorithm

Analyzing the Algorithm

Extensions

Personal Thoughts

While arguably one of the more interesting topics of this textbook, this section was long and very dense. There was a lot of information that was hard to digest all at once. Our discussion in class was helpful, but not long enough to help make this section very clear. I will most likely need to review this chapter section again. Readability: 5 Interesting: 8