Analysis of algorithms | Computer Science homework help

CS 5200 Homework -1
(Deadline: 09-17-2023 11:59pm)

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

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

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:
The price is based on these factors:
Academic level
Number of pages
Basic features
  • Free title page and bibliography
  • Unlimited revisions
  • Plagiarism-free guarantee
  • Money-back guarantee
  • 24/7 support
On-demand options
  • Writer’s samples
  • Part-by-part delivery
  • Overnight delivery
  • Copies of used sources
  • Expert Proofreading
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.

Read more

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.

Read more

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.

Read more

Privacy policy

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.

Read more

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.

Read more

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.

Let Professionals Take Care of your Academic Paper