Docsity
Docsity

Przygotuj się do egzaminów
Przygotuj się do egzaminów

Studiuj dzięki licznym zasobom udostępnionym na Docsity


Otrzymaj punkty, aby pobrać
Otrzymaj punkty, aby pobrać

Zdobywaj punkty, pomagając innym studentom lub wykup je w ramach planu Premium


Informacje i wskazówki
Informacje i wskazówki

DTU examin na zaliczenie przedmiotu, Egzaminy z Algorytmy i programowanie aplikacji

Egzamin na zaliczenie przedmiotu z algorytmow zalicznienie

Typologia: Egzaminy

2019/2020

Załadowany 06.11.2020

nieznany użytkownik
nieznany użytkownik 🇵🇱

1 dokument

1 / 10

Toggle sidebar

Ta strona nie jest widoczna w podglądzie

Nie przegap ważnych części!

bg1
Technical University of Denmark
Written test examination, May xx, 2020.
Course name: Algorithms and Data Structures 1
Course number: 02105
Aids: all aids, open internet.
Duration: 2 hours.
Weights: XX.
All exercises should be answered by filling out the areas below the description. As your solution to the exam, hand in
this page and the following pages. If you really need more space, you may use extra pieces of paper and attach these to
the end of your solution.
Asymptotic bounds should be as tight as possible. Unless otherwise specified, the base of all logarithms is 2 and logkn
means (log n)k.
"Give an algorithm" means that you should describe your solution in a short, precise, and unambiguous manner, argue
correctness of your solution, and analyze the complexity of your solution. Unless specified otherwise, the description
should be in natural language and not pseudocode. The analysis should explain how you derived the complexity bound.
"Argue correctness of your algorithm" means that you should provide a short argument for correctness of your algorithm.
"Analyse the running time of your algorithm in the relevant parameters (parameters x,y, ..) of the problem" means that
you should analyze the running time using the explicitly stated parameters of the problem (parameters x,y, ..).
Name:
Student ID:
Test exam 02105, Spring 2020 page 1 of 10
s200600
Dominik Stepien
pf3
pf4
pf5
pf8
pf9
pfa

Podgląd częściowego tekstu

Pobierz DTU examin na zaliczenie przedmiotu i więcej Egzaminy w PDF z Algorytmy i programowanie aplikacji tylko na Docsity!

Technical University of Denmark

Written test examination, May xx, 2020.

Course name: Algorithms and Data Structures 1

Course number: 02105

Aids: all aids, open internet.

Duration: 2 hours.

Weights: XX.

All exercises should be answered by filling out the areas below the description. As your solution to the exam, hand in this page and the following pages. If you really need more space, you may use extra pieces of paper and attach these to the end of your solution.

Asymptotic bounds should be as tight as possible. Unless otherwise specified, the base of all logarithms is 2 and log k^ n means (log n ) k.

"Give an algorithm" means that you should describe your solution in a short, precise, and unambiguous manner, argue correctness of your solution, and analyze the complexity of your solution. Unless specified otherwise, the description should be in natural language and not pseudocode. The analysis should explain how you derived the complexity bound.

"Argue correctness of your algorithm" means that you should provide a short argument for correctness of your algorithm.

"Analyse the running time of your algorithm in the relevant parameters (parameters x , y , ..) of the problem" means that you should analyze the running time using the explicitly stated parameters of the problem (parameters x , y , ..).

Name:

Student ID: s

Dominik Stepien

1 Movie Reviews

Consider analyzing a collection R of reviews of a popular movie. Each review has a score that is non-negative integer. Throughout the exercise, we let n denote the size of R and we assume that R is given as an array, where each entry contains the score of a review.

1.1 Give an algorithm that given R computes the total number of reviews with a score in the range [ n , n^2 ]. Analyse the running time of your algorithm in terms of parameter n.

Solution:

1.2 Give an algorithm that given R computes the total number of unique reviews scores in the range [ n , n^2 ] (i.e., multiple identical review scores should only be counted once). Analyze the running time of your algorithm in terms of parameter n.

Solution:

Let's see if it writes correctly

2 Trees distances

This exercise is about rooted binary trees. Each node x has fields x. parent , x. left and x. right denoting the parent, left child, and right child of x. For the root root , root. parent = null. Throughout the exercise, we let n denote the size of the input tree.

2.1 A descendant leaf of a node x is a descendant of node x that is also a leaf. A nearest descendant leaf is a descendant leaf of minimal distance to x. The leaf distance for x is the distance from x to a nearest descendant leaf (if x is a leaf itself the distance is of course 0). Consider the tree below. Write the leaf distance for each node x in the tree. Do so directly on the vertices in the tree.

Solution:

2.2 Give a recursive algorithm, LEAFDIST( x ), that given the root computes the leaf distance for all nodes in the tree. Assume that all nodes have a field leafdist and after the call to LEAFDIST on the root, it should hold for all nodes y that y. leafdist is the leaf distance for y. Write your algorithm in pseudocode. Analyse the running time of your algorithm in the parameter n.

Solution:

3 Zombies

A zombie outbreak consists of a set of persons and a set of infections. Each infection is a pair of persons ( p 1 , p 2 ) and we say that p 1 has infected p 2. Note that multiple persons may infect the same person. For instance, { A , B , C , D , E } and {( A , B ), ( B , C ), ( C , D ), ( A , E ), ( E , C )} is a zombie outbreak with 5 persons and 5 infections. Throughout the exercise, let P denote the number of persons and I the number of infections.

3.1 Describe how to model a zombie outbreak as a graph

Solution:

3.2 Draw the graph corresponding to the zombie outbreak in the example.

Solution:

3.3 We are interested in investigating the origin of the outbreak. A person p is a patient-zero if p did not get infected by any other person. Give an algorithm, that given a zombie outbreak, prints out all patient-zero persons. Argue correctness of your algorithm. Analyse the running time of your algorithm in the relevant parameters of the problem.

Solution:

3.5 We now associate to every infection i an infection speed , speed ( i ). We define the infection speed of an infection chain to be the sum of the infection speeds of each infection in the chain. We are interested in computing the fastest infection chain between two persons in a consistent zombie outbreak. Given an algorithm, that given a consistent zombie outbreak and two persons p 1 and p 2 computes a fastest infection chain from p 1 to p 2. Argue correctness of your algorithm. Analyse the running time of your algorithm in the relevant parameters of the problem.

Solution: