0% found this document useful (0 votes)
33 views

Design and Analysis of Algorithms - Tutorial Sheet Practice

The document discusses algorithms analysis and design problems including finding the median of values from two databases using fewest queries, implementing Horner's rule for polynomial evaluation, modifying Strassen's matrix multiplication algorithm, solving problems using FFT algorithms, finding local minima in a grid graph using few probes, and solving the Josephus problem in linear time.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Design and Analysis of Algorithms - Tutorial Sheet Practice

The document discusses algorithms analysis and design problems including finding the median of values from two databases using fewest queries, implementing Horner's rule for polynomial evaluation, modifying Strassen's matrix multiplication algorithm, solving problems using FFT algorithms, finding local minima in a grid graph using few probes, and solving the Josephus problem in linear time.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Tutorial 7, Design and Analysis of Algorithms, 2024

1. You are interested in analyzing some hard-to-obtain data from two separate databases. Each
database contains n numerical values - so there are 2n values total - and you may assume
that no two values are the same. You would like to determine the median of this set of 2n
values, which we will define here to be the n’th smallest value. However, the only way you
can access these values is through queries to the databases. In a single query, you can specify
a value k to one of the two databases, and the chosen database will return the k’th smallest
value that it contains. Since queries are expensive, you would like to compute the median
using as few queries as possible. Give an algorithm that finds the median value using at most
O(log n) queries.

2. Horner’s Rule to evaluate a polynomial of the form a0 + a1 x + a2 x2 + . . . + an xn devices a


strategy that computes the polynomial in a way similar to a0 + x(a1 + x(a2 + . . . + n(an−1 +
xan ) . . .). Write a pseudocode to implement Horner’s rule and also give proof of its correct-
ness by clearly providing loop invariant.

3. How would you modify Strassen’s algorithm to multiply n × n matrices in which n is not an
exact power of 2? Show that the resulting algorithm runs in time Θ(nlog2 7 ).

4. (a) Find the number of nodes in the divide and conquer graph for computing FFT of a vector
of length n (for simplicity you can assume n to be a power of 2).
(b) Now find time complexity of the FFT algorithm by only considering the structure of the
divide and conquer graph (without solving any recursion).

5. Find 1234 × 4321 using the FFT algorithm showing its divide and conquer graphs.

6. (a) Describe the generalization of the FFT procedure to the case in which n is a power
of 3 (using three subproblems). Give a recurrence for the running time, and solve the
recurrence.
(b) Find 97 × 68 using the above algorithm showing its divide and conquer graphs.

7. In the Modular FFT Algorithm, instead of performing an n−element FFT over complex
numbers (where n is even), we use the complete residue system modulo m (Zm ), where m =
2tn/2 + 1 and t is an arbitrary positive integer. Instead of addition of complex numbers, we
use addition modulo m. Instead of multiplication of complex numbers, we use multiplication
modulo m. We use ω = 2t instead of ωn as a principal nth root of unity, modulo m. Instead
of ωn−1 , we use the inverse ω −1 of ω computed in Zm using efficient algorithms. Find
(2x + 1) × (3x + 2) using the Modular FFT Algorithm (by taking t = 8) showing its divide
and conquer graphs.

8. Consider two sets A and B, each having n integers in the range from 0 to 10n. We wish to
compute the Cartesian sum of A and B, defined by
C = { x + y | x ∈ A, y ∈ B }.
Note that the integers in C are in the range from 0 to 20n. We want to find the elements of

1
C and the number of times each element of C is realized as a sum of elements in A and B.
Design an O(n log n)-time algorithm to solve this problem.

9. Consider an n × n grid graph G. (An n × n grid graph is just the adjacency graph of an n × n
chessboard. To be completely precise, it is a graph whose node set is the set of all ordered
pairs of natural numbers (i, j), where 1 ≤ i ≤ n and 1 ≤ j ≤ n; the nodes (i, j) and (k, l) are
joined by an edge if and only if |i − k| + | j − l| = 1.) Each node v of G is labeled with a real
number xv . You may assume that the real numbers labeling the nodes are all distinct. A node
v of G is a local minimum if the label xv is less than the label xw for all nodes w that are joined
to v by an edge. You are given such an n × n grid graph G, but the labeling is only specified
in the following implicit way: for each node v, you can determine the value xv by probing
the node v. Show how to find a local minimum of G using only O(n) probes to the nodes of
G. Give a proof of correctness of your algorithm and also prove its time complexity.

10. In the Josephus Problem, we start with n people numbered 1 to n around a circle, and we
eliminate every second remaining person until only one survives. For example, the elimina-
tion order for n = 10 is 2, 4, 6, 8, 10, 3, 7, 1, 9, so 5 survives. The problem is to determine the
survivor’s number, J(n) (in the above example, we have J(10) = 5). Design a linear time
complexity algorithm for computing J(n).

You might also like