Question: Part I: Algorithm Analysis 1 . You are given two linked lists with O ( n ) elements. You are asked to find the intersection

Part I: Algorithm Analysis
1. You are given two linked lists with O(n) elements. You are asked to find the intersection of two lists. Assume that the sets dont have duplicates and not sorted, and also assume that comparison operation is a simple statement and it takes O(1) time.
a. Please provide a pseudo code that has the growth rate of O(n2)
b. Improve your solution, and give a pseudo code that has a better growth rate which is O(nlogn).
c. Is it possible to make it O(n)? Please provide a pseudo code for your solution, if any.
Note: You can call other functions use other data structures, you dont need to give pseudocodes for those functions. Just know their run time complexity.
2. You are given the following pseudocode for an algorithm:
1 method1(n)
2 if n==0
3 return 0
4 else
5 return method2(n-1, n-1)(n-1)
6 method2(m, k)
7 if m==0
8 return method1(k)
9 else
10 return 1+ method2(m-1, k)
a. What would be the output for the following method call?
System.out.println(method1(4));
b. Please provide the recurrence form for the running time function of this algorithm.
c. Please find the growth rate of the algorithm in Big-O notation.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!