0% found this document useful (0 votes)
8 views2 pages

HW1CS3520 (S25)

This document outlines the homework assignment for CS3520: Design & Analysis of Algorithms for Spring 2025, due on March 10, 2025. It includes eight questions covering topics such as algorithm efficiency, distinct elements in arrays, computing ranges, identifying fake coins, and mathematical proofs. Each question specifies points and requires students to apply algorithm analysis techniques and mathematical induction.

Uploaded by

Javeria Fazal
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)
8 views2 pages

HW1CS3520 (S25)

This document outlines the homework assignment for CS3520: Design & Analysis of Algorithms for Spring 2025, due on March 10, 2025. It includes eight questions covering topics such as algorithm efficiency, distinct elements in arrays, computing ranges, identifying fake coins, and mathematical proofs. Each question specifies points and requires students to apply algorithm analysis techniques and mathematical induction.

Uploaded by

Javeria Fazal
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/ 2

MAJU

Department of Computer Science


CS3520: Design & Analysis of Algorithms
Semester Spring 2025

Dated: 3rd March 2025


Due Date: 10th March 2025 (In class)
Home Work # 1

Q1. (15 points) Use the definitions of O, Θ and Ω to determine whether the following assertions are true
or false. Suggest corrections (tightest bounds) for the incorrect ones.

a. 6n2 – 8n ∈ Θ(n2)
b. 12n2 + 8n ∈ O(n).
c. 3n23n + n log n = Θ(n23n)
d. 3n2 log n = Θ(n2)

Q2. (10 points) One can check whether all elements of an array are distinct (unique) by a two-part
algorithm based on the array’s presorting.

If sorting is done by an algorithm with a time efficiency in Θ(n log n), what will be a time-efficiency
class of the entire algorithm (that identifies if the elements of given array are distinct) in both best case
and worst case scenarios?

Q3. (15 points) Prove that the following assertion is true for all values of n ≥ n0. Identify both n0 and c.

2n + 5∈ O(n2)

Q4. (15 points) The range of a finite nonempty set of n real numbers S is defined as the difference
between the largest and smallest elements of S. For each representation of S given below, describe in
English an algorithm to compute the range. Indicate the time efficiency classes of these algorithms using
the most appropriate notation (O, Θ or Ω).
a. An unsorted array
b. A sorted array
c. A sorted singly linked list

Q5. (10 points) Lighter or heavier? You have n > 2 identical-looking coins and a two-pan balance
scale with no weights. One of the coins is a fake, but you do not know whether it is lighter or
heavier than the genuine coins, which all weigh the same. Design a Θ(1) algorithm to determine whether
the fake coin is lighter or heavier than the others.

Q6. (10 points) Compute the closed form of the following sums (using formulas from the lecture).

1. ∑𝑛+1
𝑖=3 1
𝑛−1
2.∑𝑖=0 i(i + 1)

Q7. (15 points) Consider the following algorithm:

ALGORITHM Sum(n)
//Input: A nonnegative integer n
S←0
for i ←1 to n do
S←S+i
return S

1
a. What does this algorithm compute?
b. What is its basic operation?
c. How many times is the basic operation executed?
d. What is the efficiency class of this algorithm?
e. Suggest an improvement, or a better algorithm altogether, and indicate its efficiency class. If you
cannot do it, try to prove that, in fact, it cannot be done.
Q8. (10 points) Prove the formula
𝑛

∑ i = 1 + 2 + ⋯ + n = n(n + 1)/2
𝑖=1
by mathematical induction.

You might also like