Sei sulla pagina 1di 6

1

Algorithms 2019/2020 - Practice part

To complete the practice part, you have to choose one of the projects. You can team up
with your colleagues (at most 3 students per group). For every question, send an e-mail
to lpepesciarria@luiss.it
You can use all the code provided on the course website. For completing the practice
part you have to send the following les:
A brief report .pdf (max 10 pages) containing:

• the members of the group with the rst name, last name, university number, e-mail
of each member

• an introduction with a description of the problem chosen

• a high-level description of your solution with a brief analysis of the algorithm's


complexity if needed (it is not needed a true formal statement!)

• implementation choices: which data structure you used, libraries, any assumption
made for implementing your solution

• experiments and results (tables and/or plots)

• a thorough analysis of the results - 1 point bonus

• conclusions

Source code

• the whole project must be delivered and the project must be complete (I should be
able to run the project without further ado)

• Make appropriate use of comments in your project:

• Each le, function, and class should have an initial comment.

• Only the more complicated part of your code should have additional comments.

• meaningful name to the variables and functions


2

The right solution to one of the project 1-4 will guarantee you 2 bonus point thus, you
can achieve at most 3 bonus points with one of such project meanwhile whit project 5-7
you can achieve at most 1 bonus point.

For submitting the project upload the report and the source code in an online repository
(Github, Gitlab, one drive, google drive, dropbox... whatever you like) and send an
e-mail to lpepesciarria@luiss.it with the link to your repository.

Project 1

Covidia De Vil is the Health Minister of Covidialand, and she hired you to study the
impact of vaccines against the recent outbreak of the Covidiot19 virus. The company
VaxForAll developed a new vaccine that can defeat Covidiot19 by reducing its spread
among the population. Covidia De Vil would like to adopt this vaccine, but rst she
wants you to understand the real eect of the vaccine on the population of Covidialand.
Withouth the vaccine, Covidiot19 has an infection probability of 92% (i.e., this is the
probability that the virues passes from an infected person to another one). If the vaccine
is adopted, this probability drops to 9%. Given a network describing the relationships
between the citizens of Covidialand, your job is to compute how many people will be
infected on average in the two scenarios (i.e., with and without the vaccine).

In particular, you see the given network as a graph and you have to develop and imple-
ment an algorithm for counting the number of nodes that are reached by the virus in the
following two cases:

• Only one single random node is infected at the beginning

• k dierent random nodes are infected at the beginning

To convince Covidia, you have to show the experimental results of your algorithm on
a real graph. The results must include the average number of nodes infected in both
scenarios (i.e., with and without the vaccine) and the standard deviation. Finally, you
have to show how your results change as k changes (i.e., you have to use dierent values
for k ).
3

Project 2

The well-known inuencer PewDiePie is tired of creating new videos and reaching always
the same people. So, he hired you to help him releasing a new video only when he
is denitely sure that this video will reach at least one new person. You know that
PewDiePie posts his videos on Facebook and that his videos are loved by everyone. As a
result, when PewDiePie posts a new video, this video will be shared by all of his friends,
by all of his friends' friends, and so on and so forth until the video reaches every person
that is reachable this way. In particular, you have to develop and implement an algorithm
that noties PewDiePie if, after the addition of a new link to the social network (i.e.,
when two people become friends on Facebook), his video can now reach at least one more
person than before.

Project 3

A well known company operating in the stock market hires you to help them buy the
right shares. You are supposed to write a program which computes which share has to
be bought at a given time. In particular, you know that a given share is available only
for a small amount of time T and, at any time, only T dierent share are available (for
the same value of T ). The problem you have to solve is the following. You are given an
array of n integers, which represent prices of dierent shares, and a time T ≤ n. At time
t = 0 only the rst T shares are available; at time t = 1 the rst share will be no longer
available and the (T + 1)-th share will become available, so that at any time there are
always T shares available. In short, the available shares are represented by a contiguous
subarray of size T that at each time is shifted one position to the right. Your job is
to develop and implement an algorithm that takes as input the array of prices and the
parameter T and return the indexes of the positions (representing shares) that are less
expensive.
For instance:
input: shares = {4, 2, 1, 4, 4, 2, 1, 9}, T =3
output: {2, 2, 2, 5, 6, 6 } .
Note that the array starts from position 0. At time 0 only the rst 3 shares are available
4

and the minimum is 1, whch is given by the share in position 2. At time 1 the available
shares are {2, 1, 4} and the minimum is still 1 which is still in position 2 of the array
(notice that the position is referred always to the array in input), and so on for each
subarray of size 3.

Project 4

You just came out with a new idea to improve QuickSort and you believe that your idea
yields a faster algorithm than Python's sorting algorithm! In particular, your idea is to
pick the pivot by using algorithm Select, rather than picking it at random.
You share your idea with Tim Peters (TimSort's inventor), but unfortunately Tim does
not trust you. Indeed, he asks you to convince him that your algorithm performs better
in practice. Your job is to implement algorithm Select (you can choose the deterministic
or the randomized version QuickSelect) and to modify QuickSort so that it uses your
implementation of Select to pick the pivot. Furthermore, you are supposed to compare
your new version with the other sorting algorithms and explain carefully the results
achieved.

Project 5

The Pokémon company wants to improve the performance of its videogames. They called
you to implement a new sorting algorithm and test its performance. The new algorithm
is Introsort [1]. Implement it and test its behaviour making a comparison with the
algorithms studied throughout the course.

Project 6

Given weights and values of n items, put these items in a knapsack of capacity W to
get the maximum total value in the knapsack. In other words, given two integer arrays
val[0...n − 1] and weights[0...n − 1] which represent values and weights associated with
n items respectively. Also given an integer W which represents knapsack capacity, nd
5

out the maximum value subset of item (i.e. the items such that their sum has the
maximum value) such that sum of the weights of this subset is smaller than or equal to
W . You cannot break an item, either pick the complete item, or don't pick it. Design
and implement an algorithm for solving the problem and execute experiments on it.

Project 7

The professor Sumonacci come up with a new problem regarding Fibonacci's sequence:
given a number k , nd the required minimum number of Fibonacci terms whose sum equal
to k . You can choose a Fibonacci number multiple times. Unfortunately, Sumonacci has
no idea how to solve the problem eciently. Your task is to design and implement an
ecient algorithm to solve the problem and help Sumonacci.
Bibliography
[1] https://en.wikipedia.org/wiki/Introsort

Potrebbero piacerti anche