CS3240: Data Structures and Algorithms

 

Solving for T(n) given recursive equation

 

 

QUESTION 0)

 

SOLUTION:

 

  • IF it takes 10ms to run program (b) for n=100, how long will it take to run for n=400 (answer = 20ms)

 

 

QUESTION 1) Solve the recurrence T(n) = aT( n/ b ) for a;b > 1.

T(n) solution

 

 

 

QUESTION 2) Describe a Theta (nlogn)-time algorithm that, given a set S of n integers and another integer x,
determines whether or not there exist two elements in S whose sum is exactly x.

 

  1. Sort the set S using merge sort. (we will see later this is )

  2. Then for each y in S separately use Binary Search to check if integer = (x-y)
    exists in S. Binary search takes and is done n times -> hence

 

Question 3) Can we solve the problem for question 2 in linear time if we have a Sorted List?

© Lynne Grewe