-
Notifications
You must be signed in to change notification settings - Fork 0
/
cs101_chapter4.html
375 lines (290 loc) · 12.5 KB
/
cs101_chapter4.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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-7">
<title>Computer Science 101: Data Abstraction</title>
<meta name="description" content="Teaching Slides for Computer Science 101">
<meta name="author" content="Gregory M. Kapfhammer">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/night-gkapfham.css" id="theme">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- Install Font Awesome and the Google Web fonts -->
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Montserrat|Roboto+Slab" rel="stylesheet" type="text/css">
<!-- If the query includes 'print-pdf', include the PDF print sheet -->
<script>
if( window.location.search.match( /print-pdf/gi ) ) {
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'css/print/pdf.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
}
</script>
</head>
<body>
<div class="reveal">
<div class="slides">
<section data-background-transition="none" data-background="https://images.unsplash.com/photo-1452860606245-08befc0ff44b" style="background: rgba(29,31,33,0.9)">
<h1>Computer Science 101</h1>
<h2>Data Abstraction</h2>
<p>Gregory M. Kapfhammer</p>
</section>
<section>
<h1>Color Scheme</h1>
<p class="fragment"><b class="orange">Key Concept</b></p>
<p class="fragment"><b class="purple">Corresponding Diagram</b></p>
<p class="fragment"><b class="green">In-Class Discussion</b></p>
<p class="fragment"><b class="red">In-Class Activity</b></p>
<p class="fragment"><b class="blue">Details in the Textbook</b></p>
</section>
<section>
<h1>Data Structure</h1>
<p class="fragment">Systematic way of organizing and accessing data</p>
</section>
<section>
<h1>Algorithm</h1>
<p class="fragment">A step-by-step for performing a task in a finite time</p>
</section>
<section>
<h1><b class="orange">Running time of algorithms as they process data structures</b></h1>
</section>
<section>
<h1><b class="orange">Larger inputs lead to longer running times</b></h1>
</section>
<section>
<h1><b class="green">What about the space overhead of an algorithm?</b></h1>
</section>
<section>
<h1><b class="orange">Trade-off time and space overhead</b></h1>
</section>
<section>
<h1><b class="blue">See Code Fragment 4.1 for a timing method</b></h1>
</section>
<section>
<h1><b class="purple">Let's draw this as a diagram</b></h1>
</section>
<section>
<h1>Challenges</h1>
<p class="fragment">Comparable results only when using same environment</p>
<p class="fragment">Limited set of inputs may lead to incorrect conclusions</p>
<p class="fragment">You must fully implement and test the algorithms</p>
</section>
<section>
<h1><b class="green">Why are these challenges important to address?</b></h1>
</section>
<section>
<h1><b class="green">Is there an alternative?</b></h1>
</section>
<section>
<h1><b class="orange">Yes!</b></h1>
</section>
<section>
<h1><b class="orange">In fact, there are several! ☺</b></h1>
</section>
<section>
<h1><b class="orange">Disciplined empirical study</b></h1>
</section>
<section>
<h1><b class="orange">Experiments through input doubling</b></h1>
</section>
<section>
<h1><b class="orange">Analytical algorithm evaluation</b></h1>
</section>
<section>
<h1>Theoretical Goals</h1>
<p class="fragment">Work independent of hardware and software</p>
<p class="fragment">Takes into account all possible inputs</p>
<p class="fragment">Does not require algorithm implementation</p>
</section>
<section>
<h1><b class="orange">Count primitive operations</b></h1>
</section>
<section>
<h1>Primitive Operations</h1>
<p class="fragment">Assign a value to a variable</p>
<p class="fragment">Follow an object reference</p>
<p class="fragment">Compare two numbers</p>
<p class="fragment">Return from a method</p>
<p class="fragment">Call a method</p>
<p class="fragment"><b class="green">Any questions about these types of operations?</b></p>
</section>
<section>
<h1><b class="orange">Focus on building intuition</b></h1>
</section>
<section>
<h1><b class="orange">Focus on the worst-case behavior</b></h1>
</section>
<section>
<h1><b class="orange">Look for iteration constructs</b></h1>
</section>
<section>
<h1><b class="orange">Nesting of iteration constructs</b></h1>
</section>
<section>
<h1><b class="green">Other types of algorithm performance behavior?</b></h1>
</section>
<section>
<h1><b class="orange">Worst-case</b></h1>
</section>
<section>
<h1><b class="orange">Average-case</b></h1>
</section>
<section>
<h1><b class="orange">Best-case</b></h1>
</section>
<section>
<h1><b class="blue">See Figure 4.2 for an example</b></h1>
</section>
<section>
<h1><b class="orange">Describe algorithm performance with a function</b></h1>
</section>
<section>
<h1><b class="orange">Operations as function of input size</b></h1>
</section>
<section>
<h1><b class="orange">The Seven Functions</b></h1>
</section>
<section>
<h1>Growth Rates</h1>
<p class="fragment">Constant</p>
<p class="fragment">Logarithm</p>
<p class="fragment">Linear</p>
<p class="fragment">n-log-n</p>
<p class="fragment">Quadratic</p>
<p class="fragment">Cubic</p>
<p class="fragment">Exponential</p>
</section>
<section>
<h1><b class="orange">Fast-growing function, slow algorithm</b></h1>
</section>
<section>
<h1><b class="orange">Slow-growing function, fast algorithm</b></h1>
</section>
<section>
<h1><b class="blue">See Figure 4.4 to compare the growth rates!</b></h1>
</section>
<section>
<h1><b class="green">Any questions about these functions?</b></h1>
</section>
<section>
<h1><b class="orange">Focusing on worst-case behavior</b></h1>
</section>
<section>
<h1><b class="orange">The "Big-Oh" Notation</b></h1>
</section>
<section>
<h1><b class="orange"><em>f(n)</em> is <em>O(g(n))</em></b></h1>
</section>
<section>
<h1><b class="orange"><em>f(n)</em> is order <em>g(n)</em></b></h1>
</section>
<section>
<h1><b class="orange"><em>f(n)</em> is bounded above by <em>g(n)</em></b></h1>
</section>
<section>
<h1><b class="orange">Asymptotic sense as <em>n</em> grows toward infinity</b></h1>
</section>
<section>
<h1><b class="purple">Let's visualize this with a diagram!</b></h1>
</section>
<section>
<h1>Algorithm Growth Rates</h1>
<p class="fragment">log n: 3, 4, 5, 6, 7, 8, 9 </p>
<p class="fragment">n: 8, 16, 32, 64, 128, 256, 512</p>
<p class="fragment">Quadratic: 64, 256, 1024, 4096, 16384, 65536, 262144</p>
<p class="fragment"><b class="orange">Cubic and exponential grow much faster!</b></p>
<p class="fragment"><b class="green">Any questions about these growth rates?</b></p>
</section>
<section>
<h1><b class="red">Organize into teams of two or three</b></h1>
</section>
<section>
<h1><b class="green">Which algorithm would you pick?</b></h1>
</section>
<section>
<h1>Algorithm Choices</h1>
<p class="fragment">Fast algorithm running on a slow computer</p>
<p class="fragment">Slow algorithm running on a fast computer</p>
</section>
<section>
<h1>Algorithm Choices</h1>
<p class="fragment">Good algorithm design is very important</p>
<p class="fragment">Ensure that your algorithm has a slow growth rate</p>
<p class="fragment">Dramatic speedups in hardware cannot overcome asymptotically slow algorithms</p>
<p class="fragment"><b class="blue">See Tables 4.4 and 4.5 for more details!</b></p>
</section>
<section>
<h1><b class="orange">Examples of algorithm analysis</b></h1>
</section>
<section>
<h1><b class="orange">arrayMax on page 171</b></h1>
<p class="fragment">This algorithm is O(n)!</p>
<p class="fragment">Can you clearly explain why?</p>
</section>
<section>
<h1><b class="orange">repeat1 on page 172</b></h1>
<p class="fragment">This algorithm is O(n<sup>2</sup>)!</p>
<p class="fragment">Can you clearly explain why?</p>
</section>
<section>
<h1><b class="green">Why is repeat1 slower than repeat2?</b></h1>
</section>
<section>
<h1><b class="orange">unique1 on page 174</b></h1>
<p class="fragment">This algorithm is O(n<sup>2</sup>)!</p>
<p class="fragment">Can you clearly explain why?</p>
</section>
<section>
<h1><b class="orange">unique2 on page 175</b></h1>
<p class="fragment">This algorithm is O(n×logn)!</p>
<p class="fragment">Can you clearly explain why?</p>
</section>
<section>
<h1><b class="orange">Interplay between theory and experiment</b></h1>
</section>
<section>
<h1><b class="green">How does this connect to previous content?</b></h1>
</section>
<section>
<h1><b class="green">Questions about algorithm analysis?</b></h1>
</section>
<section>
<h1><b class="orange">We will practice this in the assignments!</b></h1>
</section>
<section>
<h1><b class="orange">Schedule office hours to discuss further</b></h1>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'none', // default/cube/page/concave/zoom/linear/fade/none
// Parallax scrolling
// parallaxBackgroundImage: 'https://s3.amazonaws.com/hakim-static/reveal-js/reveal-parallax-1.jpg',
// parallaxBackgroundSize: '2100px 900px',
// Optional libraries used to extend on reveal.js
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>