Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
courses:cs211:winter2014:journals:emily:entryfive [2014/02/25 20:54] – [Chapter 4.2] hardye | courses:cs211:winter2014:journals:emily:entryfive [2014/02/26 04:51] (current) – [Chapter 4.2] hardye | ||
---|---|---|---|
Line 26: | Line 26: | ||
The solution that is produced from this algorithm does not have any //idle time//, meaning that there are no gaps between jobs where the machine is not doing anything and there are still jobs to complete. | The solution that is produced from this algorithm does not have any //idle time//, meaning that there are no gaps between jobs where the machine is not doing anything and there are still jobs to complete. | ||
+ | |||
**(4.7) There is an optimal schedule with no idle time.** | **(4.7) There is an optimal schedule with no idle time.** | ||
+ | |||
To prove that our solution is optimal and the maximum lateness is minimized, we use the **exchange argument**. We consider an optimal schedule O and modify O to transform it to the schedule that our greedy algorithm produced. | To prove that our solution is optimal and the maximum lateness is minimized, we use the **exchange argument**. We consider an optimal schedule O and modify O to transform it to the schedule that our greedy algorithm produced. | ||
+ | If a schedule puts a job with a greater deadline ahead of a job with a smaller deadline, then we say that schedule has an // | ||
+ | |||
+ | **(4.8) All schedules with no inversions and no idle time have the same maximum lateness** | ||
+ | |||
+ | **Proof** | ||
+ | |||
+ | If there are two schedules without idle time or inversions, they can only be different in the order they schedule jobs with the same deadline. Jobs with the same deadline are scheduled consecutively and the last one as the maximum lateness which is not affected by the order of the jobs. To prove this we take an optimal schedule with no idle time and convert it to a schedule with out any inversions. The changes we make to the schedule will not increase the maximum lateness. So both schedules are optimal | ||
+ | |||
+ | **(4.9) There is an optimal schedule that has no inversions and no idle time** | ||
+ | |||
+ | **Proof** | ||
+ | |||
+ | Start with an optimal solution O with no idle time. The schedule can have at most n/2 inversions if all of the pairs are inverted. | ||
+ | - if O has an inversion, there is a pair of jobs where the one with the later deadline is scheduled before the one with the earliest deadline | ||
+ | - after swapping the jobs we get a schedule with one less inversion | ||
+ | - the new swapped schedule has a maximum lateness no greater than that of O | ||
+ | |||
+ | To prove the new schedule' | ||
+ | |||
+ | **(4.10) The schedule A produced by the greedy algorithm has optimal maximum lateness L.** | ||
+ | |||
+ | The exchange argument is still pretty confusing to me I'd like to see a detailed outline of it. The book confused me after the lecture we had in class. | ||
+ | |||
+ | Readability 8/10 | ||
====== Chapter 4.4 ====== | ====== Chapter 4.4 ====== | ||
+ | **Shortest Paths in a Graph** | ||
+ | |||
+ | We want to be able to find the shortest path from one node to a goal node with a simple algorithm. One example of how we might use this is navigating to a webpage or finding the shortest route to a location. Given a directed graph with a start node we assume that there is a path to every other node in the graph and each edge has a length or weight greater than 0. The length of a path is the sum of the weight of all of the edges in the path. We want to find the minimum path. | ||
+ | |||
+ | **Design** | ||
+ | |||
+ | We start with Dijkstras algorithm. We determine the length of the shortest path by exploring out from our start node and adding to the set each node that has the shortest path distance from s. | ||
+ | |||
+ | Dijkstra' | ||
+ | |||
+ | Let S be the set of explored nodes | ||
+ | |||
+ | For each u in S, we store a distance d(u) | ||
+ | |||
+ | Initially S is empty and d(s)=0 | ||
+ | |||
+ | While S is not equal to V | ||
+ | |||
+ | | ||
+ | small as possible | ||
+ | |||
+ | Add v to s and define d(v) = d'(v) | ||
+ | |||
+ | Endwhile | ||
+ | |||
+ | **Analysis** | ||
+ | |||
+ | To prove the correctness of this algorithm by showing the paths the algorithms produce are the shortest distances. The algorithm is // | ||
+ | |||
+ | **Proof** | ||
+ | |||
+ | By induction we prove the size of S is the smallest it can be. | ||
+ | |||
+ | The algorithm does not work if there are edges with //negative weights// | ||
+ | |||
+ | **Implementation and Running Time** | ||
+ | |||
+ | The runtime of this algorithm is O(m*n). The while loop is executed n-1 times. To compute the edge with the minimum weight for m edges takes O(m) time so the overall runtime is O(mn). | ||
+ | If we keep the minimum values for each node in a priority queue we improve our runtime. We add the nodes into the PQ and extract the minimum to add to the set of the shortest path nodes. When we do this our runtime is improved to O(m log n) time. | ||
+ | |||
+ | Readability 8/10 | ||
====== Chapter 4.5 ====== | ====== Chapter 4.5 ====== | ||
+ | **The Minimum Spanning Tree Problem** | ||
+ | |||
+ | An example of this problem would be if we wanted to connect a neighborhood' | ||
+ | |||
+ | **Design** | ||
+ | There are three different approaches to greedy algorithms that solve this problem | ||
+ | * Kruskal' | ||
+ | * builds a tree by inserting edges in order of increasing cost | ||
+ | * don't add the edge if it creates a cycle | ||
+ | * Primm' | ||
+ | * start with a root node and greedily grow a tree outward | ||
+ | * add the node that is the cheapest edge to attach | ||
+ | * Reverse Delete | ||
+ | * backwards version of Kruskal' | ||
+ | * start with a full graph and delete edges that are most expensive | ||
+ | * delete as long as it doesn' | ||
+ | |||
+ | **Analysis** | ||
+ | |||
+ | The //cut property//: 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. | ||
+ | |||
+ | **Proof** | ||
+ | We use the exchange argument. If we replace the least cost edge in a tree with another edge that is more cost we result in a tree with less expense. | ||
+ | Both Kruskal' | ||
+ | |||
+ | Implementation of Primm' | ||
+ | * both prime' | ||
+ | * implementations of prime' | ||
+ | * if we use a priority queue we can implement in O(m log n) | ||
+ | |||
+ | This section was difficult to get past all of the obscure variables which made it more difficult to follow than with concrete examples in class. I wish the book had more examples. Readability: | ||
====== Chapter 4.6 ====== | ====== Chapter 4.6 ====== | ||
+ | **Implementing Kruskal' | ||
+ | |||
+ | We want to store a representation of connected components so we can easily and quickly update the graph and search the graph. | ||
+ | The data structure we use lets us keep disjoint sets. The find operation will return the set that has that node in it. We use this to compare two nodes and see if they' | ||
+ | |||
+ | **The Data Structure** | ||
+ | |||
+ | We could use an array that contains the name of the set containing each element. This would make lookup be O(1) but the union function would take O(n) time. To improve the runtime we will explicitly maintain the list of elements in each set. We also choose the name for the union to be the name of one of the sets so we only have to update the values of the component in the other set. We bound the average running time of k Union operations to have O(k log k) time to update component values. | ||
+ | Another data structure we can use uses pointers. Each node will point to the set it belongs to. We will still use the elements of the set as possible set names. MakeUnion operation will initialize a record for each element in the set with a pointer that points to itself to show its in its own set. | ||
+ | **This confuses me!!!! Why is it pointing to itself?*** With this data structure the Union function is constant time and to reduce the linear Find operations we keep the larger set as the name of the union to make it O(long n) and the MakeUnionFind operation is O(n). | ||
+ | This section was a lot more confusing to me and I thought was pretty difficult to read. It took me multiple times to read over before I felt like I could take notes on it. Rate 5-6/10. | ||