-
Notifications
You must be signed in to change notification settings - Fork 0
/
dsa_11_bucket.html
504 lines (470 loc) · 23.5 KB
/
dsa_11_bucket.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
<!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-6.2.1-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>11: How Fast To Sort</h1>
<p>
</section>
<section>
<h3>Outline of the lecture</h3>
<ul>
<li class="fragment roll-in"> Lower Bound for Sorting by Comparison
<li class="fragment roll-in"> Bucket Sort
</ul>
</section>
</section>
<section>
<section data-vertical-align-top data-background="figures/compare_scale.gif">
<h2>Lower Bound for Sorting by Comparison</h2>
</section>
<section>
<h2>How Fast Can We Sort?</h2>
<ul>
<li class="fragment roll-in" style="list-style:none;"><span class="fa-li"><i class="fa-regular fa-circle-question"></i></span> What is a lowerbound on the runtime of any sorting algorithm?
<li class="fragment roll-in">We know that $\Omega(n)$ is a trivial lowerbound
<li class="fragment roll-in">But all the algorithms we’ve seen so far are $O(n \log n)$ (or
$O(n^2)$), so is $\Omega(n \log n)$ a lowerbound?
</ul>
</section>
<section>
<h2><i class="fa-solid fa-scale-unbalanced-flip"></i> Comparison Sorts <i class="fa-solid fa-scale-unbalanced"></i></h2>
<ul>
<li class="fragment roll-in"><b>Definition</b>: An sorting algorithm is a comparison sort if the
sorted order they determine is based only on comparisons
between input elements.
<li class="fragment roll-in">Heapsort, mergesort, quicksort, bubblesort, and insertion sort
are all comparison sorts
<li class="fragment roll-in">We will show that any comparison sort must take $\Omega(n \log n)$
</ul>
<blockquote class="fragment roll-in" style="background-color: #93a1a1; color: #fdf6e3; font-size: 38px; width: 100%;">
$\Omega(g(n)) = \{f(n):$ there exist positive constants $c$ and $n_0$
such that $0 \leq cg(n) \leq f(n)$ for all $n \geq n_0\}$
</blockquote>
</section>
<section>
<h2><i class="fa-solid fa-scale-unbalanced-flip"></i> Comparisons</h2>
<ul>
<li class="fragment roll-in">Assume we have an input sequence $A = (a_1, a_2, . . . , a_n)$
<li class="fragment roll-in">In a comparison sort, we only perform tests of the form $a_i <
a_j$ , $a_i \leq a_j$ , $a_i = a_j$ , $a_i \geq a_j$ , or $a_i > a_j$ to determine the
relative order of all elements in $A$
<li class="fragment roll-in">We’ll assume that all elements are distinct, and so note that
the only comparison we need to make is $a_i \leq a_j$.
<li class="fragment roll-in">This comparison gives us a <i class="fa-solid fa-thumbs-up"></i> yes or <i class="fa-solid fa-thumbs-down"></i> no answer
</ul>
</section>
<section>
<h2>Decision Tree Model 1/2</h2>
<ul>
<li class="fragment roll-in">A decision tree is a full binary tree that gives the possible
sequences of comparisons made for a particular input array, $A$
<li class="fragment roll-in">Each internal node is labelled with the indices of the two
elements to be compared
<li class="fragment roll-in">Each leaf node gives a permutation of $A$
</ul>
</section>
<section>
<h2>Decision Tree Model 2/2</h2>
<ul>
<li class="fragment roll-in">The execution of the sorting algorithm corresponds to a path
from the root node to a leaf node in the tree.
<li class="fragment roll-in">We take the left child of the node if the comparison is $\leq$ and
we take the right child if the comparison is $>$
<li class="fragment roll-in">The internal nodes along this path give the comparisons
made by the algorithm, and the leaf node gives the output of the
sorting algorithm.
</uL>
</section>
<section>
<h2>Leaf Nodes <i class="fa-brands fa-pagelines"></i></h2>
<ul>
<li class="fragment roll-in">Any correct sorting algorithm must be able to produce each
possible permutation of the input
<li class="fragment roll-in">Thus, there must be at least $n!$ leaf nodes
<li class="fragment roll-in">The length of the longest path from the root node to a leaf
in this tree gives the worst case run time of the algorithm
(i.e. the height of the tree gives the worst case runtime)
</ul>
</section>
<section>
<h2>Example</h2>
<ul>
<li class="fragment roll-in">Consider the problem of sorting an array of size two: $A =
(a_1, a_2)$
<li class="fragment roll-in">Following is a decision tree for this problem.
<div align="center">
<img style="border:0; box-shadow: 0px 0px 0px rgba(150, 150, 255, 1); center;" width="50%"
src="figures/decision_tree_a1a2.svg" alt="decision tree a1a2">
</div>
</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>
<ul>
<li class="fragment roll-in">Give a decision tree for sorting an array of size three: $A = (a_1, a_2, a_3)$
<li class="fragment roll-in">What is the height? What is the number of leaf nodes?
</ul>
</section>
<section>
<h2>Height of Decision Tree</h2>
<ul>
<li class="fragment roll-in" style="list-style:none;"><span class="fa-li"><i class="fa-regular fa-circle-question"></i></span> What is the height of a binary tree with at least $n!$ leaf
nodes?
<li class="fragment roll-in" style="list-style:none;"><span class="fa-li"> <i class="fa-solid fa-a"></i></span> If $h$ is the height, we know that $2^h \geq n!$
<li class="fragment roll-in" style="list-style:none;">Taking $\log$ of both sides, we get $h \geq \log(n!)$
</ul>
</section>
<section>
<div id="header-right" style="margin-right: -120px; margin-top: -10px">
<img src="figures/log.svg" alt="L'Hopital" style="border:0; box-shadow: 0px 0px 0px rgba(150, 150, 255, 1); margin-bottom: -5%" width="300px" >
</div>
<h2>Height of Decision Tree</h2>
<ul>
<li class="fragment roll-in" style="list-style:none;"><span class="fa-li"><i class="fa-regular fa-circle-question"></i></span> What is $log(n!)$?
<li class="fragment roll-in" style="list-style:none;"><span class="fa-li"> <i class="fa-solid fa-a"></i></span> It is
\begin{align}
\log(n (n − 1) \dots 1) &\fragment{}{= \log n + \log(n − 1) + · · · + 0}\\
& \geq \frac{n}{2} \log(\frac{n}{2})\\
&\geq \frac{n}{2}(\log n − \log 2)\\
&= \Omega(n \log n)
\end{align}
</ul>
</section>
<section>
<h2>Take Away Points</h2>
<ul>
<li class="fragment roll-in">As proven, any comparison-based sorting algorithm takes $\Omega(n \log n)$ time
<li class="fragment roll-in">This does not mean that all sorting algorithms take $\Omega(n \log n)$ time
<li class="fragment roll-in">In fact, there are non comparison-based sorting algorithms which, under certain circumstances, are asymptotically faster.
</ul>
</section>
</section>
<section>
<section data-vertical-align-top data-background="figures/pile_of_papers.svg" data-background-size="contain">
<h2 style="margin-left: -500pt; margin-top: 70pt;">Bucket Sort</h2>
</section>
<section>
<h2><i class="fa-solid fa-bucket"></i><i class="fa-solid fa-bucket"></i><i class="fa-solid fa-bucket"></i></h2>
<ul>
<li class="fragment roll-in">Bucket sort assumes that the input is drawn from a uniform distribution over the range $[0, 1)$
<li class="fragment roll-in">Basic idea is to divide the interval $[0, 1)$ into $n$ equal size regions, or buckets
<li class="fragment roll-in">We expect that a small number of elements in $A$ will fall into each bucket
<li class="fragment roll-in">To get the output, we can sort the numbers in each bucket and just output the sorted buckets in order
</ul>
</section>
<section>
<h2>Implementation</h2>
<row style="width: 115%;">
<col50>
<pre class="python fragment roll-in" style="width: 99%; font-size: 12pt;"><code data-trim data-noescape data-line-numbers="*|5|7-8|10-13">
from math import floor
def bucketsort(seq):
n = len(seq)
bucketlist = [[] for x in range(n)]
for element in seq:
bucketlist[floor(n*element)].append(element)
r = []
for bucket in bucketlist:
if bucket:
ins_sort_rec(bucket, len(bucket)-1)
r += bucket
return r
</code></pre>
</col50>
<col50>
<pre class="python fragment roll-in" style="width: 99%; font-size: 12pt;"><code data-trim data-noescape data-line-numbers>
def ins_sort_rec(seq, i):
if i==0: return # Base case -- do nothing
ins_sort_rec(seq, i-1) # Sort 0..i-1
j = i # Start "walking" down
while j > 0 and seq[j-1] > seq[j]: # Look for OK spot
seq[j-1], seq[j] = seq[j], seq[j-1] # Keep moving seq[j] down
j -= 1 # Decrement j
</code></pre>
<pre class="python fragment roll-in" style="width: 99%; font-size: 12pt;"><code data-trim data-noescape data-line-numbers="|5,7,9,11">
t = np.random.rand(10000000)
tcopy = t.copy()
%time r = bucketsort(t)
CPU times: user 13.1 s, sys: 475 ms, total: 13.5 s
Wall time: 13.6 s
%time r = quicksort(tcopy)
CPU times: user 47.2 s, sys: 732 ms, total: 47.9 s
Wall time: 48.1 s
</code></pre>
</col50>
</row>
<dev class="slide-footer">
<a href="https://github.com/Apress/python-algorithms">insertion sort code comes from Chapter 4</a>
</dev>
</section>
<section>
<h2>Claim: runtime complexity</h2>
<ul>
<li class="fragment roll-in"><b>Claim</b>: If the input numbers are distributed uniformly over
the range $[0, 1)$, then Bucket sort takes expected time $O(n)$
<li class="fragment roll-in">Let $T(n)$ be the run time of bucket sort on a list of size $n$
<li class="fragment roll-in">Let $n_i$ be the random variable giving the number of elements in bucket $B[i]$
<li class="fragment roll-in" style="list-style: none;">
<blockquote style="text-align: center; background-color: #93a1a1; color: #fdf6e3; font-size: 42px; width: 110%;">
Then $T(n) = \Theta(n) + \sum_{i=0}^{n-1} O(n_i^2)$
</blockquote>
</ul>
</section>
<section>
<h2>Analysis</h2>
<ul style="margin-top: -30pt;">
<li class="fragment roll-in">We know $T(n) = \Theta(n) + \sum_{i=0}^{n-1} O(n_i^2)$
<li class="fragment roll-in">Taking expectation of both sides, we have
<div style="font-size: 22pt;">
\begin{align}
\prob{E}{T(n)} &= \prob{E}{\Theta(n) + \sum_{i=0}^{n-1} O(n_i^2)}\\
&= \prob{E}{\Theta(n)} + \sum_{i=0}^{n-1} \prob{E}{O(n_i^2)}\\
&= \Theta(n) + \sum_{i=0}^{n-1} O(\prob{E}{n_i^2})
\end{align}
</div>
<li class="fragment roll-in">The second step follows from linearity of expectation
<li class="fragment roll-in">The last step follows from it as well
for any constant $a$ and random variable $X$, $\prob{E}{aX} = a\prob{E}{X}$
</ul>
</section>
<section>
<h2>Analysis</h2>
<ul>
<li class="fragment roll-in">We claim that $\prob{E}{n_i^2} = 2 − 1/n$
<li class="fragment roll-in">To prove this, we define indicator random variables: $X_{ij} = 1$ if $A[j]$ falls in bucket $i$ and $0$ otherwise (defined for all $i$,
$0 \leq i \leq n − 1$ and $j$, $0 \leq j \leq n-1$)
<li class="fragment roll-in">Thus, $n_i = \sum_{j=0}^{n-1} X_{ij}$
<li class="fragment roll-in">We can now compute $\prob{E}{n^2_i}$ by
expanding the square and regrouping terms
</ul>
</section>
<section>
<h2 style="margin-bottom: -40pt;">Analysis</h2>
\begin{align}
\prob{E}{n^2_i} &\fragment{1}{=\prob{E}{(\sum_{j=0}^{n-1} X_{ij})^2}}\\
&\fragment{2}{=\prob{E}{\displaystyle\sum_{j=0}^{n-1}\displaystyle\sum_{k=1}^{n-1} X_{ij}X_{ik}}}\\
&\fragment{3}{=\prob{E}{\sum_{j=0}^{n-1} X_{ij}^2 + \displaystyle\sum_{0\leq j \leq n-1}\displaystyle\sum_{0\leq j \leq n-1, k\ne j} X_{ij}X_{ik}}}\\
&\fragment{4}{=\sum_{j=0}^{n-1}\prob{E}{X_{ij}^2} + \displaystyle\sum_{0\leq j \leq n-1}\displaystyle\sum_{0\leq j \leq n-1, k\ne j} \prob{E}{X_{ij}X_{ik}}}
\end{align}
</section>
<section>
<!-- <h2>Analysis</h2> -->
<ul>
<li class="fragment roll-in">We can evaluate the two sums separately. $X_{ij}$ is $1$ with probability $1/n$ and $0$ otherwise
<li class="fragment roll-in">Thus $\prob{E}{X_{ij}^2} = 1 \times (1/n) + 0 \times (1 − 1/n) = 1/n$
<li class="fragment roll-in">Where $k \ne j$, the random variables $X_{ij}$ and $X_{ik}$ are independent
<li class="fragment roll-in">For any two independent random variables $X$ and $Y$, $\prob{E}{XY} = \prob{E}{X}\prob{E}{Y}$
<li class="fragment roll-in">Thus we have that
$$
\prob{E}{X_{ij}X_{ik}} = \prob{E}{X_{ij}}\prob{E}{X_{ik}} = 1/n\times 1/n = 1/n^2
$$
</ul>
</section>
<section>
<div style="text-align: left;">
Substituting these two expected values back into our main
equation, we get:
</div>
\begin{align}
\prob{E}{n^2_i} &\fragment{1}{=\sum_{j=0}^{n-1}\prob{E}{X_{ij}^2} + \displaystyle\sum_{0\leq j \leq n-1}\displaystyle\sum_{0\leq j \leq n-1, k\ne j} \prob{E}{X_{ij}X_{ik}}}\\
&\fragment{2}{=\sum_{j=0}^{n-1}\frac{1}{n} + \displaystyle\sum_{0\leq j \leq n-1}\displaystyle\sum_{0\leq j \leq n-1, k\ne j} \frac{1}{n^2}}\\
&\fragment{3}{=n \frac{1}{n} + n (n-1) \frac{1}{n^2}}\\
&\fragment{4}{=1 + \frac{n - 1}{n} = 2 - \frac{1}{n}}
\end{align}
</section>
<section>
<ul>
<li class="fragment roll-in"> Recall that $\prob{E}{T(n)}= \Theta(n) + \sum_{i=0}^{n-1} O(\prob{E}{n_i^2})$
<li class="fragment roll-in"> Let's plug in $\prob{E}{n^2_i} = 2-1/n $
$$\prob{E}{T(n)}= \Theta(n) + \sum_{i=0}^{n-1} O(2-1/n) = \Theta(n)$$
<li class="fragment roll-in"> Thus the entire bucket sort algorithm runs in <mark>expected linear time</mark>
</ul>
</section>
</section>
<section>
<h2>See you</h2>
Monday February $20^{th}$
</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],
floor: ["\\lfloor #1 \\rfloor",1]
},
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>