0% found this document useful (0 votes)
207 views6 pages

CSE310 Assignment 2

This document describes Assignment #2 for CSE 310, which is due on September 16th, 2022. It consists of 6 questions related to asymptotic analysis, recurrence relations, and divide-and-conquer algorithms. Students are instructed to type their solutions in PDF format and submit through Canvas by the due date/time. Late submissions will not be accepted. The questions involve sorting functions by asymptotic complexity, deriving recurrences and bounds for divide-and-conquer algorithms, and designing divide-and-conquer algorithms to solve problems like finding the largest difference between array elements and counting pairs that satisfy a given condition.

Uploaded by

Rishon D Netala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
207 views6 pages

CSE310 Assignment 2

This document describes Assignment #2 for CSE 310, which is due on September 16th, 2022. It consists of 6 questions related to asymptotic analysis, recurrence relations, and divide-and-conquer algorithms. Students are instructed to type their solutions in PDF format and submit through Canvas by the due date/time. Late submissions will not be accepted. The questions involve sorting functions by asymptotic complexity, deriving recurrences and bounds for divide-and-conquer algorithms, and designing divide-and-conquer algorithms to solve problems like finding the largest difference between array elements and counting pairs that satisfy a given condition.

Uploaded by

Rishon D Netala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

CSE 310 Assignment #2

(Max. Points: 30)

Due on: Friday, Sep. 16, 2022, 11:59pm Arizona time

General Instructions:
• This is an individual assignment, please do not collaborate
• For all written exercises: your answer should be clearly typed or written and must be
saved in .pdf format. Note: unreadable answer receives no credits!
• For this assignment, you will need to submit your typed solution through the link posted
on Canvas, we do NOT accept any hand-in submissions or submissions sent through
emails!
• Submission link will be closed automatically once the due date/time is past and no late
assignment will be accepted.
• You will be allowed 2 times to submit the assignment on Canvas, but we will only grade
your last submission.

Objectives
• Asymptotic notation.
• Recurrence, Master method, etc.
• Divide and Conquer algorithms

Questions

1. [6 pts, 2 pts each] For each group of functions, sort the functions in increasing order of
asymptotic (big-O) complexity.

A) Group A 𝑓1 (𝑛) = 𝑛 ∙ 2𝑛
𝑓2 (𝑛) = 𝑛√𝑛
𝑓3 (𝑛) = 𝑛10 ∙ 2𝑛/2
𝑓4 (𝑛) = 𝑛!

B) Group B 𝑓1 (𝑛) = 𝑛1.0001


𝑓2 (𝑛) = 𝑛0.9999 𝑙𝑜𝑔𝑛
𝑓3 (𝑛) = 𝑛2
𝑓4 (𝑛) = 1.00001𝑛

1
C) Group C 𝑓1 (𝑛) = 𝑛√𝑛
𝑓2 (𝑛) = 2𝑛
100𝑛
𝑓3 (𝑛) = 22
𝑓4 (𝑛) = 2100𝑛

2. [3 pt] Give asymptotic upper and lower bounds for the following recursion by drawing a
recursion tree.
𝑛 𝑛 𝑛
𝑇(𝑛) = 𝑇 ( ) + 𝑇 ( ) + 𝑇 ( ) + 𝑛
2 4 8

2
3. [2 pts each, total 6 pts] Give tight asymptotic bounds (θ bound) for each of the following
recurrences. If you used the master method, clearly specify a, b, f(n) or ε value and which case
you applied; if not, justify your answer.
𝑛
A) 𝑇(𝑛) = 4𝑇 ( 3 ) + 𝑛𝑙𝑔𝑛

𝑛
B) 𝑇(𝑛) = 5𝑇 ( 5) + 𝑛𝑙𝑔𝑛

𝑛
C) 𝑇(𝑛) = 9𝑇 ( 3) + 𝑛2

3
4. [Total: 3 pts] Given a sorted one-dimensional array A[1..n] of integers and a key k, we
consider the problem of finding number of A elements that less or equals to k. For example, for
the following array, if k = 23, the answer to this question should be 5.

1 2 3 4 5 6 7 8

5 7 9 13 19 25 31 45

Question #1 [2 pts]: Design a linear algorithm (running time 𝑂(𝑛)) to solve this problem.
Clearly write your algorithm in pseudo-code similar as those algorithms in your textbook).

Question #2 [1 pt]: Can you do better? Consider a strategy similar as we used in binary search,
design an algorithm which runs in 𝑂(𝑙𝑔𝑛) time for this problem, write your algorithm in pseudo-
code and give the recurrence equation, solve it.

4
5. [Total 6 pts] Given a one-dimensional array A[1..n] (n ≥ 2), we consider the problem of finding
the largest difference between two elements located at index i and j such that Diff(i, j) = A[j] –
A[i] is maximized over all 1 ≤ 𝑖 < 𝑗 ≤ 𝑛. Use the following array as an example, the respective
solution for this problem will be i = 5, j = 8 and Diff(5, 8) = 3 – (-3) = 6.

1 2 3 4 5 6 7 8

7 5 8 10 -3 1 -2 3
↑ ↑
Question #1 [4 pts]: Let us use Largest_Diff(A, 1, n) to represent the solution, apply the divide-
and-conquer technique to design an algorithm which solves the problem. Clearly write your
algorithm in pseudo-code similar as those in your textbook and feel free to add additional return
values if needed.

Question #2 [2 pts]: Let T(n) be the running time of Largest_Diff(A, 1, n) in question #1. Write
the recurrence expressing T(n) in terms of T(k) for some k < n. Use the Master theorem to
determine the upper bound of T(n).

5
6. [Total 6 pts] Given a one-dimensional array A[1..n] (n ≥ 2), we consider the problem of finding
number of pairs (i, j), such that: 1 ≤ 𝑖 < 𝑗 ≤ 𝑛, and A[i] > 3* A[j]. Use the following array as an
example, the respective solution for this problem should be 7 and the corresponding pairs are:
(1, 6), (2, 6), (3, 5), (3, 6), (4, 5), (4, 6), (4, 8)

1 2 3 4 5 6 7 8

4 5 8 10 2 1 7 3

Question #1 [4 pts]: Let us use Pairs(A, 1, n) to represent the solution, apply the divide-and-
conquer technique to design an algorithm which solves the problem. Clearly write your
algorithm in pseudo-code similar as those in your textbook and feel free to add additional return
values if needed.

Question #2 [2 pts]: Let T(n) be the running time of Pairs(A, 1, n) in question #1. Write the
recurrence expressing T(n) in terms of T(k) for some k < n. Solve it to determine the upper bound
of T(n).

You might also like