Docsity

CSCE 350 Data Structures & Algorithms: Preparation Questions for Midterm 2, Exams of Computer Science

Toggle sidebar
bg1
CSCE 350 Data Structures & Algorithms, Questions to Prepare MT2
1. Solve the following recurrence relations:
a. M(n) = 2M(n-1) + 1 for n > 1; M(1) = 1
(This is the “Towers of Hanoi recurrence.” Solve exactly.)
b. T(n) = 3T(n/2) + n for n > 1; T(1) = 1
(Solve in terms of Θ(n))
c. M(n) = 7M(n/2) for n > 1; M(1) = 1
(This is the recurrence for the number of multiplications to multiply two nxn matrices
using Strassen’s algorithm. Solve it exactly for n a power of 2.)
d. W(n) = W(0.9n) + 1.6n for n >1; W(1) is in O(1)
(This is the recurrence for the number of comparisons to find the median using the Select
algorithm. Solve it in terms of Θ(n).)
2. 3^n is in Θ(2^n). True or false? Prove your answer.
3. Write the recurrence relation for the worst case of mergesort. Assume that the size of the array to
be sorted is a power of 2. Assume that the worst case complexity of merging to arrays of total size
n is (n-1).
4. Give tight upper and lower bounds for the sum of 1/i for i from 1 to n. (Use integrals.)
5. Set up the recurrence relation for the average case of quicksort, assuming (as usual) that any
position of the pivot in the array is equally likely. (Do not solve the recurrence; just set it up.)

Partial preview of the text

Download CSCE 350 Data Structures & Algorithms: Preparation Questions for Midterm 2 and more Exams Computer Science in PDF only on Docsity!

CSCE 350 Data Structures & Algorithms, Questions to Prepare MT

  1. Solve the following recurrence relations: a. M(n) = 2M(n-1) + 1 for n > 1; M(1) = 1 (This is the “Towers of Hanoi recurrence.” Solve exactly.)

b. T(n) = 3T(n/2) + n for n > 1; T(1) = 1 (Solve in terms of Θ(n))

c. M(n) = 7M(n/2) for n > 1; M(1) = 1 (This is the recurrence for the number of multiplications to multiply two nxn matrices using Strassen’s algorithm. Solve it exactly for n a power of 2.)

d. W(n) = W(0.9n) + 1.6n for n >1; W(1) is in O(1) (This is the recurrence for the number of comparisons to find the median using the Select algorithm. Solve it in terms of Θ(n).)

  1. 3^n is in Θ(2^n). True or false? Prove your answer.
  2. Write the recurrence relation for the worst case of mergesort. Assume that the size of the array to be sorted is a power of 2. Assume that the worst case complexity of merging to arrays of total size n is (n-1).
  3. Give tight upper and lower bounds for the sum of 1/i for i from 1 to n. (Use integrals.)
  4. Set up the recurrence relation for the average case of quicksort, assuming (as usual) that any position of the pivot in the array is equally likely. (Do not solve the recurrence; just set it up.)