diff -r 3a12e096f9a0 -r 3bf3f5bb067e videos/02-algo2.srt --- a/videos/02-algo2.srt Sun Oct 04 12:30:24 2020 +0100 +++ b/videos/02-algo2.srt Sun Oct 04 22:20:25 2020 +0100 @@ -1,16 +1,16 @@ 1 00:00:06,020 --> 00:00:09,945 -They come back after +Welcome back. After this disappointment 2 00:00:09,945 --> 00:00:14,115 -and case of over promising -and under achieving. +and case of over-promising +and under-achieving, 3 00:00:14,115 --> 00:00:17,295 -Let's have a look whether +let's have a look whether we can recover from that. 4 @@ -19,18 +19,18 @@ 5 00:00:20,535 --> 00:00:23,790 -Then we looked at this end -times vk expression and +When we looked at this +n-times regular expression, we 6 00:00:23,790 --> 00:00:27,330 -be able to represent +were not able to represent that directly. 7 00:00:27,330 --> 00:00:31,275 -We had two represented as a -sequence record expression. +We had to represent it as a +sequence regular expression. 8 00:00:31,275 --> 00:00:32,850 @@ -38,12 +38,12 @@ 9 00:00:32,850 --> 00:00:36,510 -So times one would be just a, +So times-one would be just a, 10 00:00:36,510 --> 00:00:40,595 -t, times two would -be a, and so on. +times-two would +be a o a, and so on. 11 00:00:40,595 --> 00:00:43,535 @@ -52,22 +52,22 @@ 12 00:00:43,535 --> 00:00:47,960 -N equals 13, the record +n equals 13, the regular expression becomes quite large. 13 00:00:47,960 --> 00:00:52,865 And now the functions -nullable and also derivative. +nullable and also derivative, 14 00:00:52,865 --> 00:00:56,360 -They need to traverse -this reg expression. +they need to traverse +this regular expression. 15 00:00:56,360 --> 00:00:59,060 -Remember this tree in sometimes +Remember this tree, sometimes, 16 00:00:59,060 --> 00:01:01,820 @@ -82,39 +82,39 @@ 18 00:01:04,535 --> 00:01:08,150 And in particular, because -our first reg expression was +our first regular expression was 19 00:01:08,150 --> 00:01:11,840 -actually not just a bot -a plus one. So b hat. +actually not just a, but +a + 1. So we had 20 00:01:11,840 --> 00:01:14,330 -In the case of 13, -we had a plus one, +in the case of 13, +we had a + 1, a + 1,... 21 00:01:14,330 --> 00:01:17,330 -a plus one a plus born 13 times. +a + 1... 13 times. 22 00:01:17,330 --> 00:01:20,150 -And this reg -expression just grows, +And this regular +expression just grows 23 00:01:20,150 --> 00:01:25,475 -stay in number n. Just to -show you this also encode, +with the number n. Just to +show you this also in code, 24 00:01:25,475 --> 00:01:28,115 -I'm Stern, This File rewarm +I'm in the file re1.sc, 25 00:01:28,115 --> 00:01:30,920 -and D and I have a size function. +and in the end I have a size function. 26 00:01:30,920 --> 00:01:33,140 @@ -123,22 +123,22 @@ 27 00:01:33,140 --> 00:01:36,215 -argument and produces in teacher. +argument and produces an integer. 28 00:01:36,215 --> 00:01:39,980 And essentially it takes -this rec expression scene as +this regular expression, seen as 29 00:01:39,980 --> 00:01:44,045 -a tree and count how many -nodes are in this tree. +a tree and counts how many +nodes there are in this tree. 30 00:01:44,045 --> 00:01:49,490 -And so if I take this even -one reg expression, this one, +And so if I take this EVIL1 +regular expression, this one, 31 00:01:49,490 --> 00:01:52,160 @@ -147,49 +147,49 @@ 32 00:01:52,160 --> 00:01:54,680 can already see -for any cross one, +for n = 1, 33 00:01:54,680 --> 00:01:56,540 the size of this -record expression is +record expression is 5 34 00:01:56,540 --> 00:01:59,615 -five and you see it +and you see it slowly increases. 35 00:01:59,615 --> 00:02:02,150 -And this 20 n equals 20. +And this 20, i.e. n = 20, 36 00:02:02,150 --> 00:02:07,100 -The size of this record -expression is SMOW already a 119. +the size of this regular +expression is now already 119. 37 00:02:07,100 --> 00:02:10,145 -So now the interesting -line as this one. +The interesting +line is this one. 38 00:02:10,145 --> 00:02:13,295 -Remember it when we +Remember, when we built the derivative, 39 00:02:13,295 --> 00:02:17,150 -very often parts of a reg +very often parts of a regular expression gets copied. 40 00:02:17,150 --> 00:02:19,280 -So if you have like EVA, +So if you have like EVIL1 41 00:02:19,280 --> 00:02:22,325 -one of 2019 nodes, +of 20, and you have 119 nodes, 42 00:02:22,325 --> 00:02:25,475 @@ -198,15 +198,15 @@ 43 00:02:25,475 --> 00:02:31,475 And we want to see what's the -resulting tree look like, +resulting tree look like, i.e. 44 00:02:31,475 --> 00:02:32,780 -how many nodes it has. +how many nodes does it have. 45 00:02:32,780 --> 00:02:34,985 -So I take here either one of 20 +So I take here EVIL1 of 20 46 00:02:34,985 --> 00:02:38,405 @@ -220,11 +220,11 @@ 48 00:02:43,210 --> 00:02:45,680 -Okay, that takes away. +Okay, that takes a while. 49 00:02:45,680 --> 00:02:48,410 -You see now this rec expression, +You see now this recular expression, 50 00:02:48,410 --> 00:02:52,280 @@ -239,7 +239,7 @@ 52 00:02:55,400 --> 00:02:58,430 traverse these trees with -a million plus nodes. +8 million plus nodes. 53 00:02:58,430 --> 00:03:01,400 @@ -257,8 +257,8 @@ 56 00:03:06,350 --> 00:03:09,050 -have an explicit and -times reg expression. +have an explicit +n-times regular expression. 57 00:03:09,050 --> 00:03:11,600 @@ -267,12 +267,12 @@ 58 00:03:11,600 --> 00:03:13,415 it to the sequence -reg expression, +regular expression, 59 00:03:13,415 --> 00:03:17,510 let's just have a single -wreck expression and times, +regular expression n-times, 60 00:03:17,510 --> 00:03:20,540 @@ -280,16 +280,16 @@ 61 00:03:20,540 --> 00:03:24,470 -a number and keeps that -regular expression Small. +a number, and keeps that +regular expression small. 62 00:03:24,470 --> 00:03:27,095 -I'm here in the fire V2, +I'm here in the file re2.sc, 63 00:03:27,095 --> 00:03:29,090 -which is also on Keats. +which is also on KEATS. 64 00:03:29,090 --> 00:03:32,570 @@ -298,40 +298,40 @@ 65 00:03:32,570 --> 00:03:33,860 -a wrecker expression for +a regular expression for 66 00:03:33,860 --> 00:03:36,770 -N times the optional -reg expression. +n-times. The optional +regular expression 67 00:03:36,770 --> 00:03:39,920 -Very leaf out at the -moment because this a +we leave out at the +moment because this a? 68 00:03:39,920 --> 00:03:41,975 -optional is represented as +is represented as 69 00:03:41,975 --> 00:03:44,645 -a plus one and doesn't -explain too much. +a + 1 and doesn't +expand too much. 70 00:03:44,645 --> 00:03:47,375 -The really the culprit -is this n times. +The real culprit +is this n-times. 71 00:03:47,375 --> 00:03:51,095 And instead of expanding -it n times, which has, +it n-times, we just 72 00:03:51,095 --> 00:03:54,275 -take here a wreck expression +take here a regular expression and a natural number, 73 @@ -347,7 +347,7 @@ 75 00:03:59,165 --> 00:04:01,370 But by adding that -reg expression, +regular expression, 76 00:04:01,370 --> 00:04:05,150 @@ -356,11 +356,11 @@ 77 00:04:05,150 --> 00:04:07,340 -derivative so that we have +derivative. So that we have 78 00:04:07,340 --> 00:04:10,205 -to now calculate next +to calculate next what they look like. 79 @@ -380,38 +380,38 @@ 82 00:04:19,580 --> 00:04:21,980 -R and B take in -times of this are, +r and we take it +n-times of this r, 83 00:04:21,980 --> 00:04:25,220 -then indicates if n equals 0, +then in case if n = 0, 84 00:04:25,220 --> 00:04:28,130 -we find that as the -one reg expression. +we definded that as the +1 regular expression. 85 00:04:28,130 --> 00:04:30,380 -If n equals one, +If n = 1, 86 00:04:30,380 --> 00:04:32,495 it will be just a -single copy of on. +single copy of r. 87 00:04:32,495 --> 00:04:33,725 -If n equals two, +If n = 2, 88 00:04:33,725 --> 00:04:35,270 -it will be two copies. +it will be two copies in sequence. 89 00:04:35,270 --> 00:04:39,260 -Sequence if three, we have +If three, we have three copies and so on. 90 @@ -421,7 +421,7 @@ 91 00:04:41,390 --> 00:04:44,285 -when these cases all nullable. +when are these cases all nullable. 92 00:04:44,285 --> 00:04:47,810 @@ -429,11 +429,11 @@ 93 00:04:47,810 --> 00:04:49,850 -then this will be defined as one, +then this will be defined as 1. 94 00:04:49,850 --> 00:04:52,100 -so one can match +So 1 can match the empty string. 95 @@ -443,24 +443,24 @@ 96 00:04:54,785 --> 00:04:57,725 -Okay, if any cross one, +Okay, if n = 1, 97 00:04:57,725 --> 00:05:00,470 -when can this reg expression +when can this regular expression match the empty string? 98 00:05:00,470 --> 00:05:02,000 -So vent should be nullable. +So when should this be nullable? 99 00:05:02,000 --> 00:05:07,535 -Well, if nullable of our holes, +Well, if nullable of r holds, 100 00:05:07,535 --> 00:05:09,860 -okay, so if I can match +If it can match the empty string, 101 @@ -475,11 +475,11 @@ 103 00:05:14,870 --> 00:05:16,265 -So these are now two copies of +So these are now two copies of r. 104 00:05:16,265 --> 00:05:20,690 -our well-posed copies need +Well, both copies need to match the empty string. 105 @@ -492,7 +492,7 @@ 107 00:05:25,774 --> 00:05:28,520 -Ok? Similarly, in the third case, +Similarly, in the third case, 108 00:05:28,520 --> 00:05:30,710 @@ -501,22 +501,22 @@ 109 00:05:30,710 --> 00:05:33,230 able to match the empty -string. Men, is that the case? +string. When is that the case? 110 00:05:33,230 --> 00:05:38,360 Well, if nullable of -our holes and so on. +r holds and so on. 111 00:05:38,360 --> 00:05:48,754 So we can actually define that -if n equals 0, then true. +if n = 0, then true, 112 00:05:48,754 --> 00:05:56,045 -Else we have to ask with -nullable of our holes. +else we have to ask whether +nullable of r holds. 113 00:05:56,045 --> 00:05:58,550 @@ -525,7 +525,7 @@ 114 00:05:58,550 --> 00:06:01,625 have to implement for -n times and nullable. +n-times and nullable. 115 00:06:01,625 --> 00:06:04,280 @@ -533,16 +533,16 @@ 116 00:06:04,280 --> 00:06:06,920 -the derivative of the n terms +the derivative of the n-times 117 00:06:06,920 --> 00:06:10,175 -reg expression. -It's not that easy. +regular expression +is not that easy. 118 00:06:10,175 --> 00:06:12,755 -So we have to look again +We have to look again how it was defined 119 @@ -552,12 +552,12 @@ 120 00:06:16,010 --> 00:06:18,380 -The voice, our +Otherwise, our algorithm will be again 121 00:06:18,380 --> 00:06:20,975 -quite slow if you don't +quite slow if we don't spot that pattern. 122 @@ -571,8 +571,8 @@ 124 00:06:26,240 --> 00:06:29,885 -then r n times most -defined as just one. +then r n-times was +defined as just 1. 125 00:06:29,885 --> 00:06:32,030