-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
53a4a8a
commit 1fe3083
Showing
3 changed files
with
221 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
10* | ||
11* | ||
12* | ||
13* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"> | ||
|
||
<title>Dynamic programming algorithms</title> | ||
|
||
<link rel="stylesheet" href="css/reveal.css"> | ||
<link rel="stylesheet" href="css/theme/simple.css"> | ||
<link rel="stylesheet" href="css/ctc.css"> | ||
|
||
<!-- Theme used for syntax highlighting of code --> | ||
<link rel="stylesheet" href="lib/css/zenburn.css"> | ||
<link rel="stylesheet" href="css/addon.css"></link> | ||
<link rel="stylesheet" href="css/font-awesome.min.css"></link> | ||
<link rel="stylesheet" href="css/academicons.min.css"></link> | ||
|
||
<!-- 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.css'; | ||
document.getElementsByTagName( 'head' )[0].appendChild( link ); | ||
</script> | ||
</head> | ||
<body> | ||
<div class="reveal"> | ||
<div class="slides"> | ||
<section id="title" class="title_slide" role="doc-cover"> | ||
<h1 class="bbbt">Dynamic programming algorithms</h1> | ||
<div class="author"> | ||
<p><a href="https://www.unibo.it/sitoweb/silvio.peroni/en">Silvio Peroni</a></p> | ||
<p class="contact"> | ||
<i class="fa fa-envelope" aria-hidden="true"></i> <a href="mailto:[email protected]">[email protected]</a> | ||
<i class="ai ai-orcid" aria-hidden="true"></i> <a href="https://orcid.org/0000-0003-0530-4305">0000-0003-0530-4305</a> | ||
<i class="fa fa-twitter" aria-hidden="true"></i> <a href="https://twitter.com/essepuntato">@essepuntato</a> | ||
</p> | ||
<p class="sst mtl"><a href="https://www.unibo.it/en/teaching/course-unit-catalogue/course-unit/2023/467045">Computational Thinking and Programming (A.Y. 2023/2024)</a></p> | ||
<p class="ssst"><a href="https://corsi.unibo.it/2cycle/DigitalHumanitiesKnowledge">Second Cycle Degree in Digital Humanities and Digital Knowledge</a></p> | ||
<p class="ssst"><a href="http://www.unibo.it/en">Alma Mater Studiorum - Università di Bologna</a></p> | ||
<p class="license"><a rel="license" href="http://creativecommons.org/licenses/by/4.0/"></a> <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">Creative Commons Attribution 4.0 International License</a></p> | ||
</div> | ||
</section> | ||
|
||
<section> | ||
<h2>Communication 1</h2> | ||
<p>During the last lectures of the course, you will be asked to fill-up a questionnaire on the organisation of the course and related stuff - it is anonymous, of course</p> | ||
<p>Please, do it carefully and honestly, since it is one of the most important inputs I will have to understand what can be improved in the next year course</p> | ||
<p>The fact that the course of this year is slightly different from the one held during the previous year one is mainly due to the comments I have received through these questionnaires</p> | ||
</section> | ||
|
||
<section> | ||
<h2>Any question about the previous lecture?</h2> | ||
</section> | ||
|
||
<section> | ||
<h2 class="bbt">Historic hero: Fibonacci</h2> | ||
<img class="wm fr mlm" src="img/fibonacci.jpg" /> | ||
<p>He was a mathematician</p> | ||
<p class="fragment">First person to introduce in Europe the Hindu-Arabic number system (i.e. 0, 1, 2, 3, 4, 5, 6, 7, 8, 9)</p> | ||
<p class="fragment">Publication <em>Liber Abaci</em> (Book of Calculation) in 1202: how to use such numeral system for addressing situations related to commerce, and for solving generic mathematical problems</p> | ||
</section> | ||
|
||
<section> | ||
<h2>Fibonacci sequence</h2> | ||
<p>Fibonacci developed an infinite sequence of numbers, named after him, that described ideally the number of male-female pairs of rabbits at a given month</p> | ||
<p class="fragment" data-fragment-index="1"><code>fib(0) = 0</code><strong class="fragment" data-fragment-index="4"> [base case 1]</strong></p> | ||
<p class="fragment" data-fragment-index="2"><code>fib(1) = 1</code><strong class="fragment" data-fragment-index="5"> [base case 2]</strong></p> | ||
<p class="fragment" data-fragment-index="3"><code>fib(n) = fib(n-1) + fib(n-2)</code><strong class="fragment" data-fragment-index="6"> [recursive step]</strong></p> | ||
</section> | ||
|
||
<section> | ||
<section data-transition="slide-in fade-out"> | ||
<h2>Fibonacci: divide and conquer</h2> | ||
<p class="tc"><img src="img/fib_dc-01.png" /></p> | ||
</section> | ||
<section data-transition="fade-in"> | ||
<h2>Fibonacci: divide and conquer</h2> | ||
<p class="tc"><img src="img/fib_dc-02.png" /></p> | ||
</section> | ||
<section data-transition="fade-in"> | ||
<h2>Fibonacci: divide and conquer</h2> | ||
<p class="tc"><img src="img/fib_dc-03.png" /></p> | ||
</section> | ||
<section data-transition="fade-in"> | ||
<h2>Fibonacci: divide and conquer</h2> | ||
<p class="tc"><img src="img/fib_dc-04.png" /></p> | ||
</section> | ||
<section data-transition="fade-in"> | ||
<h2>Fibonacci: divide and conquer</h2> | ||
<p class="tc"><img src="img/fib_dc-05.png" /></p> | ||
</section> | ||
<section data-transition="fade-in"> | ||
<h2>Fibonacci: divide and conquer</h2> | ||
<p class="tc"><img src="img/fib_dc-06.png" /></p> | ||
</section> | ||
<section data-transition="fade-in"> | ||
<h2>Fibonacci: divide and conquer</h2> | ||
<p class="tc"><img src="img/fib_dc-07.png" /></p> | ||
</section> | ||
<section data-transition="fade-in"> | ||
<h2>Fibonacci: divide and conquer</h2> | ||
<p class="tc"><img src="img/fib_dc-08.png" /></p> | ||
</section> | ||
</section> | ||
|
||
<section> | ||
<h2>Fibonacci (divide and conquer): algorithm</h2> | ||
<pre><code class="python">def fib_dc(n): | ||
if n <= 0: | ||
return 0 | ||
elif n == 1: | ||
return 1 | ||
else: | ||
return fib_dc(n-1) + fib_dc(n-2)</code></pre> | ||
</section> | ||
|
||
<section> | ||
<h2 class="bbt">Dynamic programming approach</h2> | ||
<p>Dynamic programming algorithm is based on six steps</p> | ||
<ol> | ||
<li class="fragment" data-fragment-index="1"><p class="fragment highlight-red" data-fragment-index="7"><strong>[base case: solution exists]</strong> return the solution calculated previously, otherwise</p></li> | ||
<li class="fragment" data-fragment-index="2"><p><strong>[base case: address directly]</strong> address directly if it is an easy-to-solve problem, otherwise</p></li> | ||
<li class="fragment" data-fragment-index="3"><p><strong>[divide]</strong> split the input material into two or more balanced parts, each depicting a sub-problem of the original one</p></li> | ||
<li class="fragment" data-fragment-index="4"><p><strong>[conquer]</strong> run the same algorithm recursively for every balanced parts obtained in the previous step</p></li> | ||
<li class="fragment" data-fragment-index="5"><p><strong>[combine]</strong> reconstruct the final solution of the problem by means of the partial solutions</p></li> | ||
<li class="fragment" data-fragment-index="6"><p class="fragment highlight-red" data-fragment-index="7"><strong>[memorize]</strong> store the solution to the problem for reusing it</p></li> | ||
</ol> | ||
</section> | ||
|
||
<section> | ||
<section data-transition="slide-in fade-out"> | ||
<h2>Fibonacci: dynamic programming</h2> | ||
<p class="tc"><img src="img/fib_dp-01.png" /></p> | ||
</section> | ||
<section data-transition="fade-in"> | ||
<h2>Fibonacci: dynamic programming</h2> | ||
<p class="tc"><img src="img/fib_dp-02.png" /></p> | ||
</section> | ||
<section data-transition="fade-in"> | ||
<h2>Fibonacci: dynamic programming</h2> | ||
<p class="tc"><img src="img/fib_dp-03.png" /></p> | ||
</section> | ||
<section data-transition="fade-in"> | ||
<h2>Fibonacci: dynamic programming</h2> | ||
<p class="tc"><img src="img/fib_dp-04.png" /></p> | ||
</section> | ||
<section data-transition="fade-in"> | ||
<h2>Fibonacci: dynamic programming</h2> | ||
<p class="tc"><img src="img/fib_dp-05.png" /></p> | ||
</section> | ||
<section data-transition="fade-in"> | ||
<h2>Fibonacci: dynamic programming</h2> | ||
<p class="tc"><img src="img/fib_dp-06.png" /></p> | ||
</section> | ||
</section> | ||
|
||
<section> | ||
<h2>Fibonacci: ancillary operation</h2> | ||
<p class="mbs">Non-inclusion in dictionary:<br /> <code><key> not in <dictionary></code></p> | ||
<p class="mtn">Comparison that returns <code>True</code> if <key> is not included as key in any pair of <dictionary></p> | ||
</section> | ||
|
||
<section> | ||
<h2>Fibonacci (dynamic programming): algorithm</h2> | ||
<pre><code class="python">def fib_dp(n, d): | ||
if n not in d: | ||
if n <= 0: | ||
d[n] = 0 | ||
elif n == 1: | ||
d[n] = 1 | ||
else: | ||
d[n] = fib_dp(n-1, d) + fib_dp(n-2, d) | ||
|
||
return d.get(n)</code></pre> | ||
</section> | ||
|
||
<section class="title_slide"> | ||
<h2> | ||
END | ||
<span class="subtitle">Dynamic programming algorithms</span> | ||
</h2> | ||
<div class="author"> | ||
<p><a href="https://www.unibo.it/sitoweb/silvio.peroni/en">Silvio Peroni</a></p> | ||
<p class="contact"> | ||
<i class="fa fa-envelope" aria-hidden="true"></i> <a href="mailto:[email protected]">[email protected]</a> | ||
<i class="ai ai-orcid" aria-hidden="true"></i> <a href="https://orcid.org/0000-0003-0530-4305">0000-0003-0530-4305</a> | ||
<i class="fa fa-twitter" aria-hidden="true"></i> <a href="https://twitter.com/essepuntato">@essepuntato</a> | ||
</p> | ||
<p class="sst mtl"><a href="https://www.unibo.it/en/teaching/course-unit-catalogue/course-unit/2023/467045">Computational Thinking and Programming (A.Y. 2023/2024)</a></p> | ||
<p class="ssst"><a href="https://corsi.unibo.it/2cycle/DigitalHumanitiesKnowledge">Second Cycle Degree in Digital Humanities and Digital Knowledge</a></p> | ||
<p class="ssst"><a href="http://www.unibo.it/en">Alma Mater Studiorum - Università di Bologna</a></p> | ||
</div> | ||
</section> | ||
</div> | ||
</div> | ||
|
||
<script src="lib/js/head.min.js"></script> | ||
<script src="js/reveal.js"></script> | ||
|
||
<script> | ||
// More info https://github.com/hakimel/reveal.js#configuration | ||
Reveal.initialize({ | ||
history: true, | ||
|
||
// More info https://github.com/hakimel/reveal.js#dependencies | ||
dependencies: [ | ||
{ src: 'plugin/markdown/marked.js' }, | ||
{ src: 'plugin/markdown/markdown.js' }, | ||
{ src: 'plugin/notes/notes.js', async: true }, | ||
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } } | ||
] | ||
}); | ||
</script> | ||
</body> | ||
</html> |