HW03 CSCI570 - Spring2023
HW03 CSCI570 - Spring2023
Spring 2023
Due Date: Feb. 25, 2023 at 11:59 P.M.
1. Suppose you are responsible for organizing and determining the results
of an election. An election has a winner if one person gets at least half
of the votes. For an election with n voters and k candidates, design an
optimal algorithm to decide if the election has a winner and finds that
winner. Analyze the time complexity of your algorithm.
2. Alice has learned the sqrt function in her math class last week. She thinks
that the method to compute sqrt function can be improved at least for
perfect squared numbers. Please help her to find an optimal algorithm
to find perfect squared numbers and their squared root.
3. Alice has recently started working on the Los Angeles beautification
team. She found a street and is proposing to paint a mural on their
walls as her first project. The buildings in this street are consecutive,
have the same width but have different heights. She is planning to paint
the largest rectangular mural on these walls. The chance of approving
her proposal depends on the size of the mural and is higher for the larger
murals. Suppose n is the number of buildings in this street and she has
the list of heights of buildings. Propose a divide and conquer algorithm
to help her find the size of the largest possible mural and analyze the
complexity of your algorithm. The picture below shows a part of that
street in her proposal and two possible location of the mural:
4. Solve the following recurrence using the master theorem.
a) T (n) = 8T ( n2 ) + n2 log(n)
b) T (n) = 4T ( n2 ) + n!
√
c) T (n) = 2T ( n4 ) + n
n
d) T (2n ) = 4T (2n−1 ) + 2 2
5. Suppose you have a rod of length N, and you want to cut up the rod and
sell the pieces in a way that maximizes the total amount of money you get.
A piece of length i is worth pi dollars. Devise a Dynamic Programming
Figure 1: The example in Q3
167 = 3 * 1 * 5 + 3 * 5 * 8 + 1 * 3 * 8 + 1 * 8 * 1.
a. Define (in plain English) subproblems to be solved.
b. Write a recurrence relation for the subproblems
c. Using the recurrence formula in part b, write pseudocode to find the
solution.
d. Make sure you specify
i. base cases and their values
ii. where the final answer can be found
e. What is the complexity of your solution?
10. Online Questions. Please go to DEN (https://courses.uscden.net/)
and take the online portion of your assignment.