Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

Semester 2, 2022

Tutorial 1

COMP3600/6466 - Algorithms

Exercise 1                                                            Math Refresher

Assume n is continuous

1. Calculate limn →∞

2. Calculate limn →∞   (where a > b, a > 0, and b > 0)

3. Calculate limn →∞

4. Please transform nlog n  into the form of a power of 2

5. Please compute the sum of the first consecutive n odd positive integers

6. The cost of building the first level of an apartment building is 5U, and each subsequent level is more expensive by 2U . How much is the total cost for building an apartment with ℓ levels? Please specify your answer in terms of ℓ and U .


Exercise 2                                                                  Time Complexity

Please derive the worst case total time required by the following algorithms, assuming they are executed in a RAM computational model. Please represent your total time in terms of the size of the input array (i.e., A.length). This total time is similar to the notation T(n) in InsertionSort analysis covered in the first two lectures. Please also provide the tight bound (i.e., Θ) of the total time.

Algorithm 1 BubbleSort(An array of integers A)

1:  for i = 1 to A.length do

2:       for j = A.length downto i + 1 do

3:              if A[j] < A[j − 1] then

4:                   Swap A[j] and A[j − 1]


Algorithm 2 BinarySearch(A sorted array of integers A, An integer v)

1:  Let s = 1

2:  Let e = A.length

3:  while s e do

4:       m =]

5:       if A[m] == v then

6:            Return m

7:       else if A[m] < v then

8:            Let s = m + 1

9:       else

10:            Let e = m − 1

Exercise 3                                                    Estimation of Input Size

Estimate the largest upper bound on the input size required for a modern computer (under the RAM model) to run an algorithm in 1 second, assuming the computer executes exactly one hundred million operations per second.

 

Exercise 4                                          Properties of Asymptotic Notations

1. Suppose f1 (n) = O(g1 (n)) and f2 (n) = O(g2 (n)). Is it true that f1 (n) + f2 (n) = O(g1 (n) + g2 (n))? Please provide a proof or counter example.

2. Suppose f1 (n) = O(g1 (n)) and f2 (n) = O(g2 (n)). Is it true that f1 (n) · f2 (n) = O(g1 (n) · g2 (n))? Please provide a proof or counter example.

3. Can a function f(n) be both in O(g(n)) and ω(g(n))? Please explain why or why not.