1 00:00:04,590 --> 00:00:07,360 In the previous video, we used linear optimization 2 00:00:07,360 --> 00:00:08,910 to allocate ads. 3 00:00:08,910 --> 00:00:11,040 In this video, we're going to use a greedy approach 4 00:00:11,040 --> 00:00:12,990 to allocate ads to queries. 5 00:00:12,990 --> 00:00:15,370 The approach is called greedy because we allocate the ads 6 00:00:15,370 --> 00:00:17,730 sequentially and we prioritize which 7 00:00:17,730 --> 00:00:19,520 combinations of ad and query to use, 8 00:00:19,520 --> 00:00:22,570 based on the average price per display. 9 00:00:22,570 --> 00:00:24,070 So here we have a spreadsheet set up 10 00:00:24,070 --> 00:00:26,360 in the same way as the one from the previous video 11 00:00:26,360 --> 00:00:27,360 with some minor tweaks. 12 00:00:27,360 --> 00:00:30,830 If we scroll down, we have this table here, 13 00:00:30,830 --> 00:00:33,720 which has cells corresponding to combinations of advertisers 14 00:00:33,720 --> 00:00:37,270 and queries, which tells us basically how many times we 15 00:00:37,270 --> 00:00:39,150 display a particular advertiser's 16 00:00:39,150 --> 00:00:41,550 ad with a particular query. 17 00:00:41,550 --> 00:00:43,890 But to the side here, we have another table 18 00:00:43,890 --> 00:00:46,750 which we will use to keep track at every stage 19 00:00:46,750 --> 00:00:50,430 of our allocation process, how much we can allocate-- 20 00:00:50,430 --> 00:00:53,940 how many displays we can perform of a particular ad 21 00:00:53,940 --> 00:00:57,000 with a particular query, based on the budget, 22 00:00:57,000 --> 00:01:00,280 and based on how many displays of each query 23 00:01:00,280 --> 00:01:02,770 remain unallocated. 24 00:01:02,770 --> 00:01:05,150 Further down, where we have our constraints, 25 00:01:05,150 --> 00:01:07,140 we've added some new cells here, which 26 00:01:07,140 --> 00:01:08,810 are labeled with the word "Remaining," 27 00:01:08,810 --> 00:01:11,530 to indicate how much of the budgets of each advertiser 28 00:01:11,530 --> 00:01:15,560 remaining, and how many displays of each query 29 00:01:15,560 --> 00:01:17,800 remain unallocated. 30 00:01:17,800 --> 00:01:20,940 So let's get started with our greedy allocation. 31 00:01:20,940 --> 00:01:23,190 So to start, we go up to our Average Price Per Display 32 00:01:23,190 --> 00:01:26,760 table, and we find the combination 33 00:01:26,760 --> 00:01:28,720 of advertiser and query which gives us 34 00:01:28,720 --> 00:01:31,240 the largest average price per display. 35 00:01:31,240 --> 00:01:33,920 So, in this case, the largest average price per display 36 00:01:33,920 --> 00:01:35,009 is five. 37 00:01:35,009 --> 00:01:41,560 And this happens when we display Verizon's ad with Query 3. 38 00:01:41,560 --> 00:01:43,229 So this is the first variable that we're 39 00:01:43,229 --> 00:01:45,820 going to change in our greedy allocation. 40 00:01:45,820 --> 00:01:48,789 These are the first, basically the first displays 41 00:01:48,789 --> 00:01:50,340 that we're going to use. 42 00:01:50,340 --> 00:01:57,020 So if we scroll down, we add Verizon in Query 3. 43 00:01:57,020 --> 00:01:58,720 And to figure out the budget limit, 44 00:01:58,720 --> 00:02:03,070 we go to Verizon's remaining budget which is $160. 45 00:02:03,070 --> 00:02:08,479 And so we take that $160, and we divide it 46 00:02:08,479 --> 00:02:11,250 through by the average price per display of $5. 47 00:02:11,250 --> 00:02:14,190 So, we get this number 32, and so what this means 48 00:02:14,190 --> 00:02:16,960 is that we can display Verizon's ad with Query 3, 49 00:02:16,960 --> 00:02:21,940 32 times based solely on the remaining budget of Verizon. 50 00:02:21,940 --> 00:02:25,329 Now, of course, we also have to respect how many displays 51 00:02:25,329 --> 00:02:27,840 are unallocated of each query, and for query 3, 52 00:02:27,840 --> 00:02:29,370 we have 80 displays. 53 00:02:29,370 --> 00:02:32,960 So the query limit at this stage is 80. 54 00:02:32,960 --> 00:02:34,780 So now how many times do we actually 55 00:02:34,780 --> 00:02:37,020 display Verizon's ad with Query 3? 56 00:02:37,020 --> 00:02:40,140 Well, the most that we can display Verizon's ad with Query 57 00:02:40,140 --> 00:02:43,220 3 is going to be the smaller of these two numbers. 58 00:02:43,220 --> 00:02:47,130 And so in this case the smaller of the two numbers is 32. 59 00:02:47,130 --> 00:02:52,790 So, we allocate Verizon's ad to Query 3, 32 times. 60 00:02:52,790 --> 00:02:56,640 So now after we've changed the value of this variable, 61 00:02:56,640 --> 00:03:00,600 you can see that the budget of Verizon has changed. 62 00:03:00,600 --> 00:03:01,630 So now it is 0. 63 00:03:01,630 --> 00:03:04,230 So we've completely extinguished Verizon's budget, 64 00:03:04,230 --> 00:03:07,500 and the remaining unallocated displays for Query 3 65 00:03:07,500 --> 00:03:08,650 has also changed. 66 00:03:08,650 --> 00:03:12,550 So this number used to be 80 and now it is 48. 67 00:03:12,550 --> 00:03:15,720 So, since we've extinguished Verizon's budget, 68 00:03:15,720 --> 00:03:18,340 we go back up to our Average Price Per Display table. 69 00:03:18,340 --> 00:03:20,910 And so now we have to select a new combination 70 00:03:20,910 --> 00:03:22,660 to use in our allocation. 71 00:03:22,660 --> 00:03:24,470 Since we've used up Verizon's budget, 72 00:03:24,470 --> 00:03:29,490 we're going to highlight these cells corresponding to Verizon. 73 00:03:29,490 --> 00:03:33,380 We're going to highlight them in red 74 00:03:33,380 --> 00:03:36,130 to indicate that we can't use any of those combinations 75 00:03:36,130 --> 00:03:36,900 anymore. 76 00:03:36,900 --> 00:03:38,660 And from the remaining cells in the table, 77 00:03:38,660 --> 00:03:43,540 we want to find the combination of Advertiser and Query 78 00:03:43,540 --> 00:03:46,740 that gives us the largest average price per display. 79 00:03:46,740 --> 00:03:48,829 So in this case, the next highest 80 00:03:48,829 --> 00:03:51,480 is for T-Mobile and Query 3, and in this case 81 00:03:51,480 --> 00:03:53,350 the average price per display is two. 82 00:03:53,350 --> 00:03:55,270 So this is the next combination that we'll 83 00:03:55,270 --> 00:03:57,280 use in our allocation. 84 00:03:57,280 --> 00:04:02,340 So if we scroll down, we add T-Mobile and Query 3. 85 00:04:02,340 --> 00:04:04,470 So now we have to calculate the budget limit. 86 00:04:04,470 --> 00:04:07,330 T-Mobile's remaining budget is $100. 87 00:04:07,330 --> 00:04:12,790 We take $100, and we divide it through by $2 per display, 88 00:04:12,790 --> 00:04:15,440 and we get this value of 50. 89 00:04:15,440 --> 00:04:18,390 And the query limit for T-Mobile and query 3 90 00:04:18,390 --> 00:04:21,510 is the remaining number of displays for Query 3, 91 00:04:21,510 --> 00:04:22,800 which is 48. 92 00:04:22,800 --> 00:04:24,330 So we scroll up and we add 48. 93 00:04:26,830 --> 00:04:28,540 And so now, how many times do we actually 94 00:04:28,540 --> 00:04:30,780 display T-Mobile's ad with Query 3? 95 00:04:30,780 --> 00:04:32,690 Well, that number is 48, because 48 96 00:04:32,690 --> 00:04:34,750 is the smaller of the two numbers. 97 00:04:34,750 --> 00:04:38,110 So we go ahead and we add that. 98 00:04:38,110 --> 00:04:39,900 And so now T-Mobile's budget has changed. 99 00:04:39,900 --> 00:04:42,320 So it's dropped from 100 to four, 100 00:04:42,320 --> 00:04:45,320 and the remaining displays of Query 3, 101 00:04:45,320 --> 00:04:47,390 that number has dropped to 0. 102 00:04:47,390 --> 00:04:49,090 So there are no more displays of Query 3 103 00:04:49,090 --> 00:04:51,180 remaining that we can use. 104 00:04:51,180 --> 00:04:53,430 So now we move on to the next stage of our allocation, 105 00:04:53,430 --> 00:04:56,610 and we go back to the Average Price Per Display table. 106 00:04:56,610 --> 00:05:00,180 And since we've used up all of the displays of Query 3, 107 00:05:00,180 --> 00:05:02,930 we're going to highlight the remaining cells corresponding 108 00:05:02,930 --> 00:05:06,660 to Query 3 in red, just to remind us 109 00:05:06,660 --> 00:05:07,990 that we can't use them. 110 00:05:07,990 --> 00:05:09,660 And so now from the remaining cells, 111 00:05:09,660 --> 00:05:13,310 again, we want to find the highest average price 112 00:05:13,310 --> 00:05:14,630 per display combination. 113 00:05:14,630 --> 00:05:18,250 And so from the remaining cells, the highest average price 114 00:05:18,250 --> 00:05:22,060 per display occurs when we use T-Mobile's ad with Query 1. 115 00:05:22,060 --> 00:05:25,630 So that's the next variable that we'll use in our allocation. 116 00:05:25,630 --> 00:05:31,740 So we scroll back down and we add T-Mobile with Query 1. 117 00:05:31,740 --> 00:05:34,120 To compute the budget limit, we take T-Mobile's remaining 118 00:05:34,120 --> 00:05:36,980 budget which is four, $4, and we divide it 119 00:05:36,980 --> 00:05:40,450 through by the average price per display of $1. 120 00:05:40,450 --> 00:05:44,000 So, we get four displays according to the budget. 121 00:05:44,000 --> 00:05:45,640 And the query limit, in this case, 122 00:05:45,640 --> 00:05:49,620 is 140, because there are 140 displays of Query 1 123 00:05:49,620 --> 00:05:53,680 that haven't been used towards any ad. 124 00:05:53,680 --> 00:05:55,060 Now how many times do we actually 125 00:05:55,060 --> 00:05:57,170 display T-Mobile's with Query 1? 126 00:05:57,170 --> 00:05:59,980 Again, we just take the minimum of these two quantities, which 127 00:05:59,980 --> 00:06:01,200 is four. 128 00:06:01,200 --> 00:06:04,090 We go ahead and we enter that into our table. 129 00:06:04,090 --> 00:06:06,310 So now if you look at the budgets, 130 00:06:06,310 --> 00:06:09,140 we've completely extinguished T-Mobile's budget 131 00:06:09,140 --> 00:06:12,560 and the remaining number of displays of Query 1 132 00:06:12,560 --> 00:06:17,610 that haven't been allocated has dropped to 136. 133 00:06:17,610 --> 00:06:21,830 So now we move on to the next stage of our allocation. 134 00:06:21,830 --> 00:06:23,840 Again, we've eliminated T-Mobile's budget. 135 00:06:23,840 --> 00:06:29,130 So now we highlight those cells in red. 136 00:06:29,130 --> 00:06:31,340 And so now, we want to pick the highest average price 137 00:06:31,340 --> 00:06:33,090 per display from the remaining cells. 138 00:06:33,090 --> 00:06:35,640 Now in this case, the only two combinations that remain to us 139 00:06:35,640 --> 00:06:37,620 are to display AT&T's ad with Query 1 140 00:06:37,620 --> 00:06:41,080 and to display AT&T's ad with Query 2. 141 00:06:41,080 --> 00:06:43,380 Both of these have the same average price per display, 142 00:06:43,380 --> 00:06:46,270 so it doesn't matter which one we really choose. 143 00:06:46,270 --> 00:06:48,680 But for the purpose of this solution, 144 00:06:48,680 --> 00:06:52,870 let's just go with AT&T displayed with Query 1. 145 00:06:52,870 --> 00:06:55,850 So the average price per display is 0.5. 146 00:06:55,850 --> 00:07:00,420 So we go down, we add that entry to our side table here. 147 00:07:00,420 --> 00:07:01,880 And to compute the budget limit, we 148 00:07:01,880 --> 00:07:07,070 take AT&T's remaining budget of 170, 149 00:07:07,070 --> 00:07:10,040 and we divide it through by 0.5. 150 00:07:10,040 --> 00:07:11,920 To get the query limit, we just look 151 00:07:11,920 --> 00:07:15,400 at the number of remaining displays of Query 1, 152 00:07:15,400 --> 00:07:17,620 which is 136. 153 00:07:17,620 --> 00:07:19,410 So we add that. 154 00:07:19,410 --> 00:07:22,170 And so now, obviously, the smaller of the two quantities 155 00:07:22,170 --> 00:07:23,670 is 136. 156 00:07:23,670 --> 00:07:29,430 So we'll display AT&T's ad with Query 1, 136 times. 157 00:07:29,430 --> 00:07:32,890 So now if we look at the state of our allocation, 158 00:07:32,890 --> 00:07:37,100 we've basically used up all the displays of Query 1. 159 00:07:37,100 --> 00:07:40,110 And we've used up some part of AT&T's budget, 160 00:07:40,110 --> 00:07:42,320 though there's still a lot left. 161 00:07:42,320 --> 00:07:46,060 So now we go back up and we now proceed 162 00:07:46,060 --> 00:07:51,000 to make the next allocation in our greedy solution. 163 00:07:51,000 --> 00:07:53,060 We've eliminated AT&T in Query 1. 164 00:07:53,060 --> 00:07:58,370 So now the only combination that remains is AT&T with Query 2. 165 00:07:58,370 --> 00:08:00,660 So we go down. 166 00:08:00,660 --> 00:08:03,560 We add that entry to our side table. 167 00:08:03,560 --> 00:08:05,380 And so now to get the budget limit, 168 00:08:05,380 --> 00:08:11,150 we take AT&T's remaining budget of $102, 169 00:08:11,150 --> 00:08:14,130 and we divide it through by 0.5, which 170 00:08:14,130 --> 00:08:18,050 is the average price per display to get 204. 171 00:08:18,050 --> 00:08:21,760 And the query limit now is 80, because 80 172 00:08:21,760 --> 00:08:27,380 is the number of remaining unassigned displays of Query 2. 173 00:08:27,380 --> 00:08:29,960 And now the smaller of the two numbers is 80. 174 00:08:29,960 --> 00:08:33,440 And so we add 80 to our table. 175 00:08:33,440 --> 00:08:35,970 And so at this point, we've gone through all the entries 176 00:08:35,970 --> 00:08:37,600 in our average price per display table, 177 00:08:37,600 --> 00:08:41,360 and we've eliminated basically all of them. 178 00:08:41,360 --> 00:08:43,210 And in terms of the allocation, we 179 00:08:43,210 --> 00:08:46,130 know that we can't make any more allocations, because if we look 180 00:08:46,130 --> 00:08:50,560 at our constraints, basically, there are no more displays 181 00:08:50,560 --> 00:08:53,690 of any query that have not been assigned to any advertiser. 182 00:08:53,690 --> 00:08:56,250 So all of these entries here are 0. 183 00:08:56,250 --> 00:09:00,430 And in this case, AT&T's budget is still some positive value. 184 00:09:00,430 --> 00:09:05,150 So we still have $62 of ATamp;T's budget remaining. 185 00:09:05,150 --> 00:09:08,240 But since we don't have any more displays of any query 186 00:09:08,240 --> 00:09:10,760 that we can use, we are basically done. 187 00:09:10,760 --> 00:09:13,260 So this is our greedy solution. 188 00:09:13,260 --> 00:09:15,610 And so there are a couple of interesting things 189 00:09:15,610 --> 00:09:18,140 to note about this greedy solution. 190 00:09:18,140 --> 00:09:21,570 So the first is that the actual combinations that 191 00:09:21,570 --> 00:09:23,030 are used by the greedy solution are 192 00:09:23,030 --> 00:09:25,400 different from those that are made 193 00:09:25,400 --> 00:09:27,810 by the linear optimization based solution. 194 00:09:27,810 --> 00:09:30,680 So for example, in the optimization solution, 195 00:09:30,680 --> 00:09:34,330 if you recall, we only used Query 3 with AT&T. 196 00:09:34,330 --> 00:09:38,270 So we only displayed-- whenever we displayed an ad with Query 197 00:09:38,270 --> 00:09:40,490 3, it was only ATamp;T's ad. 198 00:09:40,490 --> 00:09:43,440 But in this case, we don't actually 199 00:09:43,440 --> 00:09:46,330 display AT&T's ad with Query 3 ever. 200 00:09:46,330 --> 00:09:50,550 And in fact, we display only T-Mobile's ad and Verizon's ad 201 00:09:50,550 --> 00:09:51,620 with Query 3. 202 00:09:51,620 --> 00:09:55,510 We don't use AT&T. So that's-- so the actual allocation 203 00:09:55,510 --> 00:09:59,410 changes and so as a result, the revenue that we get from 204 00:09:59,410 --> 00:10:02,970 the greedy solution is different from the revenue that we get 205 00:10:02,970 --> 00:10:04,730 from the optimization solution. 206 00:10:04,730 --> 00:10:08,360 If you recall, the revenue from the optimization solution 207 00:10:08,360 --> 00:10:10,640 was $428. 208 00:10:10,640 --> 00:10:13,360 Now, this may not seem like a very large difference. 209 00:10:13,360 --> 00:10:15,340 So this is a difference of $60. 210 00:10:15,340 --> 00:10:21,210 But in relative terms, this is actually a rather large amount, 211 00:10:21,210 --> 00:10:30,030 368 relative to 428 is roughly 14 percent. 212 00:10:30,030 --> 00:10:34,090 And so, hopefully this illustrates the fact 213 00:10:34,090 --> 00:10:35,690 that an optimization based solution 214 00:10:35,690 --> 00:10:39,530 can provide a significant difference in performance 215 00:10:39,530 --> 00:10:43,070 relative to a basic common sense solution. 216 00:10:43,070 --> 00:10:45,600 So this concludes our construction and our discussion 217 00:10:45,600 --> 00:10:47,620 of the greedy solution. 218 00:10:47,620 --> 00:10:51,200 In the next video, we will go back to our linear optimization 219 00:10:51,200 --> 00:10:55,400 model, and we will consider some of the sensitivity analysis 220 00:10:55,400 --> 00:10:57,530 that goes along with that model.