Question: . Suppose we have the following algorithm: 1 : Algorithm Cartesian ( A , B , n ) 2 : Input: A and B ,

. Suppose we have the following algorithm:
1: Algorithm Cartesian(A, B, n)
2: Input: A and B, two n-element lists
3: Output: The Cartesian product of the two lists: [[A[0], B[0]],[A[0], B[1]],...]
4: Let C be an empty list
5: for i from 0 to n 1 do
6: for j from 0 to n 1 do
7: Add [A[i], B[j]] to the end of C
8: return C
9: End.
(a) What is the time complexity using the RAM model (i.e., directly counting operations)?
Make sure you explain your answer in terms of the operations you consider primitive.
(b) Is this algorithms running time O(n
3
)? Why or why not?
(c) Is this algorithms running time \Theta (n
2
)? Why or why not?
(d) Is this algorithms running time (n)? Why or why not?

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!