-
Notifications
You must be signed in to change notification settings - Fork 0
/
dsa_06_annihilators.html
843 lines (812 loc) · 43.2 KB
/
dsa_06_annihilators.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link href="css/fontawesome-free-5.15.4-web/css/all.css" rel="stylesheet">
<script src="lib/colorbrewer.v1.min.js" charset="utf-8"></script>
<script src="lib/colorStringStandalone.js" charset="utf-8"></script>
<script type="text/javascript" src="lib/jquery-2.2.4.min.js"></script>
<title>Design & Analysis: Algorithms</title>
<meta name="description" content="CS4851/6851 GSU class">
<meta name="author" content="Sergey M Plis">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<link rel="stylesheet" href="dist/reset.css">
<link rel="stylesheet" href="dist/reveal.css">
<!-- Code syntax highlighting -->
<link rel="stylesheet" href="plugin/highlight/monokai.css" id="highlight-theme">
<!-- <link rel="stylesheet" href="lib/css/zenburn.css"> -->
<link rel="stylesheet" href="css/custom.css">
<link rel="stylesheet" href="dist/theme/aml.css" id="theme">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.scss';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
</head>
<body>
<div class="reveal">
<!-- In between the <div="reveal"> and the <div class="slides">-->
<!-- <header style="position: absolute; top: 10px; left: 100px; z-index: 500; font-size:100px;background-color: rgba(0,0,0,0); text-align: center !important"></header> -->
<!-- In between the <div="reveal"> and the <div class="slides">-->
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<section>
<p>
<h2>Design & Analysis: Algorithms</h2>
<h1>06: Annihilators </h1>
<p>
</section>
<section>
<h3>Outline of the lecture</h3>
<ul>
<li class="fragment roll-in"> Annihilators
<li class="fragment roll-in"> Examples
<li class="fragment roll-in"> Transformations
</ul>
</section>
<section>
<h2>Relative Ranking</h2>
<row>
<img style="border:0; box-shadow: 0px 0px 0px
rgba(150, 150, 255, 0.8); width:60%;"
class="reveal" src="figures/competition_time.gif" alt="competition">
<img style="border:0; box-shadow: 0px 0px 0px
rgba(150, 150, 255, 0.8); width:18%;"
class="reveal" src="figures/course_score01.png" alt="competition">
</row>
<div style="margin-top: -20px;">
Send me your private nicknames ASAP
</div>
</section>
</section>
<section>
<section data-background-iframe="https://www.youtube.com/embed/HkX1IlPhWdU?autoplay=1&controls=0&rel=0&modestbranding=1&showinfo=0&mute=0" data-vertical-align-bottom>
<h1 style="text-shadow: 4px 4px 4px #002b36; color: #f1f1f1">annihilators</h1>
</section>
<section>
<h3>Solving Recurrences using Annihilators</h3>
</section>
<section>
<h2>Goal</h2>
<ul>
<li class="fragment roll-in"> Recursion tree and
Master method are good tools for solving many recurrences
<li class="fragment roll-in"> However these
methods are limited
<li class="fragment roll-in"> They can’t help us
get guesses for recurrences like $T(n) = T(n − 1) + T(n − 2)$ (the
Fibonacci numbers <i class="fa fa-carrot"></i> )
<li class="fragment roll-in"> Annihilators will let us solve such
recurrences
</ul>
</section>
<section>
<h2>Intro to Annihilators</h2>
<ul>
<li class="fragment roll-in"> Suppose we are given a sequence of numbers $A = < a_0, a_1, a_2, \dots >$
<li class="fragment roll-in"> This might be a sequence like the Fibonacci numbers
<li class="fragment roll-in"> I.e. $A = < a_0, a_1, a_2, \dots > = < T (1), T (2), T (3), \dots >$
</ul>
</section>
<section>
<h2>Annihilator Operators</h2>
<div class="fragment roll-in" style="text-align:left;">
We define three basic operations we can perform on this sequence:
</div>
<ol>
<li class="fragment roll-in"> Multiply the sequence by a constant: $cA = < ca_0, ca_1, ca_2, \dots >$
<li class="fragment roll-in"> Shift the sequence to the left: ${\bf L}A = < a_1, a_2, a_3, \dots >$
<li class="fragment roll-in"> Add two sequences: if $A = < a_0, a_1, a_2, \dots >$ and $B = < b_0, b_1, b_2, \dots >$,
then $A + B = < a_0 + b_0, a_1 + b_1, a_2 + b_2, \dots >$
</ol>
</section>
<section>
<h2>Everything to know about operators</h2>
<table style="font-size:30px">
<tr>
<th>
Operator
</th>
<th>
Definition
</th>
</tr>
<tr>
<td>
addition
</td>
<td>
$(f+g)(n) \colon= f(n) + g(n)$
</td>
</tr>
<tr>
<td>
subtraction
</td>
<td>
$(f-g)(n) \colon= f(n) - g(n)$
</td>
</tr>
<tr>
<td>
multiplication
</td>
<td>
$(\alpha \cdot f)(n) \colon= \alpha \cdot (f(n))$
</td>
</tr>
<tr>
<td>
shift
</td>
<td>
$\bm{E}f(n) \colon= f(n+1)$
</td>
</tr>
<tr>
<td>
k-fold shift
</td>
<td>
$\bm{E}^kf(n) \colon= f(n+k)$
</td>
</tr>
<tr>
<td>
composition
</td>
<td>
$(\bm{X}+\bm{Y})f \colon= \bm{X}f+\bm{Y}f$
</td>
</tr>
<tr>
<td>
</td>
<td>
$(\bm{X}-\bm{Y})f \colon= \bm{X}f-\bm{Y}f$
</td>
</tr>
<tr>
<td>
</td>
<td>
$\bm{XY}f \colon= \bm{X}(\bm{Y}f) = \bm{Y}(\bm{X}f)$
</td>
</tr>
<tr>
<td>
distribution
</td>
<td>
$\bm{X}(f+g)\colon=\bm{X}f+\bm{X}g$
</td>
</tr>
</table>
</section>
<section>
<h2>Annihilator Description</h2>
<ul>
<li class="fragment roll-in">We first express
our recurrence as a sequence $T$
<li class="fragment roll-in">We use these three
operators to “annihilate” $T$ , i.e. make it all $0$’s
<li class="fragment roll-in">Key rule: can’t
multiply by the constant $0$
<li class="fragment roll-in">We can then
determine the solution to the recurrence from the sequence of
operations performed to annihilate $T$
</ul>
</section>
<section>
<h2>Example (1/2)</h2>
<ul>
<li class="fragment roll-in"> Consider the recurrence $T(n) = 2T(n − 1)$, $T (0) = 1$
<li class="fragment roll-in"> If we solve for the first few terms of this sequence, we can
see they are $< 2^0, 2^1, 2^2, 2^3, \dots >$
<li class="fragment roll-in">Thus this recurrence becomes the sequence:
$$T = < 2^0, 2^1, 2^2, 2^3, \dots >$$
</ul>
</section>
<section>
<h2>Example (2/2)</h2>
<div class="fragment roll-in" style="text-align:left;">
Let’s annihilate $T = < 2^0, 2^1, 2^2, 2^3, \dots >$
</div>
<div style="text-align:left;font-size:26pt;">
<ul>
<li class="fragment roll-in">Multiplying by a constant $c = 2$ gets:
$2T = < 2 \times 2^0, 2 \times 2^1, 2 \times 2^2, 2 \times 2^3, \dots >$
<li class="fragment roll-in"> $2T = < 2^1, 2^2, 2^3, 2^4, \dots >$
<li class="fragment roll-in">Shifting one place to the left gets ${\bf L}T = < 2^1, 2^2, 2^3, 2^4, \dots >$
<li class="fragment roll-in">Adding the sequence ${\bf L}T$ and $−2T$ gives:
<div style="margin-top: -20pt; margin-bottom: -20pt;">
\begin{align}
{\bf L}T − 2T & = < 2^1 − 2^1, 2^2 − 2^2, 2^3 − 2^3, \dots >\\
& = < 0, 0, 0, \dots >
\end{align}
</div>
<li class="fragment roll-in">The annihilator of $T$ is thus ${\bf L} − 2$
</ul>
</div>
</section>
<section>
<h2>Distributive Property</h2>
<ul>
<li class="fragment roll-in">The distributive property holds for these three operators
<li class="fragment roll-in">Thus can rewrite ${\bf L}T − 2T$ as $({\bf L} − 2)T$
<li class="fragment roll-in">The operator $({\bf L} − 2)$ annihilates $T$ (makes it the sequence
of all $0$’s)
<li class="fragment roll-in">Thus $({\bf L} − 2)$ is called the annihilator of $T$
</ul>
</section>
<section>
<h2>$0$, the “Forbidden Annihilator”</h2>
<ul>
<li class="fragment roll-in">Multiplication by $0$ will annihilate any sequence
<li class="fragment roll-in">Thus we disallow multiplication by $0$ as an operation
<li class="fragment roll-in">In particular, we disallow $(c−c) = 0$ for any $c$ as an annihilator
<li class="fragment roll-in">Must always have at least one ${\bf L}$ operator in any annihilator!
</ul>
</section>
<section>
<h2>Uniqueness</h2>
<ul>
<li class="fragment roll-in">An annihilator annihilates exactly one type of sequence
<li class="fragment roll-in">In general, the annihilator ${\bf L} − c$ annihilates any sequence of
the form $< a_0c^n >$
<li class="fragment roll-in">If we find the annihilator, we can find the type of sequence,
and thus solve the recurrence
<li class="fragment roll-in">We will need to use the base case for the recurrence to solve
for the constant $a_0$
</ul>
</section>
<section>
<h2>Example</h2>
<div class="fragment roll-in" style="text-align:left;">
If we apply operator $({\bf L} − 3)$ to sequence $T$ above, it fails to
annihilate $T$
</div>
<div style="font-size:26pt">
\begin{align}
({\bf L} − 3)T & \fragment{1}{= {\bf L}T + (-3)T}\\
& \fragment{2}{= < 2^1, 2^2, 2^3, \dots > + <-3\times 2^0, -3\times 2^1, \dots>}\\
& \fragment{3}{= < (2-3)\times 2^0, (2-3)\times 2^1, \dots >}\\
& \fragment{4}{= (2-3)T}\\
&\fragment{5}{= -T}
\end{align}
</div>
</section>
<section>
<h2>Example (II)</h2>
<div class="fragment roll-in" style="text-align:left;">
What does $({\bf L}−c)$ do to other sequences $A = < a_0d^n >$ when $< d \ne c >$:
</div>
<div style="font-size: 22pt;">
\begin{align}
({\bf L} - c)A & \fragment{1}{= ({\bf L}-c) < a_0, a_0d, a_0d^2, a_0d^3,\dots >}\\
& \fragment{2}{= {\bf L}< a_0, a_0d, a_0d^2, a_0d^3,\dots > - c< a_0, a_0d, a_0d^2, a_0d^3,\dots >}\\
&\fragment{3}{= < a_0d, a_0d^2, a_0d^3,\dots > - < ca_0, a_0d, ca_0d^2, ca_0d^3,\dots >}\\
&\fragment{4}{= < a_0d - ca_0, a_0d^2 - ca_0d, a_0d^3 - ca_0d^2, \dots >}\\
&\fragment{5}{= <(d-c) a_0, (d -c) a_0 d, (d-c)a_0d^2, \dots >}\\
&\fragment{6}{= (d-c) < a_0, a_0d, a_0 d^2, a_0 d^3, \dots >}\\
&\fragment{7}{= (d-c)A}\\
\end{align}
</div>
</section>
<section>
<h2>Uniqueness</h2>
<ul>
<li class="fragment roll-in">The last example
implies that an annihilator annihilates one
type of sequence, but does not annihilate
other types of sequences
<li class="fragment roll-in">Thus Annihilators
can help us classify sequences, and thereby
solve recurrences
</ul>
</section>
<section>
<h2>Lookup Table</h2>
<img style="border:0; box-shadow: 0px 0px 0px
rgba(150, 150, 255, 0.8); width:80%;"
class="reveal" src="figures/lookup_table_annihilators.svg" alt="Lookup Table Annihilators">
</section>
<section>
<h2>Example</h2>
<div class="fragment roll-in" style="text-align:left;">
First, calculate the annihilator:
</div>
<ul>
<li class="fragment roll-in">Recurrence: $T (n) = 4 \times T (n − 1)$, $T (0) = 2$
<li class="fragment roll-in">Sequence: $T = < 2, 2 \times 4, 2 \times 4^2, 2 \times 4^3, \cdots >$
<li class="fragment roll-in">Calculate the annihilator:
<ul>
<li class="fragment roll-in"> $\bm{E}T = < 2 \times 4, 2 \times 4^2, 2 \times 4^3, 2 \times 4^4, \cdots >$
<li class="fragment roll-in"> $4T = < 2 \times 4, 2 \times 4^2, 2 \times 4^3, 2 \times 4^4, \cdots >$
<li class="fragment roll-in"> Thus $\bm{E}T − 4T = < 0, 0, 0, \cdots >$
<li class="fragment roll-in"> And so $\bm{E} − 4$ is the annihilator
</ul>
</ul>
</section>
<section>
<h2>Example (II)</h2>
<div class="fragment roll-in" style="text-align:left;">
Now use the annihilator to solve the recurrence
</div>
<ul>
<li class="fragment roll-in">Look up the annihilator in the “Lookup Table”
<li class="fragment roll-in">The annihilator $\bm{E} − 4$ annihilates any sequence of
the form $< \alpha \cdot a^n >$
<li class="fragment roll-in">Thus $T (n) = \alpha 4^n$, but what is $\alpha$?
<li class="fragment roll-in">We know $T (0) = 2$, so $T (0) = \alpha \cdot 4^0 = 2$ and so $\alpha = 2$
<li class="fragment roll-in">Thus $T (n) = 2 \cdot 4^n$
</ul>
</section>
<section>
<h2>In Class Exercise <img style="border:0; box-shadow: 0px 0px 0px rgba(150, 150, 255, 1);" width="100"
src="figures/dolphin_swim.webp" alt="dolphin">
</h2>
<div class="fragment roll-in" style="text-align:left;">
Consider the recurrence $T (n) = 3 T (n − 1)$, $T (0) = 3$,
</div>
<ul style="font-size:26pt;">
<li class="fragment roll-in">Q1: Calculate $T (0)$,$T (1)$,$T (2)$ and $T (3)$ and write out the sequence $T$
<li class="fragment roll-in">Q2: Calculate $\bm{L}T$, and use it to compute the annihilator of $T$
<li class="fragment roll-in">Q3: Look up this annihilator in the lookup table to get the
general solution of the recurrence for $T (n)$
<li class="fragment roll-in">Q4: Now use the base case $T (0) = 3$ to solve for the constants in the general solution
</ul>
</section>
<section>
<h2>Multiple Operators 1/2</h2>
<ul>
<li class="fragment roll-in">We can apply multiple operators to a sequence
<li class="fragment roll-in">For example, we can multiply by the constant $c$ and then by
the constant $d$ to get the operator $cd$
<li class="fragment roll-in">We can also multiply by $c$ and then shift left to get $c\bm{L}T$ which
is the same as $\bm{L}cT$
<li class="fragment roll-in">We can also shift the sequence twice to the left to get $\bm{L}\bm{L}T$ which we’ll write in shorthand as $\bm{L}^2T$
</ul>
</section>
<section>
<h2>Multiple Operators 2/2</h2>
<ul>
<li class="fragment roll-in">We can string operators together to annihilate more complicated sequences
<li class="fragment roll-in">Consider: $T = < 2^0 + 3^0, 2^1 + 3^1, 2^2 + 3^2, \cdots >$
<li class="fragment roll-in">We know that $(\bm{L}−2)$ annihilates the powers of $2$ while leaving
the powers of $3$ essentially untouched
<li class="fragment roll-in">Similarly, $(\bm{L} − 3)$ annihilates the powers of $3$ while leaving
the powers of $2$ essentially untouched
<li class="fragment roll-in">Thus if we apply both operators, we’ll see that $(\bm{L} − 2)(\bm{L} − 3)$
annihilates the sequence $T$
</ul>
</section>
<section>
<h2>The Details</h2>
<ul>
<li class="fragment roll-in">Consider: $T = < a^0 + b^0, a^1 + b^1, a^2 + b^2, \cdots >$
<li class="fragment roll-in">$\bm{L}T = < a^1 + b^1, a^2 + b^2, a^3 + b^3, \cdots >$
<li class="fragment roll-in">$aT = < a^1 + a \cdot b^0, a^2 + a \cdot b^1, a^3 + a \cdot b^2, \cdots >$
<li class="fragment roll-in">$\bm{L}T − aT = < (b − a) b^0, (b − a) b^1, (b − a) b^2, \cdots >$
<li class="fragment roll-in">We know that $(\bm{L} − a)T$ annihilates the $a$ terms and multiplies the $b$ terms by $b − a$ (a constant)
<li class="fragment roll-in">$(\bm{L} − a)T = < (b − a)b^0, (b − a)b^1, (b − a)b^2, \cdots >$
<li class="fragment roll-in">And so $(\bm{L} − a)T$ is annihilated by $(\bm{L} − b)$
<li class="fragment roll-in">Thus the annihilator of $T$ is $(\bm{L} − b)(\bm{L} − a)$
</ul>
</section>
<section>
<h2>Key Point</h2>
<ul>
<li class="fragment roll-in">In general, the annihilator $(\bm{L} − a)(\bm{L} − b)$ (where $a \ne b$) will
annihilate only all sequences of the form $< \alpha_1 a^n + \alpha_2 b^n >$
<li class="fragment roll-in">We will often multiply out $(\bm{L} − a)(\bm{L} − b)$ to $\bm{L}^2 − (a + b)\bm{L} + ab$
<li class="fragment roll-in">Left as an exercise to show that $(\bm{L} − a)(\bm{L} − b)T$ is the same
as $(\bm{L}^2 − (a + b)\bm{L} + ab)T$
</ul>
</section>
<section>
<h2>Lookup Table</h2>
<img style="border:0; box-shadow: 0px 0px 0px
rgba(150, 150, 255, 0.8); width:80%;"
class="reveal" src="figures/lookup_table_annihilators.svg" alt="Lookup Table Annihilators">
</section>
<section data-background="figures/fibonacci-wave_t.gif" data-background-size="contain" data-vertical-align-top>
<h2>Fibonacci Sequence</h2>
<ul style="font-size: 26pt;">
<li class="fragment roll-in">We now know enough to solve the Fibonacci sequence
<li class="fragment roll-in">Recall the Fibonacci recurrence is $T (0) = 0$, $T (1) = 1$, and $T (n) = T (n − 1) + T (n − 2)$
<li class="fragment roll-in">Let $T_n$ be the $n^{th}$ element in the sequence
<li class="fragment roll-in">Then we’ve got:
\begin{align}
T &= < T_0, T_1, T_2, T_3, \cdots >\\
\bm{L}T &= < T_1, T_2, T_3, T_4, \cdots >\\
\bm{L}^2T &= < T_2, T_3, T_4, T_5, \cdots >\\
\end{align}
<li class="fragment roll-in">Thus $\bm{L}^2T − \bm{L}T − T = < 0, 0, 0, \cdots >$
<li class="fragment roll-in">In other words, $\bm{L}^2 − \bm{L} − 1$ is an annihilator for $T$
</ul>
</section>
<section>
<h2>Lookup Table</h2>
<img style="border:0; box-shadow: 0px 0px 0px
rgba(150, 150, 255, 0.8); width:80%;"
class="reveal" src="figures/lookup_table_annihilators.svg" alt="Lookup Table Annihilators">
</section>
<section>
<h2>Factoring</h2>
<ul>
<li class="fragment roll-in">$\bm{L}^2 − \bm{L}
− 1$ is an annihilator that is not in our lookup
table
<li class="fragment roll-in">However, we can
factor this annihilator (using the quadratic
formula) to get something similar to what’s in
the lookup table
<li class="fragment roll-in"> $\bm{L}^2 - \bm{L} - 1 = (\bm{L} - \phi)(\bm{L} - \hat\phi)$, where $\phi = \frac{1+\sqrt{5}}{2}$ and $\hat\phi = \frac{1-\sqrt{5}}{2}$
</ul>
</section>
<section data-background-iframe="https://www.youtube.com/embed/JXFGy10b7Js?autoplay=1&controls=0&rel=0&modestbranding=1&showinfo=0&mute=0closedcaptions=1" data-vertical-align-bottom>
</section>
<section>
<h2>Quadratic formula</h2>
<div class="fragment roll-in" style="text-align:left;">
High School Algebra Review:
</div>
<ul>
<li class="fragment roll-in">To factor something of the form $ax^2 + bx + c$, we use the
<em>Quadratic Formula</em>:
<li class="fragment roll-in">$ax^2 + bx + c$ factors into $(x - \phi)(x - \hat\phi)$, where:
\begin{align}
\phi & = \frac{-b+\sqrt{b^2 - 4 ac}}{2a}\\
\hat\phi & = \frac{-b-\sqrt{b^2 - 4 ac}}{2a}\\
\end{align}
</ul>
</section>
<section>
<h2>Factoring</h2>
<ul>
<li class="fragment roll-in">To factor: $\bm{L}^2 − \bm{L} − 1$
<li class="fragment roll-in">Rewrite: $1 \times \bm{L}^2 − 1 ∗ \bm{L} − 1$, $a = 1$, $b = −1$, $c = −1$
<li class="fragment roll-in">From Quadratic Formula: $\phi = \frac{1+\sqrt{5}}{2}$ and $\hat\phi = \frac{1-\sqrt{5}}{2}$
<li class="fragment roll-in">So $\bm{L}^2 − \bm{L} − 1$ factors to $(\bm{L} − \phi)(\bm{L} − \hat\phi)$
</ul>
</section>
<section>
<h2>Back to Fibonacci</h2>
<ul>
<li class="fragment roll-in">Recall the Fibonacci recurrence is $T(0) = 0$, $T(1) = 1$, and $T (n) = T (n − 1) + T (n − 2)$
<li class="fragment roll-in">We’ve shown the annihilator
for $T$ is $(\bm{L} − \phi)(\bm{L} − \hat\phi)$, where $\phi = \frac{1+\sqrt{5}}{2}$ and $\hat\phi = \frac{1-\sqrt{5}}{2}$
<li class="fragment roll-in">If we look this up in the “Lookup Table”, we see that the
sequence $T$ must be of the form $< c_1 \phi^n + c_2 \hat\phi^n >$
<li class="fragment roll-in">All we have left to do is solve for $c_1$ and $c_2$
<li class="fragment roll-in">Can use the base cases to solve for these
</ul>
</section>
<section>
<h2>Finding the Constants</h2>
<ul>
<li class="fragment roll-in">We know $T = < c_1 \phi^n + c_2\hat\phi^n >$, where $\phi = \frac{1+\sqrt{5}}{2}$ and $\hat\phi = \frac{1-\sqrt{5}}{2}$
<li class="fragment roll-in">We know
\begin{align}
T (0) &= c_1 + c_2 = 0 \\
T (1) &= c_1 \phi + c_2\hat\phi = 1 \\
\end{align}
<li class="fragment roll-in">We’ve got two equations and two unknowns
<li class="fragment roll-in">Can solve to get $c_1 = \frac{1}{\sqrt{5}}$ and $c_2 = -\frac{1}{\sqrt{5}}$
</ul>
</section>
<section>
<h2>The punchline</h2>
<ul>
<li class="fragment roll-in">Recall Fibonnaci recurrence: $T(0) = 0$, $T(1) = 1$, and $T(n) = T (n − 1) + T (n − 2)$
<li class="fragment roll-in">The final explicit formula for $T(n)$ is thus: $$T(n) = \frac{1}{\sqrt{5}}(\frac{1+\sqrt{5}}{2})^n - \frac{1}{\sqrt{5}}(\frac{1-\sqrt{5}}{2})^n$$
</ul>
<div class="fragment roll-in" style="text-align:left;">
Amazingly, $T(n)$ is always an integer, in spite of all of the square
roots in its formula.
</div>
</section>
<section>
<h2 style="text-shadow: 4px 4px 4px #002b36; color: #f1f1f1">the annihilators method</h2>
<ul>
<li class="fragment roll-in">Write down the
annihilator for the recurrence
<li class="fragment roll-in">Factor the
annihilator
<li class="fragment roll-in">Look up the
factored annihilator in the “Lookup Table” to get general solution
<li class="fragment roll-in">Solve for constants
of the general solution by using initial conditions
</ul>
</section>
<section>
<h2>Lookup Table</h2>
$$
(\bm{L} - a_0)^{b_0}(\bm{L} - a_1)^{b_1}\dots(\bm{L} - a_k)^{b_k}
$$
(where $a_i\ne a_j$, for $i\ne j$) annihilates only sequences of the form:
$$
< p_0(n)a_0^n + p_1(n)a_1^n + \dots p_k(n)a_k^n>
$$
where $p_i(n)$ is a polynomial of degree $b_i - 1$
</section>
<section data-background="figures/examples_national_archive.gif">
</section>
</section>
<section>
<section>
<h1>Examples</h1>
</section>
<section data-vertical-align-top>
<h2></h2>
<blockquote style="background-color: #93a1a1; color: #fdf6e3; width:100%; text-align:left;" class="fragment roll-in" >
$
(\bm{L} - a_0)^{b_0}(\bm{L} - a_1)^{b_1}\dots(\bm{L} - a_k)^{b_k}$<br>
$
< p_0(n)a_0^n + p_1(n)a_1^n + \dots p_k(n)a_k^n>
$
</blockquote>
<ul>
<li class="fragment roll-in">
Q: What does $(\bm{L} − 3)(\bm{L} − 2)(\bm{L} − 1)$ annihilate?
<li class="fragment roll-in">A: $< c_01^n + c_12^n + c_23^n >$
<li class="fragment roll-in">Q: What does $(\bm{L} − 3)^2(\bm{L} − 2)(\bm{L} − 1)$ annihilate?
<li class="fragment roll-in">A: $< c_01^n + c_12^n + (c_2n + c_3)3^n >$
<li class="fragment roll-in">Q: What does $(\bm{L} − 1)^4$ annihilate?
<li class="fragment roll-in">A: $(c_0n^3 + c_1n^2 + c_2n + c_3)1^n$
<li class="fragment roll-in">Q: What does $(\bm{L} − 1)^3(\bm{L} − 2)^2$ annihilate?
<li class="fragment roll-in">A: $(c_0n^2 + c_1n + c_2)1^n + (c_3n + c_4)2^n$
</ul>
</section>
<section>
<h2>Example 1</h2>
<div class="fragment roll-in" style="text-align:left; margin-top:-40px; width:100%;">
Consider the recurrence $T (n) = 2T (n − 1) − T (n − 2)$, $T (0) = 0$,
$T (1) = 1$. Note that:
\begin{align}
\bm{L}^2T &= < T_{n+2} >\\
& = < 2T_{n+1} - T_{n} >\\
\bm{L}T &= < T_{n+1} >\\
T & = < T_n >
\end{align}
</div>
<ul>
<li class="fragment roll-in">Thus $\bm{L}^2T − 2\bm{L}T + T = < 0 >$
<li class="fragment roll-in">So $\bm{L}^2 − 2\bm{L} + 1$ is the annihilator of $T$
</ul>
</section>
<section>
<div class="fragment roll-in" style="margin-left:-50px;text-align:left;width:100%;color: #268bd2;">
$T (n) = 2T (n − 1) − T (n − 2), T (0) = 0, T (1) = 1$
</div>
<ul style="font-size:28pt;">
<li class="fragment roll-in"><b>Write down the annihilator</b>: From the definition of the sequence, we can see that $\bm{L}^2T −2\bm{L}T +T = 0$, so the annihilator
is $\bm{L}^2 − 2\bm{L} + 1$
<li class="fragment roll-in"><b>Factor the annihilator</b>: We can factor by hand or using the
quadratic formula to get $\bm{L}^2 − 2\bm{L} + 1 = (\bm{L} − 1)^2$
<li class="fragment roll-in"><b>Look up to get general solution</b>: The annihilator $(\bm{L} − 1)^2$
annihilates sequences of the form $(c_0n + c_1)1^n$
<li class="fragment roll-in"><b>Solve for constants</b>: $T (0) = 0 = c_1$, $T (1) = 1 = c_0 + c_1$,
We’ve got two equations and two unknowns. Solving by
hand, we get that $c_0 = 1$, $c_1 = 0$. <b>Thus</b>: $T (n) = n$
</ul>
</section>
<section>
<h2>Example 2</h2>
<div class="fragment roll-in" style="text-align:left; margin-top:-40px; margin-bottom:-40px; width:100%;font-size:26pt;">
Consider the recurrence $ T (n) = 7T (n − 1) − 16T (n − 2) + 12T (n −
3)$, $T (0) = 1$,
$T (1) = 5$, $T (2) = 17$. Note that:
</div>
\begin{align}
\bm{L}^3T &\fragment{1}{= < T_{n+3} >}\\
& \fragment{2}{= < 7T_{n+2} - 16T_{n+1} + 12T_{n} >}\\
\bm{L}^2T &\fragment{3}{= < T_{n+2} >}\\
\bm{L}T &\fragment{4}{= < T_{n+1} >}\\
T & \fragment{5}{= < T_n >}
\end{align}
<ul style="font-size:26pt;margin-top:-40px;" class="fragment roll-in" data-fragment-index="6">
<li class="fragment roll-in">Thus $\bm{L}^3T -7\bm{L}^2T + 16\bm{L}T -12 T = < 0 >$
<li class="fragment roll-in">So $\bm{L}^3 -7\bm{L}^2 + 16\bm{L} - 12$ is the annihilator of $T$
</ul>
</section>
<section>
<div class="fragment roll-in" style="margin-left:-50px;text-align:left;width:100%;color: #268bd2;">
$ T (n) = 7T (n − 1) − 16T (n − 2) + 12T (n −
3)$, $T(0)=1$,
$T (1) = 5$, $T (2) = 17$.
</div>
<ul style="font-size:26pt;">
<li class="fragment roll-in"><b>Write down the annihilator</b>: From the definition of the
sequence $\bm{L}^3T − 7\bm{L}^2T + 16\bm{L}T − 12T = 0$,
so the annihilator is $\bm{L}3 − 7\bm{L}2 + 16\bm{L} − 12$
<li class="fragment roll-in"><b>Factor the annihilator</b>: We can factor by hand or using a
CAS $\bm{L}^3 −7\bm{L}^2 +16\bm{L}−12 = (\bm{L}−2)^2(\bm{L}−3)$
<li class="fragment roll-in"><b>Look up to get general solution</b>: $(\bm{L} − 2)^2(\bm{L} − 3)$ annihilates sequences $< (c_0n + c_1)2^n+c_2 3^n >$
<li class="fragment roll-in"><b>Solve for constants</b>: $T (0) = 1 = c_1 + c_2$, $T (1) = 5 = 2c_0 + 2c_1 + 3c_2$, $T (2) = 17 = 8c_0 + 4c_1 + 9c_2$. Three equations and three unknowns. Solving by hand, we get that $c_0 = 1$, $c_1 = 0$, $c_2 = 1$. <b>Thus</b>: $T (n) = n2^n + 3^n$
</ul>
</section>
<section>
<h2>At Home Exercise</h2>
<div class="fragment roll-in" style="text-align:left; margin-top:10px; width:100%;font-size:26pt;">
Consider the recurrence $T(n) = 6T (n − 1) − 9T (n − 2)$, $T (0) = 1$,
$T (1) = 6$
</div>
<ul>
<li class="fragment roll-in">Q1: What is the annihilator of this sequence?
<li class="fragment roll-in">Q2: What is the factored version of the annihilator?
<li class="fragment roll-in">Q3: What is the general solution for the recurrence?
<li class="fragment roll-in">Q4: What are the constants in this general solution?
</ul>
<div class="fragment roll-in" style="text-align:left; margin-top: 30px; width:100%;font-size:26pt;">
(Note: You can check that your general solution works for $T(2)$)
</div>
</section>
<section>
<h2>Assigned reading</h2>
<row>
<col60>
<img style="border:0; box-shadow: 0px 0px 0px rgba(150, 150, 255, 1);" width="40%"
src="figures/Algorithms-JeffE_cover.svg" alt="Jeff E">
</col60>
<col40>
<a href="https://jeffe.cs.illinois.edu/teaching/algorithms/notes/99-recurrences.pdf">Appendix II. Solving Recurrences</a><p>
</col40>
</row>
</section>
</section>
</section>
<section>
<h2>See you</h2>
Wednesday February 1st
</section>
</div>
</div>
<script src="dist/reveal.js"></script>
<!-- <link rel="stylesheet" href="lib/css/monokai.css"> -->
<script src="plugin/highlight/highlight.js"></script>
<script src="plugin/math/math.js"></script>
<script src="plugin/chalkboard/plugin.js"></script>
<script src="plugin/notes/notes.js"></script>
<script src="plugin/zoom/zoom.js"></script>
<script src="plugin/menu/menu.js"></script>
<script>
// Full list of configuration options available at:
// https://github.com/hakimel/reveal.js#configuration
let notes = document.querySelectorAll('aside.notes');
notes.forEach(n => {
let html = n.innerHTML;
html = html.trim().replace(/\n/g, '<br/>');
n.innerHTML = html;
});
Reveal.initialize({
// history: true,
hash: true,
margin: 0.01,
minScale: 0.01,
maxScale: 1.23,
menu: {
themes: true,
openSlideNumber: true,
openButton: false,
},
customcontrols: {
slideNumberCSS : 'position: fixed; display: block; right: 90px; top: auto; left: auto; width: 50px; bottom: 30px; z-index: 31; font-family: Helvetica, sans-serif; font-size: 12px; line-height: 1; padding: 5px; text-align: center; border-radius: 10px; background-color: rgba(128,128,128,.5)',
controls: [
{ icon: '<i class="fa fa-caret-left"></i>',
css: 'position: fixed; right: 60px; bottom: 30px; z-index: 30; font-size: 24px;',
action: 'Reveal.prev(); return false;'
},
{ icon: '<i class="fa fa-caret-right"></i>',
css: 'position: fixed; right: 30px; bottom: 30px; z-index: 30; font-size: 24px;',
action: 'Reveal.next(); return false;'
}
]
},
chalkboard: {
boardmarkerWidth: 1,
chalkWidth: 2,
chalkEffect: 1,
slideWidth: Reveal.width,
slideHeight: Reveal.height,
toggleNotesButton: false,
toggleChalkboardButton: false,
//src: "chalkboards/chalkboard_em2.json",
readOnly: false,
theme: "blackboard",
eraser: { src: "plugin/chalkboard/img/sponge.png", radius: 30},
},
math: {
mathjax: 'https://cdn.jsdelivr.net/gh/mathjax/mathjax@2.7.8/MathJax.js',
config: 'TeX-AMS_SVG-full',
// pass other options into `MathJax.Hub.Config()`
TeX: {
Macros: {
RR: '\\mathbb{R}',
PP: '\\mathbb{P}',
EE: '\\mathbb{E}',
NN: '\\mathbb{N}',
vth: '\\vec{\\theta}',
loss: '{\\cal l}',
hclass: '{\\cal H}',
CD: '{\\cal D}',
def: '\\stackrel{\\text{def}}{=}',
pag: ['\\text{pa}_{{\cal G}^{#1}}(#2)}', 2],
vec: ['\\boldsymbol{\\mathbf #1}', 1],
set: [ '\\left\\{#1 \\; : \\; #2\\right\\}', 2 ],
bm: ['\\boldsymbol{\\mathbf #1}', 1],
argmin: ['\\operatorname\{arg\\,min\\,\}'],
argmax: ['\\operatorname\{arg\\,max\\,\}'],
prob: ["\\mbox{#1$\\left(#2\\right)$}", 2],
},
loader: {load: ['[tex]/color']},
extensions: ["color.js"],
tex: {packages: {'[+]': ['color']}},
svg: {
fontCache: 'global'
}
}
},
plugins: [ RevealMath, RevealChalkboard, RevealHighlight, RevealNotes, RevealZoom, RevealMenu ],
});
Reveal.configure({ fragments: true }); // set false when developing to see everything at once
Reveal.configure({ slideNumber: true });
//Reveal.configure({ history: true });
Reveal.configure({ slideNumber: 'c / t' });
Reveal.addEventListener( 'darkside', function() {
document.getElementById('theme').setAttribute('href','dist/theme/aml_dark.css');
}, false );
Reveal.addEventListener( 'brightside', function() {
document.getElementById('theme').setAttribute('href','dist/theme/aml.css');
}, false );
</script>
<style type="text/css">
/* 1. Style header/footer <div> so they are positioned as desired. */
#header-left {
position: absolute;
top: 0%;
left: 0%;
}
#header-right {
position: absolute;
top: 0%;
right: 0%;
}
#footer-left {
position: absolute;
bottom: 0%;
left: 0%;
}
</style>
<!-- // 2. Create hidden header/footer -->
<div id="hidden" style="background; display:none;">
<div id="header">
<div id="header-left"><h4>CS4520</h4></div>
<div id="header-right"><h4>Algorithms</h4></div>
<div id="footer-left">
<img style="border:0; box-shadow: 0px 0px 0px rgba(150, 150, 255, 1);" width="100"
src="figures/flowchart.png" alt="robot learning">
</div>
</div>
</div>
<script type="text/javascript">
// 3. On Reveal.js ready event, copy header/footer <div> into each `.slide-background` <div>
var header = $('#header').html();
if ( window.location.search.match( /print-pdf/gi ) ) {
Reveal.addEventListener( 'ready', function( event ) {
$('.slide-background').append(header);
});
}
else {
$('div.reveal').append(header);
}
</script>
</body>
</html>