Daa_assign3
Daa_assign3
- NITK Surathkal
CS-253 Design and Analysis of Algorithms
Assignment sheet- 3 Due Date: 14th April 2025
Greedy algorithms and Dynamic Programming
1. Dance partners: You are pairing couples for a very conservative formal ball. There are n men
and m women, and you know the height and gender of each person there. Each dancing couple must
be a man and a woman, and the man must be at least as tall as, but no more than 3 inches taller than,
his partner. You wish to maximize the number of dancing couples given this constraint.
2. Homework grade maximization: In a class, there are n assignments. You have H hours to spend
on all assignments, and you cannot divide an hour between assignments, but must spend each hour
entirely on a single assignment. The I’th hour you spend on assignment J will improve your grade
on assignment J by B[I, J], where for each J, B[1, J] ≥ B[2, J] ≥ ... ≥ B[H, J] ≥ 0. In other words, if
you spend h hours on assignment J, your grade will be Σi=1 B[I, J] and time spent on each project
has diminishing returns, the next hour being worth less than the previous one. You want to divide
your H hours between the assignments to maximize your total grade on all the assignments.
Give an efficient algorithm for this problem.
4. Alice wants to throw a party and is deciding whom to call. She has n people to choose from, and
she has made up a list of which pairs of these people know each other. She wants to pick as many
people as possible, subject to two constraints: at the party, each person should have at least five
other people whom they know and five other people whom they don’t know.
Give an efficient algorithm that takes as input the list of n people and the list of pairs who know
each other and outputs the best choice of party invitees. Give the running time in terms of n.
6. You are going on a long trip. You start on the road at mile post 0. Along the way there are n
hotels, at mile posts a1 < a2 < · · · < an , where each ai is measured from the starting point. The
only places you are allowed to stop are at these hotels, but you can choose which of the hotels
you stop at. You must stop at the final hotel (at distance an ), which is your destination.Algorithms
You’d ideally like to travel 200 miles a day, but this may not be possible (depending on the spacing
of the hotels). If you travel x miles during a day, the penalty for that day is (200 − x)2 . You want
to plan your trip so as to minimize the total penalty—that is, the sum, over all travel days, of the
daily penalties.
Give an efficient algorithm that determines the optimal sequence of hotels at which to stop.
7. A subsequence is palindromic if it is the same whether read left to right or right to left. For
instance, the sequence A, C, G, T, G, T, C, A, A, A, A, T, C, G has many palindromic
subsequences, including A, C, G, C, A and A, A, A, A (on the other hand, the subsequence A, C, T
is not palindromic). Devise an algorithm that takes a sequence x[1 . . . n] and returns the (length of
the) longest palindromic subsequence. Its running time should be O(n2 ).
10. Consider the following variation on the change-making problem (Exercise 11.): you are given
denominations x1 x2 · · · xn , and you want to make change for a value v, but you are allowed to
use each denomination at most once. For instance, if the denominations are 1, 5, 10, 20, then you
can make change for 16 = 1 + 15 and for 31 = 1 + 10 + 20 but not for 40 (because you can’t use 20
twice).
Input: Positive integers x1 x2 · · · xn ; another integer v.
Output: Can you make change for v, using each denomination xi at most once?
Show how to solve this problem in time O(nv).
11. Given a convex polygon P = (v0, . . . , vn−1), and a weight function w on triangles, find a
triangulation minimizing the total weight.
12. In the art gallery gaurding problem we are given a line L that represents a long hallway in
an art gallery. We are also given a set X= x1 x2 · · · xn-1 of real numbers that specify the positions of
the paintings in this hallway. Suppose that a single gaurd can protect all the paintings within
distance at most 1 of his or her position(on both sides). Design an algorithm for finding a placement
of gaurds that uses the minimum number of gaurds to gaurd all the paintings with position in X .