CSE321 – Homework 2 (Solution)

$ 20.99
Category:

Description

CSE321 – Introduction to Algorithm Design
1) Solve the following recurrence relations by using Master theorem. If any of the problems cannot be solved by using Master theorem, state that it cannot be solved and explain the reason.
a) !
b)
c)
d)
e)
f)
g)
2) Consider the following three algorithms:
a) Algorithm X solves problems by dividing them into nine subproblems that have one-third of the size, recursively solving each subproblem, and then combining the solutions in quadratic time.
b) Algorithm Y solves problems of size n by recursively solving 8 subproblems that have half the size and then combining the solutions in O(n3).
c) Algorithm Z solves problems of size n by dividing them into two
subproblems that have a quarter of the size, recursively solving each

subproblem, and then combining the solutions in O( n) time.
What are the running times of each of these algorithms (in big-O notation), and which would you choose? Explain your reasoning in detail.
3) a) Consider the Mergesort algorithm.
i. Give an example of an 8-element array which requires the max-imum number of comparisons, and explain your answer.
ii. Give an example of an 8-element array which requires the mini-mum number of comparisons, and explain your answer.
b) Consider the QuickSort algorithm.
i. Give an example of an 8-element array which requires the max-imum number of swap operations (Assume the pivot is the first element), and explain your answer.
ii. Give an example of an 8-element array which requires the min-imum number of swap operations (Assume the pivot is the last element), and explain your answer.
4) Analyze the following algorithm. Write the recurrence relation of the algorithm, and find the running time complexity by deriving from the recurrence relation.
algorithm(left, right) mid = (left+right)/2 if A[mid]==0 return mid
else
if A[mid] > 0 right = mid algorithm(left, right)
else left = mid algorithm(left, right)
5) Ali is planning to visit his family. Before going, he bought n gifts of different sizes and n corresponding boxes. Write an efficient algorithm that helps Ali to match each gift to its corresponding box by getting help from the QuickSort algorithm. You are allowed to try a gift and box together, from which you can determine whether the gift is larger than the box, smaller than the box, or fits in the box exactly. However, there is no way to compare two gifts together or two boxes together.
a) Write your algorithm in pseudocode.
b) Analyze your algorithm, and write the corresponding recurrence relation. Find the running time complexity of the algorithm by deriving from the recurrence relation.
c) Implement your algorithm in Phyton.
Notes
2. No collaboration is allowed, the homework must be done individually.
3. The homework will be submitted in ZIP format. The file hierarchy willbe this:
CSE321 HW2 [StudentID].zip
| → CSE321 HW2 ANS [StudentID].pdf
| → matchGiftBox [StudentID].py

Reviews

There are no reviews yet.

Be the first to review “CSE321 – Homework 2 (Solution)”

Your email address will not be published. Required fields are marked *