hw1 Recurrence 24s

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

Algorithms

8 February 2024

1. Recurrences
Homework problems
Before you start working on the homework problems, please review the sample solutions to the class
problems.

1. (10 points) Given n points in the plane by their coordinates (xi , yi ) (1 ≤ i ≤ n), we have
to find a pair with the smallest distance between them. What is the trivial algorithm for this
problem, why is it correct and what is the running time of this algorithm? (The size of the
input is the number of points (i.e. n), and the basic steps are to compare two numbers or to
perform an arithmetic operation on two numbers, i.e. addition, subtraction, square root, etc.)

2. (2 + 6 points) Selection sort is the following sorting algorithm: In the first round we find
the minimum of the input array A[1 : n] and move this minimum into A[1] by swapping this
minimum and A[1] using one single swap. In the 2nd round, we find the minimum of A[2 : n]
and move this minimum into A[2] by one single swap, and so on. To find the minimum in an
array we use the algorithm we learned in class.
(a) Why is this algorithm correct? 1 or 2 sentences are enough to explain this.
(b) Give an upper bound for the worst-case running time, i.e. give such an estimation that is
valid for all possible inputs (without identifying the worst input). The size of the input is the
length of the input array (i.e. n) and the basic steps are comparisons and swaps.

3. (10 points) We know that T (n) ≤ 2n2 + T (n − 2), if n ≥ 3 and T (1) = T (2) = 1. Prove that
T (n) ≤ n3 for all n ≥ 1.

Deadline for these regular problems: 15 February 8:00 am (CET)

You might also like