import algolab
algolab.init()
%%HTML
<!--
<h1> <a href="exam-2017-09-04.html" target="_blank" style="color:red"> 04/09/2017 EXAM TEXT</a></h1>
-->
<h1> News </h1>
<h4> 11/09/2017 </h4>
- published solutions of <a href="past-exams.html#2017-09-04" target="_blank"> 04/09/17 Exam</a> <br/>
<h4> 06/08/2017 </h4>
- published solutions of <a href="past-exams.html#2017-06-08" target="_blank"> 06/08/17 Exam</a> <br/>
<h4> 21/02/2017 </h4>
- published solutions of <a href="past-exams.html#2017-02-16" target="_blank"> 16/02/17 Exam</a> <br/>
<h4> 9/02/2017 </h4>
- fixed bugs in <a href="trees.html" target="_blank">methods of GenericTree</a>, added <code>detach_sibling</code> tests <br/>
<h4> 26/01/2017 </h4>
- published solutions of <a href="past-exams.html#2016-01-26" target="_blank"> 26/01/17 exam</a> <br/>
<h4> 23/01/2017 </h4>
- Fixed many bugs in <a href="graphs.html" target="_blank">graph</a> reports of differences during testing <br/>
<h4> 13/01/2017 </h4>
- published solutions of <a href="past-exams.html#2017-01-13-midterm" target="_blank"> 13/01/17 Midterm</a> <br/>
<h4> 10/01/2017 </h4>
- Added a lot of material <a href="graphs.html" target="_blank">on graphs </a> <br/>
<h4> 9/01/2017 </h4>
- fixed broken link in Chapters to <a href="data-structures-2.html" target="_blank">Data Structures 2.2 for stacks and linked lists </a><br/>
<h4> 8/01/2017 </h4>
- added looong intro to classes in <a href="data-structures-1.html" target="_blank" >Data Structures 2.1: ComplexNumber</a><br/>
- split Chapter 2: Data Structures into 2 parts, <a href="data-structures-1.html" target="_blank">2.1 for ComplexNumber</a> and <a href="data-structures-2.html" target="_blank">2.2 for stacks and linked lists.</a> <br/>
<h4>22/12/2016 </h4>
- added graph exercises
See exams schedule on Alberto Montresor's site
Algolab exams are open book. You can bring a printed version of the material listed below.
Exam will take place in the lab with no internet access. You will only be able to access a folder with this documentation:
So if you need to look up some Python function, please start today learning how to search documentation using the search functionality on Python website.
Theory
See Alberto Montresor website:
http://cricca.disi.unitn.it/montresor/teaching/scientific-programming
Lab
Worksheets are meant to be used online - pdf quality is not very good, if they result unreadable please tell me
2 Data Structures
2.1 ComplexNumber (pdf)
2.2 Stacks and linked lists (pdf)
A. Past exams
%%HTML
<p class="algolab-warn">
WARNING: If you don't follow the Commandments, bad things happen!
</p>
<p class="algolab-important" >
1) You shall test!
</p>
To run tests, enter the following command in the terminal:
python -m unittest my-file
%%HTML
<p class="algolab-warn">
WARNING: In the call above, DON'T append the extension <i>.py</i> to <i>my-file</i>
<br/>
WARNING: Still, on the hard-disk the file MUST be named with a <i>.py</i> at the end, like <i>my-file.py</i>
</p>
<p class="algolab-important" >
2. You shall also write on paper!
</p>
<p>
If staring at the monitor doesn't work, help yourself and draw a representation of the state sof the program.
Tables, nodes, arrows, all can help figuring out a solution for the problem.
</p>
<p class="algolab-important" >
3. You shall copy *exactly the same* function definitions as in the exercises!
</p>
For example don't write :
def MY_selection_sort(A):
%%HTML
<p class="algolab-important" >
4. You shall never ever reassign function parameters:
</p>
def myfun(i, s, L, D):
# You shall not do any of such evil, no matter what the type of the parameter is:
i = 666 # basic types (int, float, ...)
s = "666" # strings
L = [666] # containers
D = {"evil":666} # dictionaries
# For the sole case of composite parameters like lists or dictionaries,
# you can write stuff like this IF AND ONLY IF the function specification
# requires you to modify the parameter internal elements (i.e. sorting a list
# or changing a dictionary field):
L[4] = 2 # list
D.my_field = 5 # dictionary
This also applies to class methods. Never ever write horrors such as:
class MyClass
def my_method(self, x, y):
self = {a:666} # since self is a kind of dictionary, you might be tempted to do like this
# but to the outside world this will bring no effect.
# For example, let's say somebody from outside makes a call like this:
# mc = MyClass()
# mc.my_method()
# after the call mc will not point to {a:666}
self = ['666'] # self is only supposed to be a sort of dictionary and passed from outside
self = 6 # self is only supposed to be a sort of dictionary and passed from outside
%%HTML
<p class="algolab-important" >
5. You shall never ever assign values to method calls:
</p>
WRONG WRONG STUFF
my_fun() = 666
my_fun() = '666'
my_fun() = [666]
CORRECT STUFF
With the assignment operator we want to store in the left side a value from the right side, so all of these are valid operations:
x = 5
y = my_fun()
z = []
z[0] = 7
d = {}
d["a"] = 6
Function calls such as my_fun() return instead results of calculations in a box that is created just for the purpose of the call and Python will just not allow us to reuse it as a variable. So whenever you see 'name()' at the left side, it can't be possibly follewed by one equality = sign (but it can be followed by two equality signs == if you are performing a comparison).
%%HTML
<p class="algolab-important" >
6. You shall use <i>return</i> command only if you see written <i>return</i> in the pseudocode!
</p>
If there is no return in the pseudocode, the function is intended to return None. In this case you don't even need to write return None, as Python will do it implicitly for you.
Lab 1 Slides
3 Nov 2016
Lab Goals
How
Lab Midterm?
Probably not. Still, will provide exam example.
Lab 2 Slides
Date: Nov 11th, 2016
Lab 3 Slides
Nov 17th, 2016
gap_rec, binary_search_recbinary_search_iterdef MY_selection_sort(A): return command only if you see written return in the pseudocode!return in the pseudocode, the function is intended to return None. In this case you don't even need to write return None, as Python will do it implicitly for you.Lab 4 Slides
Nov 18th, 2016
New Commandment:
You shall never ever reassign function parameters:
def myfun(L, i, s):
# You shall not do any of this evil:
L = [666]
i = 666
s = "666"
Previous commandments:
Lab 7 slides
Lab 8 slides
UnorderedList ( see Chapter 2.2 ) until fast size() and append() includedLab 10 slides
19 Dic 2016
GenericTree see Graphs chapterLab 11 slides
21 Dic 2016
For exam solution, see Appendix A in Chapters
You can schedule a meeting by emailing me at david.leoni [AT] unitn.it , more or less I'm available every day until 19.00
Then you will find me in Povo 1 building at DISI, in room 226 DKM :
