Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| courses:cs211:winter2018:journals:devlinn:chapter4 [2018/03/03 18:37] – devlinn | courses:cs211:winter2018:journals:devlinn:chapter4 [2018/03/12 21:00] (current) – devlinn | ||
|---|---|---|---|
| Line 63: | Line 63: | ||
| There are three greedy algorithms which can be used to solve this problem: Kruskal' | There are three greedy algorithms which can be used to solve this problem: Kruskal' | ||
| - | | + | Assume that all edge costs are distinct. Let S be any subset of nodes that is neither empty nor equal to all of V, and let edge e = (v, w) be the minimum-cost edge with one end in S and the other in V - S. Then every minimum spanning tree contains the edge e. |
| | | ||
| - | We can use the Cut Property to prove that Kruskal' | + | We can use the Cut Property to prove that Kruskal' |
| - | The //Cycle Property// says the following, and allows us to know an edge is //not// in the minimum spanning tree: | + | Assume that all edge costs are distinct. Let C be any cycle in G, and let edge e = (v, w) be the most expensive edge belonging to C. Then e does not belong to any minimum spanning tree of G. |
| - | | + | |
| + | The Cycle Property is used to prove the optimality of the Reverse-Delete Algorithm. If using a priority queue, Prim's Algorithm can be implemented to run in O(//m//) time, plus the time for n ExtractMin and m ChangeKey operations. I understood this section alright. I would have liked to understand more simply how to Cycle and Cut Properties are implemented to show these things, because the way the book tried to explain this was unclear. I would rate it a 6. | ||
| + | ===== 4.6 Implementing Kruskal' | ||
| + | We would like to consider a graph evolving through the addition of edges. To maintain a set of connected components as we add to the graph, without having to recompute this information each time, we can implement the **Union-Find** data structure. This structure stores a representation of the components in such a way to support efficient searching and updating. The operation Find(// | ||
| + | The simplest way to implement a Union-Find data structure is using an array which will contain the name of the set currently containing each element. Using this implementation, | ||
| + | |||
| + | To improve upon this implementation, | ||
| + | |||
| + | ===== 4.7 Clustering ===== | ||
| + | Minimum spanning trees play a role in // | ||
| + | The components C1, C2, ..., Ck formed by deleting the k -1 most expensive edges of the minimum spanning tree T constitute a k-clustering of maximum spacing. | ||
| + | | ||
| + | This section was also a bit challenging to understand. We started to discuss this in class. I would have liked more visuals in the book to guide me through the maximum clustering problem. I would rate it a 6. | ||
| + | |||
| + | ===== 4.8 Huffman Codes and Data Compression ===== | ||
| + | For this problem (data compression), | ||
| + | |||
| + | Another thing to consider when creating an optimal encoding of symbols is how frequently certain letters appear in everyday language. It is preferable to assign these letters a smaller number of bits to minimize our use of bits. To do this, we assign a frequency to every letter, with the total frequency of all letters summing to 1. | ||
| + | |||
| + | To construct a greedy algorithm for this problem, we will use binary trees. This ensures that our encoding constructed from the binary tree T will be a prefix code. In addition, the binary tree which corresponds to the //optimal// prefix code is full. Here is the algorithm, // | ||
| + | To construct a prefix code for alphabet S, with given frequencies: | ||
| + | If S has two letters then | ||
| + | Encode one letter using 0 and the other using 1 | ||
| + | Else | ||
| + | Let y* and z* be the two lowest-frequency letters | ||
| + | Form a new alphabet S' by deleting y* and z* and replacing them with a new letter w of frequency fy* + fz* | ||
| + | Recursively construct a prefix code y' for S', with tree T' | ||
| + | Define a prefix code for S as follows: | ||
| + | Start with T' | ||
| + | Take the leaf labeled w and add two children below it labeled y* and z* | ||
| + | | ||
| + | Endif | ||
| + | | ||
| + | When implemented using a priority queue, Huffman' | ||
