# Analysis of algorithms | Computer Science homework help

CS 5200 Homework -1

Instructor: Huiyuan Yang

Q1. Complexity analysis [11%]

1) Consider the following algorithm (assume n >1)

int any-equal (int n, int A[ ][ ]) {
Index i, j, k, m;
for (i=1; i<=n; i++)
for (j=1; j<=n; j++)
for (k=1; k<=n; k++)
for (m=1; m<=n; m++)
if (A[i][j] == A[k][m] && !(i==k && j==m))
return 1;
return 0;
}

Β§ Show the best case; what is the best-case time complexity. [3%]
Β§ Show the worst case; what is the worst-case time complexity. [3%]
Β§ Try to improve the efficiency of the algorithm. [5%]

Q2. Growth of functions [15%]

1) Using the definition of O(.) and Ξ©(.), show that: [5%]
10π + 8 β π(π!), ππ’π‘ 10π + 8 β Ξ©(π!)

2) Using the definition of Ξ(. ) To show that: [5%]
2π” + 2π! + Ξ(π) β Ξ(π”)

3) Show by using limits that: [5%]
I. 4!#\$% β Ξ(16#)

II. π& β π! + 2π β π(π)

Q3. Master theorem [9%]

Find the asymptotic bound of the recurrence equations T(n) using master theorem when
applies:

I. π(π) = 9π(π/3) + π! + 4
II. π(π) = 6π(π/2) + π! β 2

III. π(π) = 4π(π/2) + π” + 7

Q4. Divide-and-Conquer [25%]

1) Solve the following recurrence equation using recursion tree. [7%]
π(π) = T(n/2) + T(n/4) + T(n/8) + n

2) We have a problem of size n, and two solutions to solve this problem: [8%]

a. Solution-I: runs π! times to solve this problem directly (non-recursive algorithm).
b. Solution-II: is a recursive algorithm, which takes πππππ times to split problem into

two sub-problems with equal size of π/2, and πππ times to combine the results
together.

Show whether the solution-I or solution-II is more efficient.

3) Consider the following algorithm, which return a pair with minimum and maximum in
the list of A.[10%]

Min_Max (A, lt, rt) {
if (rt β lt β€ 1)
Return (min(A[lt], A[rt]), max(A[lt], A[rt]));

(min1, max1) = Min_Max(A, lt, β(lt + rt)/2β);
(min2, max2) = Min_Max(A, β(lt + rt)/2β + 1, rt);

Return (min(min1, min2), max(max1, max2));
}

Β§ Write the recurrence equation for the code above. [3%]
Β§ Solve the recurrence equation. [2%]
Β§ Show by example why the algorithm works. (hint: you can show each step when

call the Min_Max() function with a list of size 6, etc). [5%]

Q5. Programming [35%]
Implement the algorithm for finding the closest pair of points in two-dimension plane using the
Divide-and-Conquer strategy.

Β§ Compile without errors (by calling make) [5%]
Β§ Use the brute-force approach to solve the problem and print out the execution time. [5%]
Β§ Use the Divide-and-Conquer strategy to solve the problem and print out the execution

time. [25%]

Bonus: [Extra 20%]
Design an algorithm: Given an integer array of 2π integers.

(1) Partition the list into two arrays of length π, such that the difference between the
sums of the two sub-arrays is maximized; show the time complexity. [5%]

(2) Partition the list into two arrays of length π, such that the difference between the
sums of the two sub-arrays is minimized; show the time complexity. [15%]

Submission requirements: [5%]
Put the theory part and code into a folder with the name: [YourStudentID-YourName-HW1].zip

Β§ Following all the submission requirements [5%]
Β§ Theory part:

o You solution should be clear, concise but also contain enough details.
o Only PDF format is allowed.
o Please make sure the scanned PDF file is high-resolution and easily readable if

you wrote your solution on paper.
Β§ Programming part:

o A sanity check to test the correctness of your algorithm.
o Your program will read an input file and write an output file.
o Your program will be called like this: prompt>./hw1 ./input.txt. ./output.txt
o Your code should be complied by calling the makefile.

## Calculate the price of your order

Choose an academic level, add pages, and the paper type you want.
To reduce the cost of our essay writing services, select the lengthier deadline.
We can't believe we just said that to you.

550 words
We'll send you the first draft for approval by September 11, 2018 at 10:52 AM
Total price:
\$26
The price is based on these factors:
Number of pages
Urgency
Basic features
• Free title page and bibliography
• Unlimited revisions
• Plagiarism-free guarantee
• Money-back guarantee
On-demand options
• Writerβs samples
• Part-by-part delivery
• Overnight delivery
• Copies of used sources
Paper format
• 275 words per page
• 12 pt Arial/Times New Roman
• Double line spacing
• Any citation style (APA, MLA, Chicago/Turabian, Harvard)

## Our guarantees

Delivering a high-quality product at a reasonable price is not enough anymore.
Thatβs why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.

### Money-back guarantee

You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.

### Zero-plagiarism guarantee

Each paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.

### Free-revision policy

Thanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.

Your email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.

### Fair-cooperation guarantee

By sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.

## Why is Purdue Papers the Most Helpful Essay Writing Service for You?

1. Custom-written and plagiarism-free papers: Our authors create their work from scratch. Before presenting them to clients, we routinely verify them for signs of plagiarism. Our quality assurance group also double-checks and fixes any grammatical errors, assuring that all of our authors adhere to the same standards of writing.
2. The significance of timely delivery cannot be overstated, and we consistently strive to meet or exceed our clients' deadlines. Regardless of the short time frame, you can count on our writers to get the job done. We always have a team of writers ready to go, even if the deadline is only six hours away.
3. Customer Satisfaction: Our customer service representatives are the best in the business and have a wealth of knowledge in dealing with clients. All our customer service representatives are trained to listen and reply promptly until you are satisfied with their service. To ensure you're happy, our expert writers will strictly follow the criteria to generate a special report. Our customer service may be contacted by chat, email, or phone. In addition, we provide round-the-clock assistance to all of our clients.
4. Confidentiality: Our systems are safe, and your information is always protected. We're constantly looking for new facts when it comes to finishing your work. We use a safe and secure payment channel. Since our ordering process is completely anonymous, you don't have to provide any credit card information to place a purchase with us.
5. Highly Trained Authors: Our writers have received extensive training and are committed to delivering only the best papers. They are fluent in APA, MLA, HARVARD, IEEE, CHICAGO, and AMA referencing styles. To meet your expectations, our skilled writers always pay close attention to your instructions.
6. Lowered prices: We have set prices that are already discounted. Our prices are the best and affordable for all our esteemed customers.