Docsity

Algorithms Assignment 3, Exercises of Algorithms and Programming

Toggle sidebar
bg1
1
Due: Sunday May 26th 11:59pm
COMP 9007 – Assignment 3
As a first step go to the last page and read the section: Advice on how to do the
homework.
Question 1 (10 marks)
For each of the following problems indicate which algorithmic approach (Greedy,
Divide-and-conquer, Dynamic programming, Max-flow) you would use to
attempt to solve the problem. You do not have to give an algorithm.
(a) In an n×n array, a peak is an element that is greater than its four neighbours
(left, right, top and bottom). Peaks can also lie on edges or corners, they are
greater than their three or two (respectively) neighbours. There can be more
than one peak in an array. Come up with an algorithm that efficiently finds a
peak in an n × n array.
(b) A computer network is a graph where the vertices are computers and the
(undirected) edges indicate a physi cal network link between two computers.
A computer s ends a message to another computer on the network by passing
it along the network links until it reaches its destination. Find an algorithm
that can determine if an eavesdropper that has the abil ity to monitor
messages on up to k network links can intercept every message sent from s to
t.
(c) You are in charge of assigning planes to gates at an airport. After a plane lands,
it needs to be assigned to a gate, where it must remain until i t takes off. Gi ven
a list of plane arrival and departure times, come up with an algorithm that
assigns planes to gates in an efficient manner.
(d) Your small town has grown large enough that it has to be divided into suburbs
to efficiently allocate resources (e.g. electricity, water, school zones). Come
up with an algorithm that assigns households i nto fiv e “geographically close”
suburbs – i.e. divide houses i nto five groups so that the minimum dis tance
between houses in different suburbs is maximized.
pf3
pf4

Partial preview of the text

Download Algorithms Assignment 3 and more Exercises Algorithms and Programming in PDF only on Docsity!

Due: Sunday May 26th^ 11 :59 pm

COMP 9007 – Assignment 3

As a first step go to the last page and read the section: Advice on how to do the homework.

Question 1 (10 marks)

For each of the following problems indicate which algorithmic approach (Greedy , Divide-and-conquer, Dynamic programming, Max-flow) you would use to attempt to solve the problem. You do not have to give an algorithm. (a) In an n × n array, a peak is an element that is greater than its four neighbours (left, right, top and bottom). Peaks can also lie on edges or corners, they are greater than their three or two (respectively) neighbours. There can be more than one peak in an array. Come up with an algorithm that efficiently finds a peak in an n × n array. (b) A computer network is a graph where the vertices are computers and the (undirected) edges indicate a physical network link between two computers. A computer sends a message to another computer on the network by passing it along the network links until it reaches its destination. Find an algorithm that can determine if an eavesdropper that has the ability to monitor messages on up to k network links can intercept every message sent from s to t. (c) You are in charge of assigning planes to gates at an airport. After a plane lands, it needs to be assigned to a gate, where it must remain until it takes off. Given a list of plane arrival and departure times, come up with an algorithm that assigns planes to gates in an efficient manner. (d) Your small town has grown large enough that it has to be divided into suburbs to efficiently allocate resources (e.g. electricity, water, school zones). Come up with an algorithm that assigns households into five “geographically close” suburbs – i.e. divide houses into five groups so that the minimum distance between houses in different suburbs is maximized.

(e) Come up with an algorithm for determining how many ways you can make a total t by summing k numbers (possibly repeated) from a set S.

Question 2 (20 marks)

Give a detailed algorithm for one of the problems in Question 1. Make sure to include:

  • details relating to the algorithmic approach – for example, if you give a Divide-and-conquer algorithm, clearly state the divide, conquer, and combine steps; if you give a Dynamic Programming algorithm, define the states, the recurrence and the base cases,
  • a brief justification of why your algorithm is correct,
  • an analysis of the running time of your algorithm.

Question 3 (20 marks)

For each of the following problems, decide if the provided answer correctly solves the problem. If it does then analyse the running-time of the algorithm. If it does not, give an example demonstrating why not. (a) Problem: In a weighted directed graph, find the longest simple (i.e. no repeated vertices) path between two vertices s and t. Solution: Multiply all edges by −1 and, using the Bellman-Ford algorithm, find the shortest path between s and t in the new graph. This will be the longest path in the original graph. (b) Problem: In a connected weighted graph with distinct edge weights, find the spanning tree with maximum weight. Solution: Order the edges by weight from smallest to largest. Remove edges following this order, as long as removing an edge does not disconnect the graph. When all edges have been processed, the remaining edges form the maximum spanning tree. (c) Problem: In a binary tree, find the size of the smallest subset of vertices V^0 such that every edge has at least one endpoint in V^0. Solution: Using dynamic programming. Define M [ v,i ] for every vertex v of the tree and i ∈{ 0 , 1 } as follows:

  • If v is a leaf, then M [ v,i ] = i.
  • If v has children v 1 and v 2 then

Advice on how to do the home work

All submitted work must be done individually without consulting someone elses solutions in accordance with the Universitys Academic Dishonesty and Plagiaris m policies.

  • Assignments submitted via Canvas as pdf (no handwriting!)
  • Be careful with giving multiple or alternative answers. If you give multiple answers, then we will give you marks only for ”your worst answer”, as this indicates how well you understood the question.
  • Some of the questions are very easy (with the help of the lecture notes or book). You can use the material presented in the lecture or book (without proving it). You do not need to write more than necessary (see comment above).
  • When giving answers to questions, we always would like you to prove/explain/motivate your answers.
  • When giving an algorithm as an answer, the algorithms does not have to be given as (pseudo-)code.
  • If you do give (pseudo-)code, then you also have to explain your code and your ideas.
  • Unless otherwise stated, we always ask about worst-case analysis, worst case running times etc. (for example, hashing does not guarantee anything in the worst case, in general).
  • It might help you (and us) if you briefly describe your general idea, and after that you might want to develop and elaborate on details. If we don’t see/understand your general idea, we cannot give you points for it.
  • If you use further resources (books, scientific papers, the internet,...) to formulate your answers, then add references to your sources.
  • If you refer to a result in a scientific paper or on the web you need to explai n the results to show that you understand the results, and how it was proven.