1 00:00:00,500 --> 00:00:02,800 The following content is provided under a Creative 2 00:00:02,800 --> 00:00:04,340 Commons license. 3 00:00:04,340 --> 00:00:06,660 Your support will help MIT OpenCourseWare 4 00:00:06,660 --> 00:00:11,020 continue to offer high quality educational resources for free. 5 00:00:11,020 --> 00:00:13,640 To make a donation or view additional materials 6 00:00:13,640 --> 00:00:17,365 from hundreds of MIT courses, visit MIT OpenCourseWare 7 00:00:17,365 --> 00:00:17,990 at ocw.mit.edu. 8 00:00:22,790 --> 00:00:26,120 PROFESSOR: OK, let's get started. 9 00:00:26,120 --> 00:00:30,560 Last time we looked at a variety of ways to analyze sums 10 00:00:30,560 --> 00:00:33,900 and to find closed-form expressions for the sums. 11 00:00:33,900 --> 00:00:37,440 And today we're going to use those methods to solve 12 00:00:37,440 --> 00:00:41,920 a variety of famous problems, one of them involving center 13 00:00:41,920 --> 00:00:44,370 of mass and stacking blocks. 14 00:00:44,370 --> 00:00:46,810 We saw a version of that yesterday 15 00:00:46,810 --> 00:00:50,000 in recitation, where you solved the problem of figuring out 16 00:00:50,000 --> 00:00:55,150 how many L's you need to make something like this balance 17 00:00:55,150 --> 00:00:56,870 perfectly. 18 00:00:56,870 --> 00:01:00,250 Now in this case I didn't actually get an integer number 19 00:01:00,250 --> 00:01:02,750 of L's-- which is possible-- because I didn't quite get it 20 00:01:02,750 --> 00:01:04,230 stacked right at the bottom. 21 00:01:04,230 --> 00:01:06,150 So I got 10 and 1/2 L's here. 22 00:01:06,150 --> 00:01:08,660 There's an extra vertical here. 23 00:01:08,660 --> 00:01:12,990 Now in theory there are two integer ways of doing it. 24 00:01:12,990 --> 00:01:15,430 And you proved that yesterday in recitation. 25 00:01:15,430 --> 00:01:18,060 So in theory, 10 and 11 should work, 26 00:01:18,060 --> 00:01:20,170 but in practice the blocks aren't perfect. 27 00:01:20,170 --> 00:01:22,000 I didn't get them perfectly lined up. 28 00:01:22,000 --> 00:01:24,640 And so 10 wouldn't quite work, and 11 tended 29 00:01:24,640 --> 00:01:26,530 to pitch it the other way. 30 00:01:26,530 --> 00:01:29,890 And of course in theory, as long as the center of mass 31 00:01:29,890 --> 00:01:34,080 is just anywhere over this block, it's going to be stable. 32 00:01:34,080 --> 00:01:37,550 In practice there's air moving around, and bouncing and stuff. 33 00:01:37,550 --> 00:01:40,900 And so if you're close to the edge, it's going over. 34 00:01:40,900 --> 00:01:41,420 OK. 35 00:01:41,420 --> 00:01:43,503 So now if you want to build one of these yourself, 36 00:01:43,503 --> 00:01:46,110 it's not hard to do. 37 00:01:46,110 --> 00:01:48,864 You just start with an extra block here, all right, 38 00:01:48,864 --> 00:01:49,780 and then you build up. 39 00:01:49,780 --> 00:01:50,446 And that's easy. 40 00:01:50,446 --> 00:01:52,912 And then you notice when it's about right. 41 00:01:52,912 --> 00:01:54,870 And you can just start wiggling this block out. 42 00:01:54,870 --> 00:01:57,850 And then it looks pretty cool at that point. 43 00:01:57,850 --> 00:02:01,057 Actually it was a student in the class showed me this 44 00:02:01,057 --> 00:02:03,390 a couple of years ago, because we were doing the blocks. 45 00:02:03,390 --> 00:02:04,780 The next thing we're going to do-- we were doing that-- 46 00:02:04,780 --> 00:02:06,321 and he said, hey, there's this thing. 47 00:02:06,321 --> 00:02:08,150 And yeah, pretty cool. 48 00:02:08,150 --> 00:02:11,039 So today we're going to look at a different problem, 49 00:02:11,039 --> 00:02:15,150 and that's the problem of getting the blocks stacked up 50 00:02:15,150 --> 00:02:19,950 so they go out over the edge of the table-- if that's doable. 51 00:02:19,950 --> 00:02:30,840 So the goal is to stack the blocks up like this. 52 00:02:30,840 --> 00:02:32,920 We go farther and farther out. 53 00:02:32,920 --> 00:02:35,410 And the question we're going to look at 54 00:02:35,410 --> 00:02:39,410 is is it possible-- whoa. 55 00:02:39,410 --> 00:02:39,910 Almost. 56 00:02:39,910 --> 00:02:43,909 Is it possible to get a block all the way off the table? 57 00:02:43,909 --> 00:02:45,700 That's the question we're going to look at. 58 00:02:45,700 --> 00:02:47,440 And here I got close. 59 00:02:47,440 --> 00:02:50,215 And you can see it's getting a little tipsy. 60 00:02:50,215 --> 00:02:51,090 It's not going to go. 61 00:02:51,090 --> 00:02:53,450 It's going to fall over. 62 00:02:53,450 --> 00:02:56,030 So I didn't do it this time. 63 00:02:56,030 --> 00:02:59,360 You're only allowed one block per level. 64 00:02:59,360 --> 00:03:04,110 So you can't do anything like this. 65 00:03:04,110 --> 00:03:05,590 That's not allowed. 66 00:03:05,590 --> 00:03:10,680 You can go backwards, if that helps you. 67 00:03:10,680 --> 00:03:13,570 Well it's got to be stable on both sides. 68 00:03:13,570 --> 00:03:16,220 But you can go back and forth. 69 00:03:16,220 --> 00:03:19,370 So the question is, can you get out one block totally 70 00:03:19,370 --> 00:03:21,360 out over the table? 71 00:03:21,360 --> 00:03:25,160 How many people think it can't be done? 72 00:03:25,160 --> 00:03:25,660 All right. 73 00:03:25,660 --> 00:03:26,810 A few doubters. 74 00:03:26,810 --> 00:03:27,830 More doubters. 75 00:03:27,830 --> 00:03:30,180 How many think it can be done? 76 00:03:30,180 --> 00:03:31,930 Oh, a lot of people think it can be done. 77 00:03:31,930 --> 00:03:32,750 OK. 78 00:03:32,750 --> 00:03:35,300 Well all right. 79 00:03:35,300 --> 00:03:38,540 How many people think you can get a block 80 00:03:38,540 --> 00:03:42,080 two blocks out over the table? 81 00:03:42,080 --> 00:03:43,940 A few of you. 82 00:03:43,940 --> 00:03:48,230 How many think you can get it three blocks out? 83 00:03:48,230 --> 00:03:49,020 You're believers. 84 00:03:49,020 --> 00:03:50,430 OK. 85 00:03:50,430 --> 00:03:53,840 How many people think I can reach that wall? 86 00:03:53,840 --> 00:03:56,540 Well I got to tell you I can't reach the wall because-- 87 00:03:56,540 --> 00:03:58,123 AUDIENCE: The ceiling gets in the way. 88 00:03:58,123 --> 00:03:59,020 PROFESSOR: Yeah. 89 00:03:59,020 --> 00:04:00,900 That's going to be hard to do. 90 00:04:00,900 --> 00:04:03,560 But this is what we're going to try to figure out. 91 00:04:03,560 --> 00:04:06,280 And we're going to do it with a little competition. 92 00:04:06,280 --> 00:04:12,050 So we're going to have a team of you go up against the TAs. 93 00:04:12,050 --> 00:04:17,079 And the winner gets candy to share. 94 00:04:17,079 --> 00:04:21,519 The losing team gets the infamous 6042 Nerd Pride pocket 95 00:04:21,519 --> 00:04:23,030 protectors. 96 00:04:23,030 --> 00:04:23,940 Very nice. 97 00:04:23,940 --> 00:04:24,990 Shiny plastic. 98 00:04:24,990 --> 00:04:27,100 Has the MIT logo on them. 99 00:04:27,100 --> 00:04:28,310 Very handy. 100 00:04:28,310 --> 00:04:28,810 All right. 101 00:04:28,810 --> 00:04:31,730 So I need four volunteers. 102 00:04:31,730 --> 00:04:33,710 So come on down if you'd like to volunteer. 103 00:04:33,710 --> 00:04:35,400 You can win some candy for the class-- 104 00:04:35,400 --> 00:04:38,810 or at least win yourself a pocket protector. 105 00:04:38,810 --> 00:04:42,020 And we'll put the class over there. 106 00:04:42,020 --> 00:04:45,610 And we get the TAs to come down. 107 00:04:45,610 --> 00:04:46,460 So come on down. 108 00:04:46,460 --> 00:04:47,501 I got a couple of people. 109 00:04:47,501 --> 00:04:48,920 Who else wants to join them? 110 00:04:48,920 --> 00:04:49,420 All right. 111 00:04:49,420 --> 00:04:50,910 Come on down. 112 00:04:50,910 --> 00:04:54,307 We've got a fourth volunteer out there? 113 00:04:57,271 --> 00:04:57,770 All right. 114 00:04:57,770 --> 00:04:59,061 We got some people coming down. 115 00:04:59,061 --> 00:05:00,430 All right, come on over. 116 00:05:00,430 --> 00:05:00,930 All right. 117 00:05:00,930 --> 00:05:02,270 You got all the blocks you want. 118 00:05:02,270 --> 00:05:04,660 We could even take this thing down. 119 00:05:04,660 --> 00:05:08,660 So here's your supply. 120 00:05:08,660 --> 00:05:09,490 All right. 121 00:05:09,490 --> 00:05:11,810 Now the TAs have a little bit of an advantage, 122 00:05:11,810 --> 00:05:15,960 because they've done this before, some of them. 123 00:05:15,960 --> 00:05:19,070 So you can give some advice to your colleagues here. 124 00:05:19,070 --> 00:05:21,460 So you got to get some blocks out of the block supply. 125 00:05:21,460 --> 00:05:22,751 Maybe we should take this down. 126 00:05:22,751 --> 00:05:25,180 It's about to fall over anyway. 127 00:05:25,180 --> 00:05:27,550 So yeah, how do we get this down? 128 00:05:27,550 --> 00:05:30,576 I'm not sure. 129 00:05:30,576 --> 00:05:31,770 All right, I got this end. 130 00:05:34,476 --> 00:05:35,380 Whoa! 131 00:05:35,380 --> 00:05:35,940 There we go. 132 00:05:35,940 --> 00:05:36,940 Whoa! 133 00:05:36,940 --> 00:05:37,940 [CRASHING BLOCKS] 134 00:05:37,940 --> 00:05:38,940 Oops! 135 00:05:38,940 --> 00:05:41,883 All right. 136 00:05:41,883 --> 00:05:42,383 There we go. 137 00:05:50,020 --> 00:05:53,870 So whoever gets a block out over the farthest wins. 138 00:05:53,870 --> 00:05:55,240 One block per level. 139 00:05:55,240 --> 00:05:57,625 You can't do two blocks on a level. 140 00:05:57,625 --> 00:05:59,250 Believe me it's a lot easier if you can 141 00:05:59,250 --> 00:06:00,670 do multiple blocks per level. 142 00:06:05,080 --> 00:06:06,590 You can go back and forth. 143 00:06:06,590 --> 00:06:08,680 Go ahead and give them some advice. 144 00:06:08,680 --> 00:06:11,280 They look like they need it. 145 00:06:11,280 --> 00:06:13,385 They're only about half a block out so far. 146 00:06:16,590 --> 00:06:18,591 How are the TAs doing here? 147 00:06:18,591 --> 00:06:19,513 AUDIENCE: Three steps forward, two steps back? 148 00:06:19,513 --> 00:06:20,435 Something like that? 149 00:06:20,435 --> 00:06:21,268 [INTERPOSING VOICES] 150 00:06:25,780 --> 00:06:27,280 This is an interesting idea I think 151 00:06:27,280 --> 00:06:30,556 is to go out as far as possible and then just weight it back. 152 00:06:30,556 --> 00:06:32,858 Does that change anything? 153 00:06:32,858 --> 00:06:35,095 Like this you're saying? 154 00:06:35,095 --> 00:06:35,970 PROFESSOR: All right. 155 00:06:35,970 --> 00:06:38,454 The TAs are getting scientific here. 156 00:06:38,454 --> 00:06:40,220 AUDIENCE: It need to be at least half. 157 00:06:40,220 --> 00:06:41,590 PROFESSOR: You know it's not looking good for you 158 00:06:41,590 --> 00:06:42,850 guys to get the candy today. 159 00:06:42,850 --> 00:06:43,858 I got to tell you. 160 00:06:49,535 --> 00:06:50,035 Ooh. 161 00:06:50,035 --> 00:06:53,362 TAs are close. 162 00:06:53,362 --> 00:06:54,570 AUDIENCE: No, that's too far. 163 00:06:54,570 --> 00:06:55,570 Too far. 164 00:06:55,570 --> 00:06:57,398 Look at the distance between this and this. 165 00:06:57,398 --> 00:06:58,231 [INTERPOSING VOICES] 166 00:07:05,965 --> 00:07:06,840 PROFESSOR: All right. 167 00:07:06,840 --> 00:07:08,580 Oh, you're about 2/3 of the way over. 168 00:07:08,580 --> 00:07:11,540 We've got one 2/3. 169 00:07:11,540 --> 00:07:12,890 You've got an inch to go. 170 00:07:12,890 --> 00:07:13,390 Yeah. 171 00:07:13,390 --> 00:07:14,530 Maybe it's not doable. 172 00:07:14,530 --> 00:07:17,330 It's not the first time we've done this 173 00:07:17,330 --> 00:07:20,585 and the problem has not been solvable. 174 00:07:20,585 --> 00:07:22,280 AUDIENCE: The TAs are doing pretty well. 175 00:07:22,280 --> 00:07:22,863 PROFESSOR: Oh. 176 00:07:22,863 --> 00:07:23,900 TAs are close. 177 00:07:23,900 --> 00:07:27,054 they're definitely within an inch. 178 00:07:27,054 --> 00:07:28,095 Maybe an inch and a half. 179 00:07:33,810 --> 00:07:36,060 AUDIENCE: Oh, yeah, the top one should do [INAUDIBLE]. 180 00:07:40,904 --> 00:07:41,570 PROFESSOR: Yeah. 181 00:07:41,570 --> 00:07:42,320 You can't hold it. 182 00:07:42,320 --> 00:07:43,718 It's got to stand up by itself. 183 00:07:47,760 --> 00:07:50,260 Now the bottom block can go out over the edge if you want. 184 00:07:53,730 --> 00:07:56,500 Oh, they're getting close. 185 00:07:56,500 --> 00:07:59,519 Oh, I think you might have the top block out over. 186 00:07:59,519 --> 00:08:00,018 Maybe. 187 00:08:03,240 --> 00:08:04,663 How are you guys doing? 188 00:08:11,230 --> 00:08:12,510 Not good. 189 00:08:12,510 --> 00:08:14,928 This is trouble for the-- 190 00:08:18,150 --> 00:08:18,970 AUDIENCE: It's out. 191 00:08:18,970 --> 00:08:20,011 PROFESSOR: You've got it? 192 00:08:20,011 --> 00:08:20,820 AUDIENCE: Yeah. 193 00:08:20,820 --> 00:08:20,934 PROFESSOR: Ooh. 194 00:08:20,934 --> 00:08:21,434 All right. 195 00:08:21,434 --> 00:08:24,100 You've got to work fast now if you're going to beat that. 196 00:08:24,100 --> 00:08:25,660 TAs got it out over the edge. 197 00:08:25,660 --> 00:08:26,360 You see that? 198 00:08:26,360 --> 00:08:28,470 They're out over the edge. 199 00:08:28,470 --> 00:08:28,970 All right. 200 00:08:28,970 --> 00:08:30,148 I think they did it. 201 00:08:30,148 --> 00:08:30,981 [INTERPOSING VOICES] 202 00:08:33,534 --> 00:08:35,659 We're going to have a hard time analyzing that one. 203 00:08:39,103 --> 00:08:41,964 AUDIENCE: Uh, we're-- I think we're actually there. 204 00:08:41,964 --> 00:08:42,547 PROFESSOR: No. 205 00:08:46,355 --> 00:08:46,855 All right. 206 00:08:46,855 --> 00:08:52,080 Well try another block or two, and then we'll vote. 207 00:08:52,080 --> 00:08:52,580 See? 208 00:08:52,580 --> 00:08:54,080 AUDIENCE: It's on the edge. 209 00:08:54,080 --> 00:08:54,960 Right there. 210 00:08:54,960 --> 00:08:56,697 PROFESSOR: All right. 211 00:08:56,697 --> 00:08:58,280 AUDIENCE: Looks like the Stata Center. 212 00:08:58,280 --> 00:09:00,390 PROFESSOR: Yeah that's it. 213 00:09:00,390 --> 00:09:01,750 AUDIENCE: I'm holding it. 214 00:09:01,750 --> 00:09:02,750 PROFESSOR: You're close. 215 00:09:08,410 --> 00:09:10,154 [INTERPOSING VOICES] 216 00:09:10,154 --> 00:09:12,570 PROFESSOR: You're not the most efficient, that's for sure. 217 00:09:17,740 --> 00:09:20,050 Yeah the TAs are already munching down here. 218 00:09:20,050 --> 00:09:23,426 [INTERPOSING VOICES] 219 00:09:29,410 --> 00:09:30,910 AUDIENCE: Copy the TAs' solution. 220 00:09:30,910 --> 00:09:32,201 PROFESSOR: Now there's an idea. 221 00:09:35,220 --> 00:09:35,820 All right. 222 00:09:35,820 --> 00:09:39,560 Well I think it's time for a vote. 223 00:09:39,560 --> 00:09:43,061 But let the class see what you did. 224 00:09:43,061 --> 00:09:44,560 Yeah you got to take your hands off. 225 00:09:44,560 --> 00:09:45,270 That's you know. 226 00:09:45,270 --> 00:09:45,453 AUDIENCE: We can. 227 00:09:45,453 --> 00:09:46,578 We're just choosing not to. 228 00:09:49,340 --> 00:09:51,340 PROFESSOR: Get some good top balancing on there. 229 00:09:54,714 --> 00:09:55,678 I don't know. 230 00:10:00,240 --> 00:10:00,740 All right. 231 00:10:00,740 --> 00:10:01,970 Can you let it go? 232 00:10:01,970 --> 00:10:02,470 All right. 233 00:10:02,470 --> 00:10:03,095 They let it go. 234 00:10:03,095 --> 00:10:03,690 Let's see. 235 00:10:03,690 --> 00:10:04,853 Did you get one out? 236 00:10:04,853 --> 00:10:05,477 AUDIENCE: Yeah. 237 00:10:05,477 --> 00:10:06,340 This one right here. 238 00:10:06,340 --> 00:10:07,215 PROFESSOR: All right. 239 00:10:07,215 --> 00:10:08,320 We're going to do a vote. 240 00:10:08,320 --> 00:10:13,350 Who thinks they got the one farthest out? 241 00:10:13,350 --> 00:10:14,730 Oh it's close. 242 00:10:14,730 --> 00:10:15,230 Ah! 243 00:10:15,230 --> 00:10:16,550 Look at that. 244 00:10:16,550 --> 00:10:18,080 We need some glasses out there. 245 00:10:18,080 --> 00:10:21,186 Who thinks the TAs got it farther out? 246 00:10:21,186 --> 00:10:22,182 AUDIENCE: Boo. 247 00:10:22,182 --> 00:10:23,050 PROFESSOR: Oh man. 248 00:10:23,050 --> 00:10:25,555 All right. 249 00:10:25,555 --> 00:10:26,055 All right. 250 00:10:26,055 --> 00:10:27,270 So you guys. 251 00:10:27,270 --> 00:10:28,050 Here you go. 252 00:10:28,050 --> 00:10:29,650 Your very nice pocket protectors. 253 00:10:29,650 --> 00:10:30,865 A good effort. 254 00:10:30,865 --> 00:10:31,840 There you are. 255 00:10:31,840 --> 00:10:33,860 Well done. 256 00:10:33,860 --> 00:10:37,480 And I'm afraid they get the candy here. 257 00:10:37,480 --> 00:10:39,942 So you can take these out and share them with the class. 258 00:10:42,184 --> 00:10:43,100 Oh, leave it that way. 259 00:10:43,100 --> 00:10:43,500 Leave it there. 260 00:10:43,500 --> 00:10:44,970 I mean, we're going to analyze yours, 261 00:10:44,970 --> 00:10:46,553 because I can't begin to analyze that. 262 00:10:50,241 --> 00:10:50,740 All right. 263 00:10:50,740 --> 00:10:52,460 Now watching this, how many people 264 00:10:52,460 --> 00:10:56,020 still think we can get it all the way to the wall? 265 00:10:56,020 --> 00:10:56,860 Ah, a few people. 266 00:10:56,860 --> 00:10:59,830 In fact, if you stack this high enough-- 267 00:10:59,830 --> 00:11:02,250 and we're going to analyze how high it has to go-- 268 00:11:02,250 --> 00:11:03,870 you could reach the wall. 269 00:11:03,870 --> 00:11:05,990 Now in fact we're going to find that you probably 270 00:11:05,990 --> 00:11:09,010 got to go out to the stars to get that high 271 00:11:09,010 --> 00:11:10,490 before you can reach the wall. 272 00:11:10,490 --> 00:11:13,750 So it's not too practical. 273 00:11:13,750 --> 00:11:18,130 Now what I want to do is analyze this strategy. 274 00:11:18,130 --> 00:11:19,880 And this sort of looks like a nice design. 275 00:11:19,880 --> 00:11:21,800 They got out there with just five. 276 00:11:21,800 --> 00:11:25,070 And they did a particular approach 277 00:11:25,070 --> 00:11:27,500 using what we could call as the greedy algorithm. 278 00:11:27,500 --> 00:11:29,580 We've seen greedy algorithms before. 279 00:11:29,580 --> 00:11:32,370 And they used another greedy algorithm here. 280 00:11:32,370 --> 00:11:36,820 Now what their greedy strategy did-- and I'm going to redo it 281 00:11:36,820 --> 00:11:42,770 here-- is stack all the blocks right at the edge. 282 00:11:42,770 --> 00:11:46,680 Line it up here and, starting at the top, 283 00:11:46,680 --> 00:11:50,230 push it out as far as you can go. 284 00:11:50,230 --> 00:11:53,250 Now in this case, we can get it out about halfway, 285 00:11:53,250 --> 00:11:56,889 because the center of mass of this block is at halfway point. 286 00:11:56,889 --> 00:11:58,680 And that better be sitting over this block, 287 00:11:58,680 --> 00:12:01,020 or it's going to tip. 288 00:12:01,020 --> 00:12:03,860 So the top block goes out here. 289 00:12:03,860 --> 00:12:06,590 Now I'm going to slide the top two blocks out 290 00:12:06,590 --> 00:12:07,738 as far as they go. 291 00:12:11,240 --> 00:12:11,790 All right. 292 00:12:11,790 --> 00:12:13,170 That's about the tip. 293 00:12:13,170 --> 00:12:18,500 Then I slide the top three out as far as they go. 294 00:12:18,500 --> 00:12:19,840 Whoa! 295 00:12:19,840 --> 00:12:22,600 Almost. 296 00:12:22,600 --> 00:12:24,020 Oops. 297 00:12:24,020 --> 00:12:27,030 Theory is always easier than practice. 298 00:12:27,030 --> 00:12:30,600 And now we do the top four blocks. 299 00:12:30,600 --> 00:12:34,120 And they did a better job than I did. 300 00:12:34,120 --> 00:12:36,960 But that's the algorithm, OK, the greedy algorithm. 301 00:12:36,960 --> 00:12:40,020 The top i blocks-- when i goes 1 to n-- push it out 302 00:12:40,020 --> 00:12:41,480 as far as you can go. 303 00:12:41,480 --> 00:12:41,980 All right. 304 00:12:41,980 --> 00:12:47,840 And we're going to analyze that strategy 305 00:12:47,840 --> 00:12:49,108 and see how far it goes. 306 00:12:57,750 --> 00:13:02,410 So we're given n blocks. 307 00:13:02,410 --> 00:13:05,365 And let's say they all have length 1, to make it easy. 308 00:13:10,130 --> 00:13:15,010 And we're going to define r sub i to be the amount by which 309 00:13:15,010 --> 00:13:17,380 the i'th block hangs out over the edge. 310 00:13:30,108 --> 00:13:31,691 and we're going to count from the top. 311 00:13:44,830 --> 00:13:45,330 All right. 312 00:13:45,330 --> 00:13:49,270 So let's see this on a picture. 313 00:13:49,270 --> 00:13:51,080 So I got the table here. 314 00:13:55,220 --> 00:14:02,160 And then I'm stacking the blocks out in some way like this. 315 00:14:02,160 --> 00:14:04,555 And with a greedy strategy, you don't ever go backwards. 316 00:14:12,400 --> 00:14:12,900 All right. 317 00:14:12,900 --> 00:14:15,980 So I'm defining this distance. 318 00:14:15,980 --> 00:14:19,110 This is block one. 319 00:14:19,110 --> 00:14:26,240 This distance here is r 1. 320 00:14:26,240 --> 00:14:31,470 This distance is r 2. 321 00:14:31,470 --> 00:14:34,710 This one is r 3-- and so forth, until you get down to here. 322 00:14:34,710 --> 00:14:38,080 This is r n, because this is the n'th block, 323 00:14:38,080 --> 00:14:40,610 and it extends out r n from the table. 324 00:14:40,610 --> 00:14:43,590 And this is 0 here, which the table-- 325 00:14:43,590 --> 00:14:45,860 we'll consider the table to be the n plus first block. 326 00:14:45,860 --> 00:14:49,940 So r n plus 1 is 0. 327 00:14:49,940 --> 00:14:51,330 OK. 328 00:14:51,330 --> 00:14:53,820 And so using the strategy-- the greedy strategy-- 329 00:14:53,820 --> 00:14:56,170 we want to know what's r 1? 330 00:14:56,170 --> 00:15:00,040 We want to compute that-- if I keep pushing the blocks out 331 00:15:00,040 --> 00:15:02,970 in a topward fashion as far as they'll go. 332 00:15:02,970 --> 00:15:06,850 Now the constraint is the stability constraint 333 00:15:06,850 --> 00:15:08,171 so it won't fall over. 334 00:15:15,930 --> 00:15:24,970 The stability constraint says that the center of mass-- 335 00:15:24,970 --> 00:15:37,010 we'll call it C k-- of the top k blocks 336 00:15:37,010 --> 00:15:40,149 must lie on the k plus first block. 337 00:15:40,149 --> 00:15:41,190 Otherwise it'll tip over. 338 00:15:49,090 --> 00:15:53,775 And of course the table is block n plus 1 in this context. 339 00:16:02,100 --> 00:16:02,840 OK. 340 00:16:02,840 --> 00:16:07,550 So if at any point we've got k blocks, 341 00:16:07,550 --> 00:16:11,200 and their center of mass is out here, 342 00:16:11,200 --> 00:16:13,040 they'll fall over at that point. 343 00:16:13,040 --> 00:16:14,850 Or if you are building it this way, 344 00:16:14,850 --> 00:16:16,390 they would fall over that way. 345 00:16:16,390 --> 00:16:16,890 All right. 346 00:16:16,890 --> 00:16:19,680 So for each set of the top k blocks, the center of mass 347 00:16:19,680 --> 00:16:21,280 has to be on the block below. 348 00:16:21,280 --> 00:16:23,300 And if it is, we're fine. 349 00:16:23,300 --> 00:16:24,602 It won't fall over. 350 00:16:27,410 --> 00:16:28,840 Now for the greedy stacking. 351 00:16:39,540 --> 00:16:41,940 Where is the center of mass of the top k 352 00:16:41,940 --> 00:16:44,630 blocks in the greedy stacking, the way 353 00:16:44,630 --> 00:16:49,270 we defined them in terms of these variables. 354 00:16:49,270 --> 00:16:50,446 What is C k? 355 00:16:54,870 --> 00:16:55,370 All right. 356 00:16:55,370 --> 00:17:02,190 So I got the top k blocks r k plus 1. 357 00:17:02,190 --> 00:17:06,089 The center of mass of the top k blocks by the greedy strategy 358 00:17:06,089 --> 00:17:09,349 is right at the edge of the k'th block. 359 00:17:09,349 --> 00:17:15,131 So if this is a block k here, then this is r k plus 1. 360 00:17:15,131 --> 00:17:16,589 That's where the center of mass has 361 00:17:16,589 --> 00:17:20,500 to be of all these blocks-- the top k blocks. 362 00:17:20,500 --> 00:17:23,270 If it's a little bit more, it's going to fall over. 363 00:17:23,270 --> 00:17:25,480 If it's less, then it's not greedy. 364 00:17:25,480 --> 00:17:28,510 We didn't push it out as far as it could go. 365 00:17:28,510 --> 00:17:30,010 All right. 366 00:17:30,010 --> 00:17:33,250 So for the greedy stacking, C k is equal to r k plus 1. 367 00:17:36,550 --> 00:17:42,090 And r n plus 1 of course is the edge of the table. 368 00:17:42,090 --> 00:17:42,830 That's zero. 369 00:17:45,880 --> 00:17:48,540 Any questions so far? 370 00:17:48,540 --> 00:17:50,500 What we're doing? 371 00:17:50,500 --> 00:17:51,570 OK. 372 00:17:51,570 --> 00:17:52,080 All right. 373 00:17:52,080 --> 00:17:55,180 So let's figure out where the center of mass of the top k 374 00:17:55,180 --> 00:17:59,600 blocks is-- a formula for that-- a recursive formula. 375 00:17:59,600 --> 00:18:03,280 So to do that we look at the center of mass 376 00:18:03,280 --> 00:18:06,970 of the k'th block by itself, and then average it in with 377 00:18:06,970 --> 00:18:10,551 the center of mass of the top k minus 1 blocks. 378 00:18:10,551 --> 00:18:11,050 OK. 379 00:18:11,050 --> 00:18:15,560 So we're going to set up a recursion to compute C k. 380 00:18:15,560 --> 00:18:23,150 Where is the center of mass of the k'th block just by itself? 381 00:18:23,150 --> 00:18:26,280 The center of mass of the k'th block. 382 00:18:26,280 --> 00:18:26,780 This guy. 383 00:18:26,780 --> 00:18:29,970 Where is its center of mass? 384 00:18:29,970 --> 00:18:30,870 AUDIENCE: [INAUDIBLE] 385 00:18:32,670 --> 00:18:35,840 PROFESSOR: Yeah, r k plus 1 minus 0.5. 386 00:18:35,840 --> 00:18:38,200 Because the center of mass of this block 387 00:18:38,200 --> 00:18:40,860 is 1/2 from the right edge. 388 00:18:40,860 --> 00:18:45,450 And the right edge is-- oh, it's r k. 389 00:18:45,450 --> 00:18:46,315 Sorry. 390 00:18:46,315 --> 00:18:46,900 All right? 391 00:18:46,900 --> 00:18:47,590 The top. 392 00:18:47,590 --> 00:18:48,560 Yeah this is. 393 00:18:48,560 --> 00:18:49,060 What? 394 00:18:49,060 --> 00:18:49,851 What did I do here? 395 00:18:49,851 --> 00:18:50,451 Oh, the top k. 396 00:18:50,451 --> 00:18:50,950 Sorry. 397 00:18:50,950 --> 00:18:53,074 This is the k'th block, the way I had it. 398 00:18:53,074 --> 00:18:53,740 Here's the k'th. 399 00:18:53,740 --> 00:18:56,519 So it is r k minus a half. 400 00:18:56,519 --> 00:18:57,060 That's right. 401 00:18:57,060 --> 00:18:59,161 This is r k plus 1 down here. 402 00:18:59,161 --> 00:18:59,660 All right. 403 00:18:59,660 --> 00:19:02,730 Because the right edge of the k'th block is at r k, 404 00:19:02,730 --> 00:19:06,320 the center of mass is 1/2 left of that. 405 00:19:06,320 --> 00:19:06,820 All right. 406 00:19:06,820 --> 00:19:20,860 So we know that the center of mass of the k'th block is at r 407 00:19:20,860 --> 00:19:24,180 k minus 1/2. 408 00:19:24,180 --> 00:19:24,870 All right. 409 00:19:24,870 --> 00:19:27,980 Now we can compute another expression for C k. 410 00:19:30,520 --> 00:19:45,610 The center of mass of the top k blocks 411 00:19:45,610 --> 00:19:53,660 is C k equals-- well there's k minus 1 block centered 412 00:19:53,660 --> 00:19:56,990 at C k minus 1, because the center of mass 413 00:19:56,990 --> 00:20:00,180 of the top k minus 1 block's by definition is C k minus 1. 414 00:20:00,180 --> 00:20:02,910 And they have weight k minus 1. 415 00:20:02,910 --> 00:20:05,700 And then we average that with a k'th block that has weight 1 416 00:20:05,700 --> 00:20:08,930 at position r k minus 1/2. 417 00:20:08,930 --> 00:20:13,980 And the total weight of this is k minus 1 here, 418 00:20:13,980 --> 00:20:16,160 and one for this block. 419 00:20:16,160 --> 00:20:24,160 So this equals KC k minus 1 minus-- 420 00:20:24,160 --> 00:20:25,600 let me write it better here. 421 00:20:25,600 --> 00:20:27,860 k minus 1. 422 00:20:27,860 --> 00:20:36,140 C k minus 1 plus R k minus 1/2 all over k. 423 00:20:36,140 --> 00:20:36,640 All right. 424 00:20:36,640 --> 00:20:39,670 So now we've got an expression-- a recursive expression-- 425 00:20:39,670 --> 00:20:40,780 for C k. 426 00:20:44,820 --> 00:20:48,425 And to simplify it, we're going to plug in that-- C k 427 00:20:48,425 --> 00:20:50,470 as r k plus 1 for the greedy strategy. 428 00:20:50,470 --> 00:20:52,104 Yeah? 429 00:20:52,104 --> 00:20:54,570 AUDIENCE: [INAUDIBLE] 430 00:20:54,570 --> 00:20:55,900 PROFESSOR: L is 1. 431 00:20:55,900 --> 00:20:59,427 The length of the blocks is 1, here to make it simpler. 432 00:20:59,427 --> 00:21:01,010 Otherwise it would have been a half L. 433 00:21:01,010 --> 00:21:03,890 So yesterday we talked about length L blocks. 434 00:21:03,890 --> 00:21:06,870 Today they're length 1, to be simple. 435 00:21:06,870 --> 00:21:07,370 All right. 436 00:21:07,370 --> 00:21:08,828 So now for the greedy strategy, I'm 437 00:21:08,828 --> 00:21:12,580 just going to plug in C k as r k plus 1. 438 00:21:12,580 --> 00:21:15,680 So let's do that. 439 00:21:15,680 --> 00:21:24,830 So I got C k as r k plus 1 equals zero k minus 1. 440 00:21:24,830 --> 00:21:37,090 Well C k minus 1 is just R k plus R k minus 1/2 over K. 441 00:21:37,090 --> 00:21:43,130 And this simplifies to k r k minus r k 442 00:21:43,130 --> 00:21:49,010 plus r k-- they cancel-- minus 1/2 over k. 443 00:21:49,010 --> 00:21:52,790 This equals r k minus 1/2. 444 00:21:52,790 --> 00:21:56,020 So getting very simple now. 445 00:21:56,020 --> 00:21:57,780 And I'm just going to rewrite this 446 00:21:57,780 --> 00:22:02,950 to look at the difference between r k and r k plus 1. 447 00:22:02,950 --> 00:22:07,562 So r k minus r k plus 1 Oops. 448 00:22:07,562 --> 00:22:08,270 I made a mistake. 449 00:22:08,270 --> 00:22:09,700 That's 1 over 2 k. 450 00:22:09,700 --> 00:22:12,100 Half over k is 1 over 2K. 451 00:22:16,500 --> 00:22:20,921 Any questions about the math we did? 452 00:22:20,921 --> 00:22:21,420 Interesting. 453 00:22:21,420 --> 00:22:23,970 This is one of those problems where the math this way 454 00:22:23,970 --> 00:22:25,099 is easy. 455 00:22:25,099 --> 00:22:27,140 There are other ways to try to solve this problem 456 00:22:27,140 --> 00:22:29,380 and the math gets pretty hairy. 457 00:22:29,380 --> 00:22:32,220 But this one's a simple approach. 458 00:22:32,220 --> 00:22:34,030 What's the meaning of this? 459 00:22:34,030 --> 00:22:39,090 What's an interpretation of r k minus r k plus 1? 460 00:22:39,090 --> 00:22:39,703 Yeah. 461 00:22:39,703 --> 00:22:40,578 AUDIENCE: [INAUDIBLE] 462 00:22:42,924 --> 00:22:43,590 PROFESSOR: Yeah. 463 00:22:43,590 --> 00:22:47,270 This is how much further the k'th block sticks out over 464 00:22:47,270 --> 00:22:49,160 the k plus first block. 465 00:22:49,160 --> 00:22:51,398 So let's see that. 466 00:22:51,398 --> 00:22:52,170 All right. 467 00:22:52,170 --> 00:22:54,230 So here's r 1. 468 00:22:54,230 --> 00:22:56,020 Here's r 2. 469 00:22:56,020 --> 00:23:00,350 r 1 minus r 2 is the amount by which the first block sticks 470 00:23:00,350 --> 00:23:02,010 out over the second. 471 00:23:02,010 --> 00:23:04,700 Here's r 2 two minus r 3. 472 00:23:04,700 --> 00:23:06,841 It's that distance. 473 00:23:06,841 --> 00:23:07,340 All right. 474 00:23:07,340 --> 00:23:11,760 So we've gotten a formula for the greedy strategy of how much 475 00:23:11,760 --> 00:23:15,630 the k'th block sticks out over the k plus first block. 476 00:23:15,630 --> 00:23:17,311 And it's pretty simple. 477 00:23:17,311 --> 00:23:17,810 All right. 478 00:23:17,810 --> 00:23:22,740 So now we can write down this expression 479 00:23:22,740 --> 00:23:25,340 for all the values of k. 480 00:23:25,340 --> 00:23:30,620 So what's r 1 minus r 2 going to be in the greedy strategy? 481 00:23:30,620 --> 00:23:32,480 How much is the top block sticking out 482 00:23:32,480 --> 00:23:38,130 over the second block in the greedy strategy? 483 00:23:38,130 --> 00:23:38,860 1/2. 484 00:23:38,860 --> 00:23:42,140 Just plug in k equals 1. 485 00:23:42,140 --> 00:23:46,758 r 2 minus r 3 equals-- 486 00:23:46,758 --> 00:23:49,105 AUDIENCE: A quarter. 487 00:23:49,105 --> 00:23:50,880 One quarter. 488 00:23:50,880 --> 00:23:56,430 r 3 minus r 4 is what? 489 00:23:56,430 --> 00:23:57,270 6. 490 00:23:57,270 --> 00:23:57,950 All right. 491 00:23:57,950 --> 00:24:00,030 So now you can start to see what the TAs did, 492 00:24:00,030 --> 00:24:02,990 how it got smaller each step going down 493 00:24:02,990 --> 00:24:04,250 all the way to the end here. 494 00:24:04,250 --> 00:24:13,326 You get r n-- the n'th block-- minus the table is 1 over 2 n. 495 00:24:13,326 --> 00:24:14,010 All right. 496 00:24:14,010 --> 00:24:15,980 Now there's a very easy way to figure out 497 00:24:15,980 --> 00:24:19,970 what r 1 is, which is what we're after. 498 00:24:19,970 --> 00:24:21,630 How far out is the top block? 499 00:24:21,630 --> 00:24:24,880 What do I do? 500 00:24:24,880 --> 00:24:28,170 Add them all together. 501 00:24:28,170 --> 00:24:31,520 And everything cancels. 502 00:24:31,520 --> 00:24:39,430 So I get r 1 minus r n plus 1 equals 1/2 plus 1/4 503 00:24:39,430 --> 00:24:43,910 plus 1/6 out to 1 over 2 n. 504 00:24:46,851 --> 00:24:47,350 All right. 505 00:24:47,350 --> 00:24:55,210 So that's just equal to the sum i equal 1 to n 1 over 2 1. 506 00:24:55,210 --> 00:24:55,710 All right. 507 00:24:55,710 --> 00:24:59,990 Now I got r 1 minus r n plus 1. 508 00:24:59,990 --> 00:25:03,810 But what's r n plus 1? 509 00:25:03,810 --> 00:25:04,350 0. 510 00:25:04,350 --> 00:25:05,080 That's the table. 511 00:25:05,080 --> 00:25:06,980 The table doesn't hang out over itself. 512 00:25:06,980 --> 00:25:16,320 So in fact r 1 equals a half of the sum of the inverses 513 00:25:16,320 --> 00:25:17,420 of the first n integers. 514 00:25:20,130 --> 00:25:21,460 OK? 515 00:25:21,460 --> 00:25:25,760 And so now all we have to do is to compute this sum 516 00:25:25,760 --> 00:25:28,350 to know how far out it is. 517 00:25:28,350 --> 00:25:31,090 In fact, this sum comes up so often 518 00:25:31,090 --> 00:25:34,260 in mathematics and computer science, it has a special name. 519 00:25:34,260 --> 00:25:36,150 It's called the harmonic sum. 520 00:25:36,150 --> 00:25:39,790 And the numbers are called the harmonic numbers. 521 00:25:39,790 --> 00:25:49,860 And in particular, the n'th harmonic number 522 00:25:49,860 --> 00:25:53,990 is typically denoted H n just equals 523 00:25:53,990 --> 00:25:55,655 the sum of the n reciprocals. 524 00:26:00,310 --> 00:26:00,810 All right. 525 00:26:00,810 --> 00:26:04,810 So for example, the first harmonic number is 1. 526 00:26:04,810 --> 00:26:10,510 The second is 1 plus 1/2 equals 3/2. 527 00:26:10,510 --> 00:26:21,130 The third is 3/2 plus 1/3, which is 11/6. 528 00:26:21,130 --> 00:26:27,340 The fourth harmonic number is that plus 1/4. 529 00:26:27,340 --> 00:26:29,816 22 plus 3/12 is 25/12. 530 00:26:32,449 --> 00:26:33,990 That's sort of an interesting number, 531 00:26:33,990 --> 00:26:37,380 because it's bigger than 2. 532 00:26:37,380 --> 00:26:39,691 What does that tell us? 533 00:26:39,691 --> 00:26:41,565 Why is that interesting from this perspective 534 00:26:41,565 --> 00:26:44,790 of what we're doing here? 535 00:26:44,790 --> 00:26:47,070 Now you can get a block off the table. 536 00:26:47,070 --> 00:26:50,230 Because R1, the distance that the top block hangs out 537 00:26:50,230 --> 00:26:53,690 off the table, is half the harmonic number. 538 00:26:53,690 --> 00:26:57,930 Half of H 4 is a little bit bigger than 1. 539 00:26:57,930 --> 00:27:02,580 Which means with four blocks the top block can be off the table. 540 00:27:02,580 --> 00:27:04,880 Now the TAs did it using five. 541 00:27:04,880 --> 00:27:06,780 I didn't even get it to work with five. 542 00:27:06,780 --> 00:27:08,950 In theory it'll work with 12. 543 00:27:08,950 --> 00:27:11,380 You can hang one out there just a 24th 544 00:27:11,380 --> 00:27:15,040 beyond the edge of the table in theory. 545 00:27:15,040 --> 00:27:15,540 All right. 546 00:27:15,540 --> 00:27:19,920 If we kept on going, h of a million-- 547 00:27:19,920 --> 00:27:23,490 the millionth harmonic number, if you were to go compute it, 548 00:27:23,490 --> 00:27:29,000 is 14.3927 and some other stuff. 549 00:27:29,000 --> 00:27:32,910 So if I had a million blocks stacked up, in theory 550 00:27:32,910 --> 00:27:37,230 how far would I get the top block off the table? 551 00:27:37,230 --> 00:27:38,910 Seven blocks. 552 00:27:38,910 --> 00:27:39,410 All right. 553 00:27:39,410 --> 00:27:40,493 So that gives you an idea. 554 00:27:40,493 --> 00:27:44,020 You have to do a lot of work to get seven. 555 00:27:44,020 --> 00:27:46,720 And in fact it's hard, because the bottom block 556 00:27:46,720 --> 00:27:49,500 would be hanging out one two millionth of a block. 557 00:27:49,500 --> 00:27:50,000 All right? 558 00:27:50,000 --> 00:27:51,670 So you're adding up a lot of tiny things 559 00:27:51,670 --> 00:27:52,800 to get to seven out there. 560 00:27:54,460 --> 00:27:56,860 Now it turns out that the harmonic numbers 561 00:27:56,860 --> 00:27:58,729 grow to infinity. 562 00:27:58,729 --> 00:27:59,520 And we'll see that. 563 00:27:59,520 --> 00:28:02,760 But they grow very, very slowly. 564 00:28:02,760 --> 00:28:05,890 And to see that, we need to get a closed-form expression 565 00:28:05,890 --> 00:28:08,130 for this sum. 566 00:28:08,130 --> 00:28:11,210 Now does anybody know a closed-form expression 567 00:28:11,210 --> 00:28:14,690 for the sum of 1 over i? 568 00:28:14,690 --> 00:28:16,750 I don't think so, because I don't 569 00:28:16,750 --> 00:28:20,575 know anybody who knows that. 570 00:28:20,575 --> 00:28:25,150 In fact it's [? probably ?] believed that it doesn't exist. 571 00:28:25,150 --> 00:28:30,208 So what do we do to get a good estimation of that sum? 572 00:28:34,360 --> 00:28:35,852 What do we do? 573 00:28:35,852 --> 00:28:37,060 AUDIENCE: Integration bounds. 574 00:28:37,060 --> 00:28:38,110 PROFESSOR: The integration bounds. 575 00:28:38,110 --> 00:28:38,450 Yeah. 576 00:28:38,450 --> 00:28:40,410 Because we're not going to get a closed form. 577 00:28:40,410 --> 00:28:44,260 At least I don't know of anybody who knows how to do it. 578 00:28:44,260 --> 00:28:45,810 So we'll use the integration bounds. 579 00:28:57,260 --> 00:28:59,460 And what kind of function are we summing? 580 00:28:59,460 --> 00:29:03,000 Is it increasing or decreasing? 581 00:29:03,000 --> 00:29:03,660 Decreasing. 582 00:29:03,660 --> 00:29:05,790 Yep. 583 00:29:05,790 --> 00:29:08,158 So we'll use the formula we did last time. 584 00:29:14,221 --> 00:29:14,720 All right. 585 00:29:14,720 --> 00:29:23,980 And that formula is that the sum i equals 1 to n of f of i 586 00:29:23,980 --> 00:29:28,042 is, at most, the first term plus the integral. 587 00:29:31,730 --> 00:29:35,370 And it's at least the last term plus the integral. 588 00:29:42,100 --> 00:29:42,600 All right. 589 00:29:42,600 --> 00:29:45,680 In this case we have f of i as 1 over i. 590 00:29:51,140 --> 00:29:54,197 So the first step is to compute the integral. 591 00:30:02,250 --> 00:30:03,530 And that's pretty easy. 592 00:30:03,530 --> 00:30:08,520 That's just the natural log of x evaluated at n and 1. 593 00:30:08,520 --> 00:30:10,070 And that's easy. 594 00:30:10,070 --> 00:30:12,990 That's just the natural log of n. 595 00:30:12,990 --> 00:30:15,930 So the integral is very easy here. 596 00:30:15,930 --> 00:30:17,720 And now we actually can just plug in 597 00:30:17,720 --> 00:30:18,883 and get really good bounds. 598 00:30:22,100 --> 00:30:23,868 Maybe I'll save that just in case. 599 00:30:42,600 --> 00:30:46,740 OK so plugging in into the bounds f of n 600 00:30:46,740 --> 00:30:51,620 is 1 over n plus the integral is log of n 601 00:30:51,620 --> 00:30:54,860 is less than or equal to the n'th harmonic number. 602 00:30:54,860 --> 00:30:57,190 And it's upper bounded by f of 1, 603 00:30:57,190 --> 00:31:01,798 which is 1 plus the integral. 604 00:31:01,798 --> 00:31:02,550 All right. 605 00:31:02,550 --> 00:31:03,520 So that's really good. 606 00:31:03,520 --> 00:31:05,410 We got very tight bounds. 607 00:31:05,410 --> 00:31:08,220 And now you can see that the n'th harmonic number-- 608 00:31:08,220 --> 00:31:09,800 how fast is it growing? 609 00:31:09,800 --> 00:31:14,620 If I were to use tilde notation, what would I write? 610 00:31:14,620 --> 00:31:15,381 As log n. 611 00:31:15,381 --> 00:31:15,880 Yeah. 612 00:31:15,880 --> 00:31:20,047 So this means that h of n is tilde log of n. 613 00:31:22,750 --> 00:31:25,080 Now this is such an important function 614 00:31:25,080 --> 00:31:27,640 that people have gone to a lot of extra work-- 615 00:31:27,640 --> 00:31:32,810 which we can't do in this class-- to really nail down 616 00:31:32,810 --> 00:31:34,260 the value-- get it much closer. 617 00:31:34,260 --> 00:31:40,560 And in fact it's now known that it's the natural log of n 618 00:31:40,560 --> 00:31:49,360 plus 1 over 2n plus 1 over 12n squared plus epsilon of n 619 00:31:49,360 --> 00:31:58,080 over 120n to the fourth where for all n 620 00:31:58,080 --> 00:32:00,730 epsilon n is between 0 and 1. 621 00:32:04,661 --> 00:32:05,160 Oop. 622 00:32:05,160 --> 00:32:08,230 And I left one piece out. 623 00:32:08,230 --> 00:32:11,990 Actually there's a constant term in here-- delta-- 624 00:32:11,990 --> 00:32:15,230 that's called Euler's constant. 625 00:32:15,230 --> 00:32:21,630 Delta is called Euler's constant, 626 00:32:21,630 --> 00:32:32,131 and equals 0.577215664 and some other stuff. 627 00:32:32,131 --> 00:32:33,630 And in fact to this day people don't 628 00:32:33,630 --> 00:32:37,760 know if this constant is rational or irrational. 629 00:32:37,760 --> 00:32:42,200 But they know it to a lot of decimal places. 630 00:32:42,200 --> 00:32:48,250 So basically H n is the log of n plus some fixed value between 0 631 00:32:48,250 --> 00:32:50,110 and 1-- as we knew it had to be-- 632 00:32:50,110 --> 00:32:52,120 plus even some tail terms here that 633 00:32:52,120 --> 00:32:55,630 get very small as n gets large. 634 00:32:55,630 --> 00:32:56,130 All right. 635 00:32:56,130 --> 00:33:00,070 So say I wanted to using this greedy strategy. 636 00:33:00,070 --> 00:33:04,750 How many blocks I would need to get a block 100 blocks out 637 00:33:04,750 --> 00:33:06,700 over the end of the table. 638 00:33:06,700 --> 00:33:09,300 So I want to go 100 blocks out. 639 00:33:09,300 --> 00:33:13,880 How many blocks do I need using this strategy, roughly? 640 00:33:18,090 --> 00:33:20,390 What is it? 641 00:33:20,390 --> 00:33:23,190 I think somebody said it. 642 00:33:23,190 --> 00:33:30,020 So I want to get r 1 to be 100. 643 00:33:30,020 --> 00:33:36,070 So I need the harmonic number to be 200. 644 00:33:36,070 --> 00:33:40,401 And what does this tell me about n to get this to be 200? 645 00:33:43,840 --> 00:33:45,100 e to the 200. 646 00:33:45,100 --> 00:33:45,600 All right. 647 00:33:45,600 --> 00:33:48,030 So you're going to need an exponential 648 00:33:48,030 --> 00:33:51,350 in 200 number of blocks, which now we're past the stars, 649 00:33:51,350 --> 00:33:54,340 all right, to get that many. 650 00:33:54,340 --> 00:33:54,840 All right. 651 00:33:54,840 --> 00:33:59,480 Now we won't prove it in class, but this strategy-- the TA 652 00:33:59,480 --> 00:34:02,710 greedy strategy-- is optimal. 653 00:34:02,710 --> 00:34:07,660 There is no way to get a block farther out over the edge. 654 00:34:07,660 --> 00:34:11,080 That said, there is a second way to get there. 655 00:34:11,080 --> 00:34:15,380 And in the second way, the top block is not the optimal block. 656 00:34:15,380 --> 00:34:18,196 In the second way, it's the second block that goes out. 657 00:34:18,196 --> 00:34:19,529 So it looks something like that. 658 00:34:19,529 --> 00:34:21,730 So there's a counterweight on it. 659 00:34:21,730 --> 00:34:24,320 And in the text, when you read chapter nine, 660 00:34:24,320 --> 00:34:27,699 you will see the proof that shows that there's 661 00:34:27,699 --> 00:34:29,000 two solutions that are optimal. 662 00:34:29,000 --> 00:34:30,666 One's a greedy, and one's this other one 663 00:34:30,666 --> 00:34:33,599 that sort of is mostly the greedy, except the top couple 664 00:34:33,599 --> 00:34:34,810 of blocks are different. 665 00:34:34,810 --> 00:34:36,150 And it proves that's optimal. 666 00:34:36,150 --> 00:34:37,790 We won't cover that in class. 667 00:34:40,580 --> 00:34:42,830 Now actually in the literature today people 668 00:34:42,830 --> 00:34:45,900 have been studying how far a block can go out 669 00:34:45,900 --> 00:34:48,310 if you're allowed to do more than one block per level, 670 00:34:48,310 --> 00:34:50,870 like one of the students wanted to do. 671 00:34:50,870 --> 00:34:53,429 So if you're allowed to have multiple blocks 672 00:34:53,429 --> 00:34:57,460 on the same level, it turns out you can get much farther 673 00:34:57,460 --> 00:34:58,900 out with n blocks. 674 00:34:58,900 --> 00:35:02,400 And right now it's known that it's something like n 675 00:35:02,400 --> 00:35:04,830 to the third is how far you can get out, 676 00:35:04,830 --> 00:35:07,310 which is much better than log of n. 677 00:35:07,310 --> 00:35:10,950 And so mathematicians have been studying that problem. 678 00:35:10,950 --> 00:35:15,420 Any questions about the block stacking? 679 00:35:18,360 --> 00:35:19,331 OK. 680 00:35:19,331 --> 00:35:19,830 All right. 681 00:35:19,830 --> 00:35:24,130 So that's basically it for sums. 682 00:35:24,130 --> 00:35:27,190 I do want to spend a little time talking about products. 683 00:35:27,190 --> 00:35:29,340 And that may get us back into sums pretty quick. 684 00:35:32,410 --> 00:35:37,690 The most famous product out there is n factorial. 685 00:35:37,690 --> 00:35:40,900 And once we get to counting and probability, 686 00:35:40,900 --> 00:35:42,410 probably every lecture we're going 687 00:35:42,410 --> 00:35:45,530 to be looking at n factorial one way or another. 688 00:35:45,530 --> 00:35:48,595 Just comes up all the time. 689 00:35:48,595 --> 00:35:54,610 n factorial is the product of i equals 1 to n of i. 690 00:35:54,610 --> 00:36:02,530 It's the product of the first n natural numbers after zero. 691 00:36:02,530 --> 00:36:05,280 Now we'd like to be able to get a closed-form expression 692 00:36:05,280 --> 00:36:07,600 for this, because factorial is really not closed form, 693 00:36:07,600 --> 00:36:10,870 because it's hiding this thing. 694 00:36:10,870 --> 00:36:15,040 And if I ask you how big is n factorial, sort of hard 695 00:36:15,040 --> 00:36:19,560 to say how big it is, how fast it grows. 696 00:36:19,560 --> 00:36:24,970 Any ideas about how we might go about doing a product to get 697 00:36:24,970 --> 00:36:26,676 a closed-form expression? 698 00:36:26,676 --> 00:36:28,634 AUDIENCE: If you take a logarithm of a product, 699 00:36:28,634 --> 00:36:29,770 you get a sum. 700 00:36:29,770 --> 00:36:31,170 PROFESSOR: Yeah, good. 701 00:36:31,170 --> 00:36:32,341 Take the log of it. 702 00:36:36,970 --> 00:36:43,980 Well, let's write that out-- 1 times 2 times 3 to n. 703 00:36:43,980 --> 00:36:47,470 That equals the log of 1 plus the log of 2. 704 00:36:50,347 --> 00:36:50,847 Whoops. 705 00:36:53,441 --> 00:36:53,940 All right. 706 00:36:53,940 --> 00:36:55,420 So I've now got a sum. 707 00:37:01,005 --> 00:37:05,150 And now that I've got a sum we can use all the tools 708 00:37:05,150 --> 00:37:06,650 we had for sums. 709 00:37:06,650 --> 00:37:09,750 So really, products look hairy, but they're 710 00:37:09,750 --> 00:37:11,399 no different than sums. 711 00:37:11,399 --> 00:37:13,190 Because we're going to get an approximation 712 00:37:13,190 --> 00:37:15,640 or get an answer for [? login ?] n factorial. 713 00:37:15,640 --> 00:37:18,660 Then we'll exponentiate it, and we'll have the answer. 714 00:37:18,660 --> 00:37:19,160 All right. 715 00:37:19,160 --> 00:37:21,540 So we're looking at this sum. 716 00:37:21,540 --> 00:37:26,200 And so how do I get a closed form for that? 717 00:37:26,200 --> 00:37:30,010 Turns out nobody knows the closed form. 718 00:37:30,010 --> 00:37:35,100 But we do know a method that approximates it very well, 719 00:37:35,100 --> 00:37:39,470 which is the integration bounce. 720 00:37:39,470 --> 00:37:43,450 Only in this case, it's an increasing function. 721 00:37:43,450 --> 00:37:44,320 So let's do that. 722 00:38:05,450 --> 00:38:05,960 OK. 723 00:38:05,960 --> 00:38:06,930 So let's do that. 724 00:38:21,620 --> 00:38:22,760 And the formula is easy. 725 00:38:22,760 --> 00:38:25,770 It's basically the same formula we had there-- 726 00:38:25,770 --> 00:38:30,740 that the sum i equals 1 to n of f of i 727 00:38:30,740 --> 00:38:34,996 is at most the n'th term plus the integral. 728 00:38:37,950 --> 00:38:42,590 And it's at least the first term plus the integral. 729 00:38:47,006 --> 00:38:47,760 All right. 730 00:38:47,760 --> 00:38:51,165 Now in this case f of i is the log of i. 731 00:38:54,890 --> 00:39:03,300 And so we need to compute the integral of log of x. 732 00:39:03,300 --> 00:39:04,060 And that's easy. 733 00:39:04,060 --> 00:39:11,950 That's x ln of x minus x evaluated at n and 1. 734 00:39:11,950 --> 00:39:15,641 And that's just n log of n minus n. 735 00:39:19,410 --> 00:39:23,250 If I plug in 1, I get a 0 here, and I'm subtracting negative 1 736 00:39:23,250 --> 00:39:25,901 there. 737 00:39:25,901 --> 00:39:26,400 All right. 738 00:39:26,400 --> 00:39:30,633 And so now we'll just plug this into the integral 739 00:39:30,633 --> 00:39:31,674 and we'll get our bounce. 740 00:39:34,890 --> 00:39:37,700 So f of 1. 741 00:39:37,700 --> 00:39:42,370 What is f of 1 in this case? 742 00:39:42,370 --> 00:39:44,980 Yeah, 0. 743 00:39:44,980 --> 00:39:52,140 Plus n ln n minus n plus 1 less than 744 00:39:52,140 --> 00:39:59,580 equal to log of n factorial, less than or equal to f of n 745 00:39:59,580 --> 00:40:00,770 is log of n. 746 00:40:07,830 --> 00:40:09,340 OK. 747 00:40:09,340 --> 00:40:11,690 So to get bounds on n factorial, we just 748 00:40:11,690 --> 00:40:14,770 exponentiate both sides. 749 00:40:14,770 --> 00:40:18,300 So I take e to this, gives me-- well, that's 750 00:40:18,300 --> 00:40:23,205 going to give n to the n here. 751 00:40:23,205 --> 00:40:24,080 And this is negative. 752 00:40:24,080 --> 00:40:25,822 That'll be e to the n minus 1. 753 00:40:29,690 --> 00:40:34,170 And here I've got n plus 1 times the log of n. 754 00:40:34,170 --> 00:40:38,680 So it's n to the n plus 1 over the same thing-- 755 00:40:38,680 --> 00:40:41,710 e to the n minus 1. 756 00:40:41,710 --> 00:40:43,160 So we got very close bounds. 757 00:40:43,160 --> 00:40:46,570 They're within a factor of n-- which sounds like a lot, 758 00:40:46,570 --> 00:40:50,450 but compared to how big n factorial is, not so bad. 759 00:40:50,450 --> 00:40:54,205 Pretty good bounds there. 760 00:40:54,205 --> 00:40:54,705 OK. 761 00:40:57,470 --> 00:41:01,570 So n factorial's about n over e to the n'th power. 762 00:41:01,570 --> 00:41:05,180 Now this is so important that-- even more important 763 00:41:05,180 --> 00:41:08,060 than harmonic numbers-- people have gone to a lot of effort 764 00:41:08,060 --> 00:41:10,970 to get very tight bounds on n factorial. 765 00:41:10,970 --> 00:41:12,386 So let me tell you what those are. 766 00:41:19,754 --> 00:41:21,045 It's called Stirling's formula. 767 00:41:30,510 --> 00:41:35,650 And that says that n factorial equals n over e 768 00:41:35,650 --> 00:41:42,230 to the n'th power times the square root of 2 pi n times 769 00:41:42,230 --> 00:41:54,770 e to the epsilon n where epsilon n is between 1 over 12n 770 00:41:54,770 --> 00:42:00,670 plus 1 and 1 over 12n. 771 00:42:00,670 --> 00:42:04,430 So it's epsilon n is going to 0 as n gets big. 772 00:42:04,430 --> 00:42:07,921 So e to something going to 0 is going to 1. 773 00:42:07,921 --> 00:42:08,420 All right. 774 00:42:08,420 --> 00:42:11,000 So another way of looking at this 775 00:42:11,000 --> 00:42:13,270 is you could put a tilde here, all right, 776 00:42:13,270 --> 00:42:14,490 and ignore that term. 777 00:42:14,490 --> 00:42:16,310 And that's called Stirling's formula. 778 00:42:16,310 --> 00:42:19,670 This is a good thing to have on your crib sheet 779 00:42:19,670 --> 00:42:21,110 for the midterm. 780 00:42:21,110 --> 00:42:23,040 So very likely there'll be something 781 00:42:23,040 --> 00:42:25,700 where you've got to have some kind of analysis 782 00:42:25,700 --> 00:42:31,370 of n factorial, and to know how fast it's growing. 783 00:42:31,370 --> 00:42:34,860 Now these bounds you get here are very tight. 784 00:42:34,860 --> 00:42:42,330 For example, 100 factorial is at least 100 785 00:42:42,330 --> 00:42:50,520 over e to 100 times square root 200 pi, times e to the 1 786 00:42:50,520 --> 00:42:52,960 over 1,201. 787 00:42:52,960 --> 00:42:54,880 This thing is just really tiny. 788 00:42:54,880 --> 00:43:03,080 This thing here is 1.0008329 and something. 789 00:43:03,080 --> 00:43:06,710 And 100 factorial is lower-bounded 790 00:43:06,710 --> 00:43:15,040 by the same things, only here it's e to the 1 over 1,200. 791 00:43:15,040 --> 00:43:24,100 And that is very close to 1-- 1.00083368. 792 00:43:24,100 --> 00:43:26,850 So the difference in these bounds 793 00:43:26,850 --> 00:43:30,770 is a tiny fraction of 1%. 794 00:43:30,770 --> 00:43:33,360 So the bound you get from Stirling's formula 795 00:43:33,360 --> 00:43:35,476 is very, very close to the right answer. 796 00:43:41,910 --> 00:43:46,659 Any questions on Stirling's formula? 797 00:43:46,659 --> 00:43:47,450 We won't derive it. 798 00:43:47,450 --> 00:43:49,407 You can derive that in a graduate math class. 799 00:43:49,407 --> 00:43:50,365 They do that sometimes. 800 00:43:53,380 --> 00:43:55,615 More typically you'll see it without that e 801 00:43:55,615 --> 00:43:56,940 to the error term. 802 00:43:56,940 --> 00:43:58,540 And you just see n factorial written 803 00:43:58,540 --> 00:44:05,930 as tilde, and over e to the n, square root 2 pi n. 804 00:44:05,930 --> 00:44:06,430 All right? 805 00:44:06,430 --> 00:44:10,610 Because that e to the epsilon n goes to 1 in the limit. 806 00:44:10,610 --> 00:44:14,490 So it sort of disappears when you go to the tilde notation. 807 00:44:14,490 --> 00:44:16,900 And this in fact is a lower bound on n 808 00:44:16,900 --> 00:44:21,510 factorial, and very close to the right answer. 809 00:44:21,510 --> 00:44:25,010 Now this is sort of an amazing formula. 810 00:44:25,010 --> 00:44:29,010 I mean who would think that when you look at n factorial 811 00:44:29,010 --> 00:44:32,640 that the expression would have e and pi 812 00:44:32,640 --> 00:44:34,120 in the expression for it? 813 00:44:34,120 --> 00:44:34,930 Maybe e. 814 00:44:34,930 --> 00:44:35,640 Maybe. 815 00:44:35,640 --> 00:44:39,330 But what's pi doing in n factorial? 816 00:44:39,330 --> 00:44:43,410 It's sort of a bizarre thing. 817 00:44:43,410 --> 00:44:44,470 OK. 818 00:44:44,470 --> 00:44:45,660 That's it for products. 819 00:44:45,660 --> 00:44:47,285 We're just going to do the one example, 820 00:44:47,285 --> 00:44:50,530 because really any product just becomes a sum through the log. 821 00:44:50,530 --> 00:44:52,590 And that makes it really easy. 822 00:44:52,590 --> 00:44:56,900 Any questions on sums and products? 823 00:44:56,900 --> 00:45:00,940 Because I'm going to totally change gears now and talk 824 00:45:00,940 --> 00:45:02,760 about more things like tilde. 825 00:45:05,297 --> 00:45:05,796 OK. 826 00:45:10,170 --> 00:45:15,340 So we're going to talk today and tomorrow in recitation 827 00:45:15,340 --> 00:45:18,690 about asymptotic notation. 828 00:45:18,690 --> 00:45:24,130 It is used all over the place in computer science. 829 00:45:24,130 --> 00:45:28,810 We've already seen one example, which is the tilde notation. 830 00:45:28,810 --> 00:45:33,150 And it turns out there's five more things like that 831 00:45:33,150 --> 00:45:35,911 which we're going to learn what they are and how they work. 832 00:45:42,790 --> 00:45:46,530 They're used to explain or describe how 833 00:45:46,530 --> 00:45:50,330 a function grows in the limit. 834 00:45:50,330 --> 00:45:54,540 So for example, we had the tilde notation. 835 00:45:54,540 --> 00:46:04,680 And we wrote f of x is tilde g of x if the limit as x goes 836 00:46:04,680 --> 00:46:11,223 to infinity of f over g is 1. 837 00:46:13,880 --> 00:46:16,280 Now the next one-- and most commonly 838 00:46:16,280 --> 00:46:17,910 used one in computer science-- is 839 00:46:17,910 --> 00:46:23,200 called the O notation, or the big O. 840 00:46:23,200 --> 00:46:24,760 And it's written like this. 841 00:46:24,760 --> 00:46:31,100 f of x equals O of g of x. 842 00:46:31,100 --> 00:46:37,100 And it means that the limit as x goes 843 00:46:37,100 --> 00:46:40,560 to infinity of the absolute value of f 844 00:46:40,560 --> 00:46:46,510 of x over g of x is convergence-- 845 00:46:46,510 --> 00:46:48,210 is less than infinity. 846 00:46:48,210 --> 00:46:55,760 So it's finite, and it can't diverge. 847 00:46:55,760 --> 00:47:00,730 The interpretation is that this function 848 00:47:00,730 --> 00:47:05,860 is up to constant factors upper-bounded by this one, 849 00:47:05,860 --> 00:47:11,690 that this grows the same rate or slower than this one grows 850 00:47:11,690 --> 00:47:13,880 as x gets large. 851 00:47:13,880 --> 00:47:18,450 Because if f was growing a lot faster than g in the limit, 852 00:47:18,450 --> 00:47:20,520 then the limit would be the ratio is infinity. 853 00:47:20,520 --> 00:47:22,521 And we're saying that doesn't happen. 854 00:47:22,521 --> 00:47:23,020 All right. 855 00:47:23,020 --> 00:47:25,630 I'm not going to do a lot of examples for this. 856 00:47:29,600 --> 00:47:31,400 In fact, let's go over here. 857 00:47:31,400 --> 00:47:33,544 There's several other ways you'll see it written. 858 00:47:50,980 --> 00:47:53,460 For example, you'll see people write 859 00:47:53,460 --> 00:47:57,270 f of x is less than or equal to O 860 00:47:57,270 --> 00:48:01,550 of g of x, because the natural interpretation is 861 00:48:01,550 --> 00:48:05,950 f is not growing faster than g-- sort of upper-bounded by g. 862 00:48:05,950 --> 00:48:13,060 You'll see people write f of x is O of g of x. 863 00:48:13,060 --> 00:48:16,440 And the formal math way that people don't use, 864 00:48:16,440 --> 00:48:18,590 but it's the formally correct one, 865 00:48:18,590 --> 00:48:23,750 is f of x is an element of O of g of x. 866 00:48:23,750 --> 00:48:26,890 And the interpretation there is that O of g of x 867 00:48:26,890 --> 00:48:29,950 is a set of functions that don't grow any faster than g. 868 00:48:29,950 --> 00:48:31,810 And f is one of them. 869 00:48:31,810 --> 00:48:34,357 You can use any of these and that's fine. 870 00:48:34,357 --> 00:48:36,065 People will know what you mean, and it'll 871 00:48:36,065 --> 00:48:38,560 be fine for the class. 872 00:48:38,560 --> 00:48:39,060 All right. 873 00:48:39,060 --> 00:48:44,513 Let's see some examples, and see how to prove a big O relation. 874 00:48:47,300 --> 00:48:51,480 Let f of x be the function x, and g 875 00:48:51,480 --> 00:48:55,670 of x be the function x squared. 876 00:48:55,670 --> 00:48:59,900 Then in this case f of x is O of g 877 00:48:59,900 --> 00:49:05,280 of x-- because x doesn't grow any faster than x 878 00:49:05,280 --> 00:49:06,940 squared as x gets large. 879 00:49:06,940 --> 00:49:11,510 To prove it, we take the limit as x 880 00:49:11,510 --> 00:49:18,700 goes to infinity of x over x squared. 881 00:49:18,700 --> 00:49:21,040 That is equal to what? 882 00:49:21,040 --> 00:49:25,920 What is the limit of x over x squared as x goes to infinity? 883 00:49:25,920 --> 00:49:28,350 0. 884 00:49:28,350 --> 00:49:32,000 And that is less than infinity. 885 00:49:32,000 --> 00:49:33,960 So we proved it. 886 00:49:33,960 --> 00:49:40,350 So if you get asked to prove f is O of g, what you do 887 00:49:40,350 --> 00:49:44,860 is you take the limit of f over g as x goes to infinity 888 00:49:44,860 --> 00:49:47,871 and show that it doesn't diverge. 889 00:49:47,871 --> 00:49:48,530 All right. 890 00:49:48,530 --> 00:49:52,258 Let's do another example. 891 00:49:52,258 --> 00:49:55,400 In this case we'll show that f is not O of g. 892 00:50:02,270 --> 00:50:06,232 x squared is not O of x. 893 00:50:06,232 --> 00:50:08,360 Of course, x squared grows faster than x, 894 00:50:08,360 --> 00:50:09,783 but let's see why not. 895 00:50:12,670 --> 00:50:16,010 Well we take the limit as x goes to infinity 896 00:50:16,010 --> 00:50:21,130 of x squared over x. 897 00:50:21,130 --> 00:50:23,920 And what is that limit? 898 00:50:23,920 --> 00:50:25,870 Infinity. 899 00:50:25,870 --> 00:50:28,360 And so it can't be true that it's x squared 900 00:50:28,360 --> 00:50:31,541 is O of x, because it has to be less than infinity. 901 00:50:31,541 --> 00:50:32,296 Yeah? 902 00:50:32,296 --> 00:50:32,962 AUDIENCE: Sorry. 903 00:50:32,962 --> 00:50:33,819 I missed it. 904 00:50:33,819 --> 00:50:34,360 What's alpha? 905 00:50:37,227 --> 00:50:38,060 PROFESSOR: Infinity. 906 00:50:41,180 --> 00:50:41,770 Sorry. 907 00:50:41,770 --> 00:50:42,050 Infinity. 908 00:50:42,050 --> 00:50:42,350 There we go. 909 00:50:42,350 --> 00:50:43,808 That's important in the definition. 910 00:50:43,808 --> 00:50:44,763 Yep. 911 00:50:44,763 --> 00:50:45,263 Good. 912 00:50:48,890 --> 00:50:49,390 All right. 913 00:50:49,390 --> 00:50:52,190 What about this? 914 00:50:52,190 --> 00:50:59,450 Is x squared equal O of a million times x? 915 00:51:04,750 --> 00:51:05,630 Yes? 916 00:51:05,630 --> 00:51:07,811 No? 917 00:51:07,811 --> 00:51:08,560 What do you think? 918 00:51:12,100 --> 00:51:14,166 This looks pretty darn big. 919 00:51:14,166 --> 00:51:15,470 AUDIENCE: It's a constant. 920 00:51:15,470 --> 00:51:17,750 PROFESSOR: That a constant. 921 00:51:17,750 --> 00:51:23,670 So in the limit, as x goes to infinity, this over that 922 00:51:23,670 --> 00:51:25,541 is infinite. 923 00:51:25,541 --> 00:51:26,040 All right. 924 00:51:26,040 --> 00:51:28,720 So no. 925 00:51:28,720 --> 00:51:32,250 Because the limit of x goes to infinity 926 00:51:32,250 --> 00:51:40,180 of x squared over 10 to the sixth x, that equals infinity. 927 00:51:40,180 --> 00:51:43,300 So the thing with this big O notation 928 00:51:43,300 --> 00:51:45,390 is you just ignore our constant factors. 929 00:51:45,390 --> 00:51:46,650 They don't do anything. 930 00:51:46,650 --> 00:51:47,914 Just forget about them. 931 00:51:51,690 --> 00:51:52,690 What about this? 932 00:51:52,690 --> 00:51:59,828 Is 10 to the sixth x equal O of x squared? 933 00:52:03,170 --> 00:52:05,010 Yes. 934 00:52:05,010 --> 00:52:06,819 Because you just ignore the constant. 935 00:52:06,819 --> 00:52:08,360 That's what the big O is for, and why 936 00:52:08,360 --> 00:52:10,810 it's used all the time in computer science. 937 00:52:10,810 --> 00:52:13,670 So yes, that's true. 938 00:52:13,670 --> 00:52:16,260 The proof is very simple. 939 00:52:16,260 --> 00:52:23,280 The limit as x goes to infinity of 100 x squared-- whoops. 940 00:52:23,280 --> 00:52:25,110 I could even put a square there. 941 00:52:25,110 --> 00:52:31,780 10 to the sixth x squared over x squared is 10 to the sixth. 942 00:52:31,780 --> 00:52:33,080 That's less than infinity. 943 00:52:37,000 --> 00:52:40,380 In fact, I could take any quadratic polynomial. 944 00:52:40,380 --> 00:52:47,410 x squared plus 100x plus 10 to the seventh is O of x squared. 945 00:52:49,970 --> 00:52:52,140 Because smaller order terms don't matter. 946 00:52:52,140 --> 00:52:56,880 The limit of this here over that in that case is 1. 947 00:52:56,880 --> 00:52:59,192 So it's less than infinity as x gets big. 948 00:53:02,050 --> 00:53:04,236 All right let's do a few more. 949 00:53:09,200 --> 00:53:10,660 This really is not so hard. 950 00:53:10,660 --> 00:53:12,770 It's a little dull. 951 00:53:12,770 --> 00:53:16,401 But you've got to know it for later. 952 00:53:21,460 --> 00:53:21,960 OK. 953 00:53:21,960 --> 00:53:24,740 I could take classes like 6046, and you'll never 954 00:53:24,740 --> 00:53:28,040 see any constants, because everything is things like big O 955 00:53:28,040 --> 00:53:31,040 and the other notation we'll talk about. 956 00:53:31,040 --> 00:53:32,050 What about this? 957 00:53:32,050 --> 00:53:37,490 X to the 10th equal O of e to the x. 958 00:53:40,720 --> 00:53:43,175 Is x to the 10 O of e to the x? 959 00:53:46,390 --> 00:53:48,740 Yeah, it is. 960 00:53:48,740 --> 00:53:49,870 So this is a theorem. 961 00:53:53,250 --> 00:53:55,240 Proof. 962 00:53:55,240 --> 00:53:57,730 Limit as x goes to infinity. 963 00:53:57,730 --> 00:54:00,680 x to the 10 over e to the x. 964 00:54:00,680 --> 00:54:03,185 That equals 0, which is certainly less than infinity. 965 00:54:05,810 --> 00:54:06,310 All right. 966 00:54:06,310 --> 00:54:08,070 Now the reason this stuff is useful 967 00:54:08,070 --> 00:54:11,310 when you're doing the analysis of algorithms 968 00:54:11,310 --> 00:54:13,590 is because when you're talking about things 969 00:54:13,590 --> 00:54:17,410 like matrix multiplication algorithms or things like that, 970 00:54:17,410 --> 00:54:20,580 the actual running time depends on the machine you're 971 00:54:20,580 --> 00:54:24,950 dealing with-- the machine characteristics-- details 972 00:54:24,950 --> 00:54:27,097 in how you count steps of the algorithm. 973 00:54:27,097 --> 00:54:28,805 For example, doing matrix multiplication, 974 00:54:28,805 --> 00:54:33,160 do you count multiply different than you count plus addition? 975 00:54:33,160 --> 00:54:37,440 And if you start getting caught up in all those details 976 00:54:37,440 --> 00:54:39,880 you lose the important fact of the algorithm. 977 00:54:39,880 --> 00:54:41,440 For example, matrix multiplication-- 978 00:54:41,440 --> 00:54:47,320 the elementary algorithm takes order O of n cubed steps. 979 00:54:47,320 --> 00:54:48,930 And that's the important fact. 980 00:54:48,930 --> 00:54:53,070 And it tells you that if you double the size of the matrix 981 00:54:53,070 --> 00:54:55,960 the running time will increase by at most a factor of eight 982 00:54:55,960 --> 00:54:58,890 in the limit as n gets large. 983 00:54:58,890 --> 00:55:03,300 And so you might write things like the time 984 00:55:03,300 --> 00:55:08,450 to multiply n by n matrices. 985 00:55:12,810 --> 00:55:16,990 You might call that t of n, and then state that is O of n 986 00:55:16,990 --> 00:55:19,390 cubed. 987 00:55:19,390 --> 00:55:19,890 All right. 988 00:55:19,890 --> 00:55:21,970 And you don't have to worry about what computer 989 00:55:21,970 --> 00:55:24,470 it's running on, exactly how you're 990 00:55:24,470 --> 00:55:27,580 counting the details of what a step is or what time is. 991 00:55:27,580 --> 00:55:30,350 The important thing is that it's growing 992 00:55:30,350 --> 00:55:35,490 at most as a cubic of the size of the matrices. 993 00:55:35,490 --> 00:55:41,730 And so in 6046 and 6006 you will spend lots of time 994 00:55:41,730 --> 00:55:44,040 proving that things are the running time, 995 00:55:44,040 --> 00:55:50,313 or the size is O of some function of the input size. 996 00:55:50,313 --> 00:55:50,812 All right. 997 00:55:53,780 --> 00:55:55,340 Any questions? 998 00:55:55,340 --> 00:55:55,845 Yeah. 999 00:55:55,845 --> 00:55:56,720 AUDIENCE: [INAUDIBLE] 1000 00:56:05,484 --> 00:56:06,150 PROFESSOR: Yeah. 1001 00:56:06,150 --> 00:56:08,580 It gets all dicey if you do oscillatory things. 1002 00:56:08,580 --> 00:56:10,350 And it depends how you define it. 1003 00:56:10,350 --> 00:56:13,360 So we're going to stay away from that 1004 00:56:13,360 --> 00:56:15,730 and just stick with this definition. 1005 00:56:15,730 --> 00:56:18,280 So if this guy oscillates-- like f 1006 00:56:18,280 --> 00:56:21,660 is a sine of x, sine of x is O of x. 1007 00:56:21,660 --> 00:56:22,160 All right. 1008 00:56:22,160 --> 00:56:24,060 It doesn't have to converge. 1009 00:56:24,060 --> 00:56:27,380 But as long as the ratio is less than infinity. 1010 00:56:27,380 --> 00:56:29,444 AUDIENCE: [INAUDIBLE] 1011 00:56:29,444 --> 00:56:30,110 PROFESSOR: Yeah. 1012 00:56:30,110 --> 00:56:31,500 Everything you do. 1013 00:56:31,500 --> 00:56:33,250 Maybe you'll see sine functions sometimes. 1014 00:56:33,250 --> 00:56:34,708 But everything you do in algorithms 1015 00:56:34,708 --> 00:56:36,350 is going to be growing monotonically. 1016 00:56:36,350 --> 00:56:36,850 Yeah. 1017 00:56:36,850 --> 00:56:40,660 Nothing-- no wacky stuff in math usually. 1018 00:56:40,660 --> 00:56:42,790 Any other questions? 1019 00:56:42,790 --> 00:56:43,555 Yeah. 1020 00:56:43,555 --> 00:56:45,980 AUDIENCE: [INAUDIBLE] sort of comparing 1021 00:56:45,980 --> 00:56:48,890 something that's the same magnitude that you go off 1022 00:56:48,890 --> 00:56:49,784 into infinity. 1023 00:56:49,784 --> 00:56:50,450 PROFESSOR: Yeah. 1024 00:56:50,450 --> 00:56:52,006 It's upper bounded. 1025 00:56:52,006 --> 00:56:52,880 So it's not the same. 1026 00:56:52,880 --> 00:56:54,296 We'll get to the same in a minute. 1027 00:56:54,296 --> 00:56:55,310 But it's upper bounded. 1028 00:56:55,310 --> 00:56:58,950 f is upper bounded by g up to a fixed constant 1029 00:56:58,950 --> 00:57:00,820 as you go to infinity. 1030 00:57:00,820 --> 00:57:04,949 And all constants get washed away by O. Yeah. 1031 00:57:04,949 --> 00:57:05,824 AUDIENCE: [INAUDIBLE] 1032 00:57:08,850 --> 00:57:10,840 PROFESSOR: Ah, why is this true? 1033 00:57:10,840 --> 00:57:13,920 Well technically we'd have to go back to calculus 1034 00:57:13,920 --> 00:57:16,510 and use L'Hopital's rule or something like that, 1035 00:57:16,510 --> 00:57:20,520 because this function exponential grows a lot faster 1036 00:57:20,520 --> 00:57:21,370 than x to the tenth. 1037 00:57:21,370 --> 00:57:23,620 So L'Hopital's rule is you take the derivative of this 1038 00:57:23,620 --> 00:57:24,900 over the derivative of that. 1039 00:57:24,900 --> 00:57:27,850 Then you'd have x to the ninth over e to the x. 1040 00:57:27,850 --> 00:57:29,780 You do it nine more times. 1041 00:57:29,780 --> 00:57:33,150 And you'd get 10 factorial over e to the x. 1042 00:57:33,150 --> 00:57:35,000 And that limit is zero. 1043 00:57:35,000 --> 00:57:39,150 So that's how you'd actually do it using L'Hopital's rule. 1044 00:57:39,150 --> 00:57:40,240 Yep. 1045 00:57:40,240 --> 00:57:42,420 Any polynomial grows slower than any exponential. 1046 00:57:45,380 --> 00:57:46,090 All right. 1047 00:57:46,090 --> 00:57:50,940 Let's now do some examples that can get you screwed up. 1048 00:57:53,800 --> 00:57:56,790 What about this one? 1049 00:57:56,790 --> 00:58:01,311 Is 4 to the x O to 2 to the x? 1050 00:58:06,900 --> 00:58:10,180 Is that true? 1051 00:58:10,180 --> 00:58:11,830 No, it's not true. 1052 00:58:11,830 --> 00:58:13,710 I mean, the mistake you might make 1053 00:58:13,710 --> 00:58:16,940 is say, oh, 4 and 2, 4 is only double 2. 1054 00:58:16,940 --> 00:58:18,750 Big O wipes out constant factors. 1055 00:58:18,750 --> 00:58:20,360 So the answer is yes. 1056 00:58:20,360 --> 00:58:21,740 That would be bad. 1057 00:58:21,740 --> 00:58:24,770 Better to look at the limit. 1058 00:58:24,770 --> 00:58:27,760 So we'll state the correct theorem-- 4 to the x 1059 00:58:27,760 --> 00:58:30,970 is not O of 2 to the x. 1060 00:58:30,970 --> 00:58:35,590 And the proof is obtained by looking at the limit 1061 00:58:35,590 --> 00:58:40,060 as x goes to infinity of 4 to the x over 2 to the x. 1062 00:58:40,060 --> 00:58:43,660 That is just the limit 4 to the x over 2 to the x 1063 00:58:43,660 --> 00:58:45,000 is 2 to the x. 1064 00:58:45,000 --> 00:58:47,730 That's infinity. 1065 00:58:47,730 --> 00:58:49,556 So the limit is not bounded. 1066 00:58:49,556 --> 00:58:50,510 All right? 1067 00:58:50,510 --> 00:58:53,701 So it is not big O there. 1068 00:58:53,701 --> 00:58:54,380 All right. 1069 00:58:54,380 --> 00:58:55,060 Here is one. 1070 00:58:57,770 --> 00:59:00,270 Is 10 O of 1? 1071 00:59:05,230 --> 00:59:08,790 I've purposely written it this way. 1072 00:59:08,790 --> 00:59:10,940 Yes, it is. 1073 00:59:10,940 --> 00:59:13,770 And in fact the interpretation here 1074 00:59:13,770 --> 00:59:15,570 is that you've got some function f 1075 00:59:15,570 --> 00:59:18,310 of x that's just always equal to 10, 1076 00:59:18,310 --> 00:59:22,550 and some function g of x that's always equal to 1. 1077 00:59:22,550 --> 00:59:26,070 And then it is true in this case that f of x is O of g of x. 1078 00:59:28,851 --> 00:59:29,350 All right. 1079 00:59:29,350 --> 00:59:36,020 But any constant function is O of any other constant function. 1080 00:59:36,020 --> 00:59:37,690 We're going to revisit this in a nastier 1081 00:59:37,690 --> 00:59:40,895 scenario in a little bit. 1082 00:59:40,895 --> 00:59:41,395 OK. 1083 00:59:45,490 --> 00:59:50,670 Sometimes you'll see notation like this. 1084 00:59:50,670 --> 00:59:53,890 H of n-- in fact, we saw this earlier-- 1085 00:59:53,890 --> 01:00:00,770 is the log of n plus delta plus O of 1 over n. 1086 01:00:00,770 --> 01:00:04,310 When we wrote out the formula for the n'th harmonic number, 1087 01:00:04,310 --> 01:00:08,260 it was log of n plus Euler's constant plus 1088 01:00:08,260 --> 01:00:11,200 something like 1 over n, constant times 1 over n. 1089 01:00:11,200 --> 01:00:13,750 And then some even smaller terms. 1090 01:00:13,750 --> 01:00:15,390 And so people will write it like this. 1091 01:00:15,390 --> 01:00:19,840 And it tells you that the error terms grow no faster 1092 01:00:19,840 --> 01:00:22,260 than a constant times 1 over n. 1093 01:00:22,260 --> 01:00:25,400 Technically this is the wrong way to write it. 1094 01:00:25,400 --> 01:00:29,260 But everybody does it, so you can too. 1095 01:00:29,260 --> 01:00:31,320 What it means is this. 1096 01:00:31,320 --> 01:00:36,881 H of n minus ln of n minus delta is O of 1 over n. 1097 01:00:36,881 --> 01:00:37,380 All right. 1098 01:00:37,380 --> 01:00:40,050 That's the correct way to write it, 1099 01:00:40,050 --> 01:00:43,790 because you're taking the ratio of this over that. 1100 01:00:43,790 --> 01:00:45,540 This is how people will do it. 1101 01:00:45,540 --> 01:00:46,040 All right. 1102 01:00:46,040 --> 01:00:50,260 So just make sure you understand that, what it means 1103 01:00:50,260 --> 01:00:52,070 when you put it over there. 1104 01:00:52,070 --> 01:00:54,150 Same thing with tilde notation. 1105 01:00:54,150 --> 01:01:00,230 People will write this-- H of n is tilde ln of n plus Euler's 1106 01:01:00,230 --> 01:01:01,360 constant. 1107 01:01:01,360 --> 01:01:05,360 The right way to write it is Hn minus Euler's constant 1108 01:01:05,360 --> 01:01:08,720 is tilde ln of n. 1109 01:01:08,720 --> 01:01:13,190 Now can anybody tell me why this is really not 1110 01:01:13,190 --> 01:01:14,570 a good thing to do? 1111 01:01:14,570 --> 01:01:16,320 And you think of how things get really 1112 01:01:16,320 --> 01:01:20,996 screwed up if you allow to start doing this? 1113 01:01:20,996 --> 01:01:22,370 Can you think of anything that--? 1114 01:01:25,489 --> 01:01:26,280 What if I did this? 1115 01:01:26,280 --> 01:01:27,093 Is this true? 1116 01:01:31,431 --> 01:01:31,930 10. 1117 01:01:35,070 --> 01:01:37,400 The n'th harmonic is harmonic number 1118 01:01:37,400 --> 01:01:41,180 is tilde of log of n plus 10. 1119 01:01:41,180 --> 01:01:41,760 Is that true? 1120 01:01:44,280 --> 01:01:46,050 Think about that. 1121 01:01:46,050 --> 01:01:48,247 People are shaking their heads. 1122 01:01:48,247 --> 01:01:49,330 I mean how can it be true? 1123 01:01:49,330 --> 01:01:51,090 Because we know this is. 1124 01:01:51,090 --> 01:01:53,700 We know that's what it is. 1125 01:01:53,700 --> 01:01:55,730 In fact, this is true. 1126 01:01:55,730 --> 01:01:59,000 I can even make it a million. 1127 01:01:59,000 --> 01:02:00,470 10 to the sixth here. 1128 01:02:00,470 --> 01:02:02,530 It's true. 1129 01:02:02,530 --> 01:02:08,560 Because the ratio of this over that in the limit is what? 1130 01:02:11,160 --> 01:02:12,360 1. 1131 01:02:12,360 --> 01:02:16,091 And that's all I need for tilde. 1132 01:02:16,091 --> 01:02:16,590 All right. 1133 01:02:16,590 --> 01:02:21,730 So when I wrote this, everybody knew what I meant. 1134 01:02:21,730 --> 01:02:24,960 But I could write this and be just as true mathematically. 1135 01:02:24,960 --> 01:02:27,640 And so you've got to be sort of careful about this. 1136 01:02:27,640 --> 01:02:29,840 Really, the right way to do it is this, 1137 01:02:29,840 --> 01:02:31,880 because now we're taking off that term, 1138 01:02:31,880 --> 01:02:33,820 and then it's-- actually I did this wrong. 1139 01:02:33,820 --> 01:02:34,860 I should've put the [INAUDIBLE]. 1140 01:02:34,860 --> 01:02:35,200 Whoops. 1141 01:02:35,200 --> 01:02:36,408 I should've done it this way. 1142 01:02:36,408 --> 01:02:37,490 Let me rewrite that. 1143 01:02:37,490 --> 01:02:40,710 The right way to do it is H of n-- yeah-- is this. 1144 01:02:40,710 --> 01:02:42,560 You put the small term out over here. 1145 01:02:42,560 --> 01:02:43,740 That's the right way. 1146 01:02:43,740 --> 01:02:46,380 Because now it's not true that it's 10 to the sixth out 1147 01:02:46,380 --> 01:02:52,050 here-- all right-- for the ratio of that over this guy. 1148 01:02:52,050 --> 01:02:52,550 All right. 1149 01:02:52,550 --> 01:02:53,740 So you can do it. 1150 01:02:53,740 --> 01:02:55,750 But be careful, because you might 1151 01:02:55,750 --> 01:02:57,790 write wrong things that technically 1152 01:02:57,790 --> 01:02:59,400 would fit the definition. 1153 01:02:59,400 --> 01:03:03,040 Same thing with big O. Same problem there. 1154 01:03:03,040 --> 01:03:06,365 Any questions about that? 1155 01:03:10,160 --> 01:03:12,080 All right. 1156 01:03:12,080 --> 01:03:12,580 All right. 1157 01:03:12,580 --> 01:03:17,780 Now one thing that people do all the time that you cannot do is 1158 01:03:17,780 --> 01:03:20,132 to use big O as a lower bound. 1159 01:03:22,760 --> 01:03:23,370 All right. 1160 01:03:23,370 --> 01:03:26,710 So that's one abuse that we won't-- you'll get marked wrong 1161 01:03:26,710 --> 01:03:31,380 for doing that, even though famous researchers will do it, 1162 01:03:31,380 --> 01:03:33,754 and you'll probably even have a professor do it sometime. 1163 01:03:37,280 --> 01:03:39,760 So you may not do this. 1164 01:03:39,760 --> 01:03:44,270 f of x is bigger than or equal to O of g of x. 1165 01:03:44,270 --> 01:03:45,123 That is meaningless. 1166 01:03:50,180 --> 01:03:54,440 Because the whole point of big O is that it's an upper bound. 1167 01:03:54,440 --> 01:03:57,230 So you can't use it as a lower bound. 1168 01:03:57,230 --> 01:03:58,670 And the reason you can't do it is 1169 01:03:58,670 --> 01:04:03,820 because there is another symbol to do what you want to do. 1170 01:04:03,820 --> 01:04:07,960 And that's called the omega symbol. 1171 01:04:07,960 --> 01:04:09,495 And it's written like this. 1172 01:04:12,380 --> 01:04:15,810 It's a capital omega. 1173 01:04:15,810 --> 01:04:24,020 And it's if the limit as x goes to infinity of f of x over g 1174 01:04:24,020 --> 01:04:28,640 of x is greater than zero. 1175 01:04:28,640 --> 01:04:29,210 OK. 1176 01:04:29,210 --> 01:04:31,500 So now we're getting the lower bound version. 1177 01:04:31,500 --> 01:04:37,355 In fact it's just the opposite of big O. 1178 01:04:37,355 --> 01:04:39,080 In fact, we'll state a theorem. 1179 01:04:39,080 --> 01:04:40,060 Not hard to prove. 1180 01:04:40,060 --> 01:04:41,800 We won't do it. 1181 01:04:41,800 --> 01:04:50,210 f of x equals O of g of x if and only if g of x 1182 01:04:50,210 --> 01:04:54,120 equals big omega of f of x. 1183 01:04:57,370 --> 01:05:01,280 In other words, f grows no faster than g 1184 01:05:01,280 --> 01:05:06,590 if and only if g grows at least as fast as f. 1185 01:05:06,590 --> 01:05:07,640 One's an upper bound one. 1186 01:05:07,640 --> 01:05:09,010 One's a lower bound. 1187 01:05:09,010 --> 01:05:11,430 And you've just got to use the symbol the right way. 1188 01:05:11,430 --> 01:05:13,070 Now you can do this. 1189 01:05:13,070 --> 01:05:19,620 You can write f of x bigger than or equal to omega g of x. 1190 01:05:19,620 --> 01:05:21,750 That's OK. 1191 01:05:21,750 --> 01:05:22,250 All right? 1192 01:05:22,250 --> 01:05:24,130 That's all right to do. 1193 01:05:24,130 --> 01:05:24,630 All right. 1194 01:05:24,630 --> 01:05:25,588 Let's do some examples. 1195 01:05:29,910 --> 01:05:36,360 So x squared is omega of x, because it grows faster than x. 1196 01:05:36,360 --> 01:05:39,910 2 to the x is omega of x squared. 1197 01:05:54,200 --> 01:05:55,960 All right. 1198 01:05:55,960 --> 01:06:06,260 x over 100 is omega of 100x plus 25, 1199 01:06:06,260 --> 01:06:08,580 because constants don't matter. 1200 01:06:08,580 --> 01:06:10,970 x over 100 grows at least as fast 1201 01:06:10,970 --> 01:06:14,940 as 100x does in terms, because we're measuring the growth. 1202 01:06:14,940 --> 01:06:17,670 So constants go away. 1203 01:06:17,670 --> 01:06:20,830 If you want to say the running time of that algorithm 1204 01:06:20,830 --> 01:06:25,590 is at least quadratic, you would write T of n 1205 01:06:25,590 --> 01:06:28,502 is omega n squared. 1206 01:06:28,502 --> 01:06:29,190 All right. 1207 01:06:29,190 --> 01:06:33,310 And that says that the running time is at least n squared. 1208 01:06:33,310 --> 01:06:37,570 Any questions on big omega? 1209 01:06:37,570 --> 01:06:42,380 Not too hard once you have big O. It's just the opposite. 1210 01:06:42,380 --> 01:06:46,890 All right the next symbol is the version 1211 01:06:46,890 --> 01:06:49,020 of equality, where you're bigger-- at least as big 1212 01:06:49,020 --> 01:06:51,240 as, and at most as big as. 1213 01:06:51,240 --> 01:06:55,180 There's a special symbol for that. 1214 01:06:55,180 --> 01:06:56,585 So in that case we use theta. 1215 01:07:02,160 --> 01:07:06,210 And we say that f of x equals theta 1216 01:07:06,210 --> 01:07:15,130 of g of x if the limit is both bigger than 0 1217 01:07:15,130 --> 01:07:19,280 and less than infinity. 1218 01:07:19,280 --> 01:07:19,780 All right. 1219 01:07:19,780 --> 01:07:24,400 So it's just a shorthand way of saying big O and big omega. 1220 01:07:24,400 --> 01:07:25,400 That's what theta means. 1221 01:07:25,400 --> 01:07:28,720 It just both hold true. 1222 01:07:28,720 --> 01:07:29,220 All right. 1223 01:07:29,220 --> 01:07:31,430 And that's a theorem which is not hard to prove, 1224 01:07:31,430 --> 01:07:32,990 but we won't do it. 1225 01:07:32,990 --> 01:07:41,280 f of x equals theta of g of x if and only f of the x 1226 01:07:41,280 --> 01:07:49,770 equals O of g of x and f of x equals omega g of x. 1227 01:07:53,130 --> 01:07:53,650 All right. 1228 01:07:53,650 --> 01:07:55,845 So let's do some examples of theta. 1229 01:08:09,710 --> 01:08:18,680 So for example, 10x cubed minus 20x plus 1 is more easily 1230 01:08:18,680 --> 01:08:24,340 written as theta of x cubed-- because the constants don't 1231 01:08:24,340 --> 01:08:24,840 matter. 1232 01:08:24,840 --> 01:08:27,319 The low order terms don't matter. 1233 01:08:27,319 --> 01:08:28,859 What about this? 1234 01:08:28,859 --> 01:08:34,460 Is x over log of x, is that theta of x? 1235 01:08:37,400 --> 01:08:38,760 x over log of x. 1236 01:08:38,760 --> 01:08:41,500 Is that theta of x? 1237 01:08:41,500 --> 01:08:44,979 People are nodding their heads. 1238 01:08:44,979 --> 01:08:46,880 Hmm. 1239 01:08:46,880 --> 01:08:47,750 Let's see. 1240 01:08:47,750 --> 01:08:48,319 Let's check. 1241 01:08:51,859 --> 01:08:57,560 The limit as x goes to infinity of x over log 1242 01:08:57,560 --> 01:09:01,660 of x divided by x. 1243 01:09:01,660 --> 01:09:02,920 Well, the x's cancel. 1244 01:09:02,920 --> 01:09:11,240 That's the limit as x goes to infinity of 1 over log of x. 1245 01:09:11,240 --> 01:09:13,399 What's that? 1246 01:09:13,399 --> 01:09:15,460 0. 1247 01:09:15,460 --> 01:09:16,640 Uh-oh. 1248 01:09:16,640 --> 01:09:18,830 it is not theta. 1249 01:09:18,830 --> 01:09:22,300 I got to be bigger than zero. 1250 01:09:22,300 --> 01:09:27,880 In fact, this grows more slowly than that-- 1251 01:09:27,880 --> 01:09:30,250 strictly more slowly. 1252 01:09:30,250 --> 01:09:31,930 All right. 1253 01:09:31,930 --> 01:09:36,020 A little more slowly, but strictly more slowly. 1254 01:09:36,020 --> 01:09:36,520 All right. 1255 01:09:36,520 --> 01:09:39,729 If I use for an algorithm, if you 1256 01:09:39,729 --> 01:09:43,680 want to say the algorithm runs in quadratic time-- namely 1257 01:09:43,680 --> 01:09:46,100 at least quadratic time, and at most quadratic time-- then 1258 01:09:46,100 --> 01:09:51,166 you'd say t of n is theta of n squared. 1259 01:09:51,166 --> 01:09:52,292 So let me write that. 1260 01:09:55,190 --> 01:10:04,560 So t of n equals theta n squared means t grows 1261 01:10:04,560 --> 01:10:14,094 quadratically in n-- both upper and lower bound. 1262 01:10:14,094 --> 01:10:15,056 OK? 1263 01:10:15,056 --> 01:10:27,690 So for these three guys, to summarize-- sort of you 1264 01:10:27,690 --> 01:10:39,070 can keep track of them pretty simply-- O means less than 1265 01:10:39,070 --> 01:10:40,030 or equal. 1266 01:10:40,030 --> 01:10:43,572 Omega means greater than or equal. 1267 01:10:43,572 --> 01:10:47,198 Theta means equal up to constant factors. 1268 01:10:55,870 --> 01:10:59,000 Now there's two more symbols here. 1269 01:10:59,000 --> 01:11:03,622 And they correspond very naturally to this set-up. 1270 01:11:03,622 --> 01:11:05,830 What two symbols are missing from here that would you 1271 01:11:05,830 --> 01:11:08,650 naturally add to here? 1272 01:11:08,650 --> 01:11:09,150 Yeah. 1273 01:11:09,150 --> 01:11:11,130 Less than and greater than. 1274 01:11:11,130 --> 01:11:15,620 So less than is little o. 1275 01:11:15,620 --> 01:11:19,430 Greater than is little omega. 1276 01:11:19,430 --> 01:11:24,710 And less than means it's less than or equal, but not equal. 1277 01:11:24,710 --> 01:11:28,276 And this means greater than or equal, not equal. 1278 01:11:28,276 --> 01:11:30,150 And let me put them up over here and give you 1279 01:11:30,150 --> 01:11:31,108 the formal definitions. 1280 01:11:34,852 --> 01:11:35,352 Eraser. 1281 01:11:52,240 --> 01:11:52,740 OK. 1282 01:11:52,740 --> 01:11:55,120 So little o. 1283 01:12:00,770 --> 01:12:04,280 as we have f of x equals little o of g 1284 01:12:04,280 --> 01:12:18,310 x if the limit of f of x over g of x equals 0. 1285 01:12:18,310 --> 01:12:20,810 So f is growing strictly smaller than g, 1286 01:12:20,810 --> 01:12:24,680 so that when I take the ratio, the limit goes to 0. 1287 01:12:24,680 --> 01:12:26,477 And the reverse is little omega. 1288 01:12:30,860 --> 01:12:35,880 And we say that f of x is little omega-- whoops-- 1289 01:12:35,880 --> 01:12:42,770 of g of x if this is infinity. 1290 01:12:42,770 --> 01:12:46,430 Because now f is growing strictly faster than g, 1291 01:12:46,430 --> 01:12:51,110 so I take the limit of the ratio, and it goes to infinity. 1292 01:12:51,110 --> 01:12:55,394 All right so we can do some simple examples. 1293 01:12:55,394 --> 01:12:57,310 Then we're almost done with all this notation. 1294 01:13:09,520 --> 01:13:10,680 What about this one? 1295 01:13:10,680 --> 01:13:16,709 x over ln of x-- we just looked at it-- and x. 1296 01:13:16,709 --> 01:13:18,176 What symbol do I put there? 1297 01:13:21,600 --> 01:13:24,870 What symbol's missing here? 1298 01:13:24,870 --> 01:13:26,060 Little o. 1299 01:13:26,060 --> 01:13:27,890 This grows strictly smaller than that. 1300 01:13:27,890 --> 01:13:31,390 If I took the ratio, and I took the limit, we got 0. 1301 01:13:31,390 --> 01:13:33,510 So that's a little o. 1302 01:13:33,510 --> 01:13:35,810 OK. 1303 01:13:35,810 --> 01:13:37,340 Is this true? 1304 01:13:37,340 --> 01:13:40,427 x over 100-- is that little o of x? 1305 01:13:44,050 --> 01:13:46,410 No. 1306 01:13:46,410 --> 01:13:48,520 The limit of the ratio is 1 over 100. 1307 01:13:48,520 --> 01:13:49,590 That's bigger than 0. 1308 01:13:49,590 --> 01:13:51,270 Constants don't matter. 1309 01:13:51,270 --> 01:13:51,770 All right. 1310 01:13:51,770 --> 01:13:54,530 So what symbol would go here? 1311 01:13:54,530 --> 01:13:56,060 Theta goes here. 1312 01:13:56,060 --> 01:13:56,960 Good. 1313 01:13:56,960 --> 01:13:58,310 Also big O and big omega. 1314 01:13:58,310 --> 01:14:01,311 But theta captures everything. 1315 01:14:01,311 --> 01:14:01,810 All right. 1316 01:14:01,810 --> 01:14:03,990 What symbol goes here? 1317 01:14:03,990 --> 01:14:08,330 x squared equals something x. 1318 01:14:08,330 --> 01:14:11,660 What symbol goes there? 1319 01:14:11,660 --> 01:14:12,635 Little omega. 1320 01:14:12,635 --> 01:14:14,260 It would also be true to put big omega, 1321 01:14:14,260 --> 01:14:16,320 but little omega tells you more. 1322 01:14:16,320 --> 01:14:21,021 Because the limit of x squared over x goes to infinity. 1323 01:14:21,021 --> 01:14:21,520 OK. 1324 01:14:21,520 --> 01:14:24,760 Any questions about these things? 1325 01:14:24,760 --> 01:14:28,690 So a natural thing on the midterm is we do some of that, 1326 01:14:28,690 --> 01:14:29,710 for example. 1327 01:14:29,710 --> 01:14:30,410 All right? 1328 01:14:30,410 --> 01:14:33,040 And you'll certainly see some of that on homework. 1329 01:14:33,040 --> 01:14:35,520 You might see some of that on the test. 1330 01:14:35,520 --> 01:14:37,690 You'll certainly see all this stuff-- little omega 1331 01:14:37,690 --> 01:14:41,020 not very often in 6046 and later algorithms courses. 1332 01:14:41,020 --> 01:14:43,970 But all the rest you'll see there. 1333 01:14:43,970 --> 01:14:46,230 Any questions? 1334 01:14:46,230 --> 01:14:46,860 All right. 1335 01:14:46,860 --> 01:14:49,760 Now I'm going to show you something 1336 01:14:49,760 --> 01:14:52,020 that is sort of scary. 1337 01:14:52,020 --> 01:14:52,562 Yeah. 1338 01:14:52,562 --> 01:14:53,978 AUDIENCE: Why do you say that it's 1339 01:14:53,978 --> 01:14:55,671 equal to zero when you said it's less 1340 01:14:55,671 --> 01:15:01,450 than [INAUDIBLE] equals sign. 1341 01:15:01,450 --> 01:15:02,820 PROFESSOR: Which equals? 1342 01:15:02,820 --> 01:15:05,580 AUDIENCE: You said little omega is less than. 1343 01:15:05,580 --> 01:15:08,296 PROFESSOR: Little omega, it corresponds to a greater 1344 01:15:08,296 --> 01:15:11,650 than, which means a greater than or equal to, 1345 01:15:11,650 --> 01:15:14,840 but not an equal to. 1346 01:15:14,840 --> 01:15:17,510 And the way we can see that is looking at the definitions 1347 01:15:17,510 --> 01:15:25,705 here in the greater than or equal to is the big omega. 1348 01:15:25,705 --> 01:15:31,850 And that just says you're bigger than 0. 1349 01:15:31,850 --> 01:15:32,350 Ah. 1350 01:15:32,350 --> 01:15:33,280 Let's see. 1351 01:15:33,280 --> 01:15:35,350 All right. 1352 01:15:35,350 --> 01:15:37,680 So I'm bigger than or equal to is omega. 1353 01:15:37,680 --> 01:15:42,970 But I'm not equal to, which is theta. 1354 01:15:42,970 --> 01:15:46,940 So if I know that I'm this but not that, 1355 01:15:46,940 --> 01:15:51,460 the only conclusion is that I'm infinity in the ratio. 1356 01:15:51,460 --> 01:15:51,960 All right? 1357 01:15:51,960 --> 01:15:53,890 So that's another way of saying it. 1358 01:15:53,890 --> 01:15:55,940 That's why. 1359 01:15:55,940 --> 01:15:56,922 Any other questions? 1360 01:16:00,090 --> 01:16:00,590 All right. 1361 01:16:00,590 --> 01:16:02,048 Now I'm going to show you something 1362 01:16:02,048 --> 01:16:05,420 that is commonly done, and that many students will attempt 1363 01:16:05,420 --> 01:16:07,137 to do after seeing this notation, 1364 01:16:07,137 --> 01:16:08,720 because the notation is pretty simple. 1365 01:16:08,720 --> 01:16:09,428 Take your limits. 1366 01:16:09,428 --> 01:16:10,900 Everything goes fine. 1367 01:16:10,900 --> 01:16:13,290 Then you start cruising along with it. 1368 01:16:13,290 --> 01:16:15,490 So now I'm going to show you how to prove something 1369 01:16:15,490 --> 01:16:21,770 that's false using this notation in a way that people often do. 1370 01:16:21,770 --> 01:16:26,700 And the hope is by showing you, you won't do it. 1371 01:16:26,700 --> 01:16:31,090 It will confuse you, which is why sometimes we 1372 01:16:31,090 --> 01:16:32,480 worry about showing you. 1373 01:16:32,480 --> 01:16:48,420 But let f of i-- f of n-- equal the sum i equals 1 to n of i. 1374 01:16:48,420 --> 01:16:51,600 Now we all know what that is, right? 1375 01:16:51,600 --> 01:16:52,700 All right. 1376 01:16:52,700 --> 01:16:59,456 So I'm going to prove to you that f of n is O of n. 1377 01:17:02,310 --> 01:17:06,460 Now what really-- what should be here instead of n? 1378 01:17:06,460 --> 01:17:07,980 n squared. 1379 01:17:07,980 --> 01:17:10,090 So n squared can't be O of n. 1380 01:17:10,090 --> 01:17:12,000 So this can't be true. 1381 01:17:12,000 --> 01:17:12,500 All right. 1382 01:17:12,500 --> 01:17:15,130 Well let's see how we do it. 1383 01:17:17,570 --> 01:17:18,070 All right. 1384 01:17:18,070 --> 01:17:31,280 So the false proof is by induction on n. 1385 01:17:31,280 --> 01:17:39,820 My induction hypothesis is p of n is going to be that f of n 1386 01:17:39,820 --> 01:17:41,910 is O of n. 1387 01:17:41,910 --> 01:17:42,410 All right? 1388 01:17:42,410 --> 01:17:45,020 That's what we, when we want to prove something by induction, 1389 01:17:45,020 --> 01:17:46,480 typically that's what you do. 1390 01:17:46,480 --> 01:17:49,365 Becomes the induction hypothesis. 1391 01:17:49,365 --> 01:17:50,531 Let's look at the base case. 1392 01:17:54,690 --> 01:18:03,012 Well f of 1 is 1, and 1 is O of 1 surely. 1393 01:18:03,012 --> 01:18:03,850 Right? 1394 01:18:03,850 --> 01:18:06,990 Even 10 was O of 1. 1395 01:18:06,990 --> 01:18:07,490 OK. 1396 01:18:19,420 --> 01:18:19,920 All right. 1397 01:18:19,920 --> 01:18:21,426 Now we do the inductive step. 1398 01:18:28,030 --> 01:18:36,405 We assume p n is true to prove that p n plus 1 is true. 1399 01:18:39,260 --> 01:18:46,850 Well p n means that f of n is O of n. 1400 01:18:46,850 --> 01:18:49,980 Now I look at f of n plus 1. 1401 01:18:49,980 --> 01:18:53,630 That equals the sum of the first n plus 1 number. 1402 01:18:53,630 --> 01:18:59,640 So that will be f of n plus n plus 1. 1403 01:18:59,640 --> 01:19:04,000 The induction hypothesis says this is O of n. 1404 01:19:04,000 --> 01:19:05,620 Clearly this is O of n. 1405 01:19:08,720 --> 01:19:10,830 Well I got O of n plus O of n. 1406 01:19:10,830 --> 01:19:12,385 That's at most twice O of n. 1407 01:19:16,490 --> 01:19:18,630 And constants don't matter. 1408 01:19:18,630 --> 01:19:20,121 So that's O of n. 1409 01:19:26,020 --> 01:19:26,520 All right. 1410 01:19:26,520 --> 01:19:31,680 This should begin to cause panic. 1411 01:19:31,680 --> 01:19:32,900 Is induction wrong? 1412 01:19:32,900 --> 01:19:35,520 What's going on with the big O? 1413 01:19:35,520 --> 01:19:37,350 You will see this done all the time. 1414 01:19:37,350 --> 01:19:40,990 People would do this kind of an argument. 1415 01:19:40,990 --> 01:19:44,430 Looks pretty good, right? 1416 01:19:44,430 --> 01:19:48,356 Can anybody see where I got off track? 1417 01:19:48,356 --> 01:19:49,980 This is a really hard one to figure out 1418 01:19:49,980 --> 01:19:51,310 where things went wrong. 1419 01:19:51,310 --> 01:19:52,254 Yeah? 1420 01:19:52,254 --> 01:19:53,906 AUDIENCE: One of them might be that you 1421 01:19:53,906 --> 01:20:00,458 might be applying O of n to numbers which really you 1422 01:20:00,458 --> 01:20:05,040 really apply asymptotic notation to functions. 1423 01:20:05,040 --> 01:20:06,390 PROFESSOR: Great. 1424 01:20:06,390 --> 01:20:08,060 That's a great observation. 1425 01:20:08,060 --> 01:20:11,700 Asymptotic notation only works for functions. 1426 01:20:11,700 --> 01:20:15,460 Now here when we say 1 is O of 1, 1427 01:20:15,460 --> 01:20:19,600 well, you could think of it as f of x being 1-- the function-- 1428 01:20:19,600 --> 01:20:20,240 and so forth. 1429 01:20:20,240 --> 01:20:21,480 So that's OK. 1430 01:20:21,480 --> 01:20:22,730 That's a great point. 1431 01:20:22,730 --> 01:20:26,999 Now let's figure out using that how we got in trouble. 1432 01:20:26,999 --> 01:20:28,040 We're not quite done yet. 1433 01:20:28,040 --> 01:20:29,670 That's a great observation. 1434 01:20:29,670 --> 01:20:32,160 But where's the step that's wrong? 1435 01:20:35,870 --> 01:20:36,590 Oh, no. 1436 01:20:36,590 --> 01:20:38,750 2 times O of n is O of n. 1437 01:20:38,750 --> 01:20:43,190 If I have a function that's f is O of g, twice f is O of g. 1438 01:20:43,190 --> 01:20:44,078 Yeah? 1439 01:20:44,078 --> 01:20:47,752 AUDIENCE: It's the end of n equals 1 [INAUDIBLE]. 1440 01:20:47,752 --> 01:20:48,460 PROFESSOR: Is it? 1441 01:20:48,460 --> 01:20:50,371 So what's the problem now? 1442 01:20:50,371 --> 01:20:52,830 AUDIENCE: [INAUDIBLE] 1443 01:20:52,830 --> 01:20:56,100 PROFESSOR: Well f of n plus 1-- this statement is true, 1444 01:20:56,100 --> 01:21:03,400 because f of n plus 1 is the sum of i equals 1 to n plus 1 of i. 1445 01:21:03,400 --> 01:21:07,360 That's 1 plus 2 plus n plus n plus 1. 1446 01:21:07,360 --> 01:21:10,630 And this is f of n. 1447 01:21:10,630 --> 01:21:11,532 So that's OK. 1448 01:21:19,010 --> 01:21:19,970 Yeah. 1449 01:21:19,970 --> 01:21:24,404 AUDIENCE: [INAUDIBLE] that function. 1450 01:21:24,404 --> 01:21:25,070 PROFESSOR: Yeah. 1451 01:21:25,070 --> 01:21:28,820 You know, you're getting closer. 1452 01:21:28,820 --> 01:21:32,740 Yeah that's a little flaky, because I've just 1453 01:21:32,740 --> 01:21:34,950 got a single value saying it's O of one. 1454 01:21:34,950 --> 01:21:38,120 But we sort of argued before that 10 was O of 1. 1455 01:21:38,120 --> 01:21:40,762 Now realize a function behind here that matters. 1456 01:21:40,762 --> 01:21:41,970 So you're on the right trail. 1457 01:21:41,970 --> 01:21:44,160 But there's an even bigger whopper hiding. 1458 01:21:44,160 --> 01:21:44,984 Yeah. 1459 01:21:44,984 --> 01:21:46,159 AUDIENCE: [INAUDIBLE] 1460 01:21:46,159 --> 01:21:46,950 PROFESSOR: Oh yeah. 1461 01:21:46,950 --> 01:21:51,130 This is really, really bad. 1462 01:21:51,130 --> 01:21:52,520 All right. 1463 01:21:52,520 --> 01:21:56,770 So now explain to me why this is really bad what I did here. 1464 01:21:56,770 --> 01:21:59,904 AUDIENCE: You didn't need the function [INAUDIBLE]. 1465 01:21:59,904 --> 01:22:00,570 PROFESSOR: Yeah. 1466 01:22:00,570 --> 01:22:02,840 And why isn't-- this looks like a function. 1467 01:22:02,840 --> 01:22:03,938 Why isn't it a function? 1468 01:22:07,010 --> 01:22:07,740 It's not. 1469 01:22:07,740 --> 01:22:09,450 But it looks like one. 1470 01:22:09,450 --> 01:22:10,760 f of n sure looks like one. 1471 01:22:10,760 --> 01:22:14,128 Why is it not a function when it's sitting in this thing? 1472 01:22:16,870 --> 01:22:19,730 This P of n, right? 1473 01:22:19,730 --> 01:22:23,350 Because I've fixed the value of n here. 1474 01:22:23,350 --> 01:22:25,870 And so this is now just a scalar. 1475 01:22:25,870 --> 01:22:34,020 In fact, you know, I could state the following-- f of a million, 1476 01:22:34,020 --> 01:22:38,930 right, is O of 1, because this is really some function H 1477 01:22:38,930 --> 01:22:41,930 of x that always is this value. 1478 01:22:41,930 --> 01:22:44,470 So the difference between a scalar and a function. 1479 01:22:44,470 --> 01:22:47,710 And this is just so nasty looking, because we see f of n. 1480 01:22:47,710 --> 01:22:49,140 That's a function. 1481 01:22:49,140 --> 01:22:54,991 But you can never use big O in a predicate, 1482 01:22:54,991 --> 01:22:56,990 all right, because we've lost the function here. 1483 01:22:56,990 --> 01:23:00,690 This is just f valued at n period. 1484 01:23:00,690 --> 01:23:03,430 That single instance is all that's happened here. 1485 01:23:03,430 --> 01:23:05,910 It's not a function anymore. 1486 01:23:05,910 --> 01:23:06,790 All right. 1487 01:23:06,790 --> 01:23:09,480 If we had f n of x or something, that might be OK. 1488 01:23:09,480 --> 01:23:11,540 But there's no function left. 1489 01:23:11,540 --> 01:23:12,040 All right. 1490 01:23:12,040 --> 01:23:17,670 So never ever use asymptotic notation with inductive proofs, 1491 01:23:17,670 --> 01:23:20,240 because you will just invariably stick 1492 01:23:20,240 --> 01:23:23,150 big O into your predicate. 1493 01:23:23,150 --> 01:23:27,190 And you could prove all sorts of false things once you do that. 1494 01:23:27,190 --> 01:23:29,590 OK? 1495 01:23:29,590 --> 01:23:30,150 All right. 1496 01:23:30,150 --> 01:23:33,400 Never use asymptotic notation in induction or predicates. 1497 01:23:33,400 --> 01:23:34,950 Thanks.