Lecture 121407

Yeah, this one sucks.

Problem 2: We have a bunch of cows and a bunch of types of grass. You want to get a unique grass for each cow. You have a cost c for grass g. You want to find the minimum amount of money to spend on grass such that each cow is happy and has unique grass. First, you should draw a graph (graph1). You want to assign each x to a cow, which is o. You go through the x's in increasing order of cost. For each grass, we should assign it to the cow whose cost constraints are minimal, but who's greenness constraints are biggest. First, I should prove that it works. First, suppose that you go through the costs in increasing order again. I have 2 magical algorithms, A and A'. If they do the same thing, then we're fine, but if they don't do the same point, then there must be some point where it starts failing. A-C1 A'-C2. You can reorder the elements in A' so that the elements match those of A. We can do this because the overall cost of each Algorithm is the same. We can keep making changes in A' so that all disagreements between A and A' are fixed. We have to use the fact that the greenness and cost of C2 are <= the cost and greenness of G', the later value. We know that this holds true for cost because we arranged them in increasing order. We know the greenness is true because our algorithm picked the cow with the highest greenness. So C1>C2, C1<G', C2<G'. The problem is that there are 100000 cows. The algorithm requires O(G*C) steps, about O(n^2) steps because we go through each seed, which each require going through each cow. This is bad because 100000^2 takes longer than a second. We want something thats n log n. So we create a tree on some interval, and then a tree to keep track of each side of that interval, and then we keep going recursively. Interval Trees will be explained in the coming weeks. Each node in the tree keeps track of whether the value is constant throughout its interval and what that constant number is. At any point, we want to find the cow with the maximum greenness. If we have the array already built, then we have to take the first cow which has our desired greenness in the array. To update this, I say I want to add some cow with some greenness. If I want to add a 2, then I add the two at index 2, then replace all values after that who are less than two with two.

Mr T: Jacob, we shouldn't try to finish #1, move on to #2

Jacob talks about balanced binary search trees with Brian and Jeff

Jacob: Ok, Problem 2: you are given this string, lets say abcdbca. You want to change it to the lexicographically smallest string that has the same characters. You start out with your string S and a String T. At any point, we can remove the first or last element in S and append it to T. First we choose A, and then A again. The next two choices are B and C, so we choose B, then we have two Cs, and we choose the second one. Now we are left with cdb in S. We have b and c, so we choose b, then c, then d. T now contains aabcbcd. LECTURE ENDS HERE

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License