retagged by
3,079 views
3 votes
3 votes
Given 2 sorted arrays each of n-elements and distinct. How much time it will take to find middle element of union array?

(a) O(1)

(b) O(log n)

(c) O(n)

(d) None of these
retagged by

5 Answers

9 votes
9 votes
1 votes
1 votes
Answer would be O(nlgn)

In order to find middle of union array atleast half of both the arrays should be compared and we can do this by using binary search on both the arrays, so three cases arrives,

1) both m/2 and n/2 array are covered then we will find the middle element (or)

2) array 1 is totally over (or)

3) array 2nd is totally over

 

In all these three cases binary search will take O(nlgn)
1 votes
1 votes
@arjun , @bala sir can you please check ...i think answer should be O(n) as it will take O(n+n) time (merge procedure) to create 1 sorted array and then O(1 ) to get middle element.....

and O(log n) is not right? and if not why?
0 votes
0 votes
It will take O(n)  because you have to first find the union of both both array is sorted than we can find union by merge algorithm and you know merge algorithm take O(n) time after that middle element n/2 constant time O(1) overall it will take O(n) time

Related questions

0 votes
0 votes
2 answers
1
Rustam Ali asked Sep 5, 2018
1,741 views
What is the time complexity of calculating power of an element using DAC?
0 votes
0 votes
0 answers
2
Emankashyap asked 5 days ago
46 views
In quick sort, n numbers the (n/10)th element is selected as pivot using n^2 sortimng time complexity what will be the time complexity of quick sort is.....a)O(nlogn)b)O(...
1 votes
1 votes
1 answer
3
meethunjadhav asked Jul 30, 2018
448 views
suppose merge sort takes 2 sec to sort a set of 64 keys then how much time will take to sort a set of 512 keys?here, ans is 24 sec how it is plz explain me.