Additional material for the project (e.g. the class ScholarlySearchEngine
) and for the course (e.g. a list of exercises about algorithms) will be provided before the holidays
Just a reminder about the date of the exams
23 January 2018
26 February 2018
10 May 2018
22 June 2018
25 September 2018
23 October 2018
They will be uploaded on AlmaEsami soon
For each date:
written examination: 10-12
project oral colloquium: 13-16
He was an engineer and entrepreneur
He thought that profit of a company had to be reinvested for the benefits of the whole society
He was known all over the world, in particular in the United States, as one of the most important worldwide manufacturer of typewriters, calculators, and computers
His vision towards electronic products has driven the company even after his death
Lettera 32 was released in 1963 - it was a portable (5.9 kg) mechanical typewriter very popular among journalists and students
Programma 101 was released in 1965 - first commercial programmable desktop computer, designed for personal use, programmable with assembly-like language
NASA used it to plan the Apollo 11 landing on the Moon
At every stage of execution of a particular algorithm when we are seeking for possible candidates for constructing the solution to a computational problem, this approach makes always the choice that is optimal (i.e. the best one) at that particular moment
It is easy to come up with a greedy algorithm for a problem
Computational problem: to give the change of a certain amount of euros in coins
A possible greedy approach:
Consider the coins to choose for the change as ordered in a decrescent way, from the highest value (i.e. 2 euros) to the lowest one (i.e. 1 cent)
For each kind of value, add in the candidate set of the solution as much coins of that value as possible until their sum is lesser than the remaining of the change to give
Return the selected coins for the change
Sometimes the solution found, while it provides a correct solution to the problem, is just sub-optimal - i.e. it is not the best one for solving the problem
For instance, if you are driving from Florence to Bologna, and, at a certain crossroad you find two signs indicating two different routes to get to Bologna
left route: get to Bologna by travelling for 42 kilometers
right route: get to Bologna by travelling for 56 kilometers
Greedy approach: go to left (1)
It cannot predict the existence of traffic in the left route
Greedy choice property: at a certain step, we can choose the best candidate for improving the set of candidates bringing to a solution - this chioce can be somehow driven by all the previous choices
The problem as an optimal substructure, i.e. optimal solution to a computational problem can be built by considering the optimal solutions to its subproblems
Computational problem: break a text into lines such that it will fit in the available width of a page
<string>.split(<string_separator>)
It returns a list of strings where each string in the list represents a word (or a token)
Example: "a b c".split(" ")
returns the list ["a", "b", "c"]
<string_separator>.join(<list_of_strings>)
It returns a string composed by all the strings in the list separated by <string_separator>
Example: " ".join(["a", "b", "c"])
returns the string "a b c"
def line_wrap(text, line_width):
result = []
space_left = line_width
line = []
for word in text.split(" "):
word_len = len(word)
if word_len + 1 <= space_left:
line.append(word)
space_left = space_left - word_len + 1
else:
result.append(" ".join(line))
line = [word]
space_left = line_width - word_len
result.append(" ".join(line))
return "\n".join(result)
silvio.peroni@unibo.it 0000-0003-0530-4305 @essepuntato
Computational Thinking and Programming (A.Y. 2017/2018)
Second Cycle Degree in Digital Humanities and Digital Knowledge
Alma Mater Studiorum - Università di Bologna