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

a) O(1)

b) O(logn)

c) O(n)

d) None of these

explain briefly.
retagged by

1 Answer

3 votes
3 votes

As suggested by  abhishekmehta4u:

We can do this in O(logn) time by comparing medians of both arrays. Since both of them are of the same size, we can continuously divide the problem in half until we find medians of the same size.

More information here: 

https://www.geeksforgeeks.org/median-of-two-sorted-arrays/amp/

 

My previous less efficient answer:

It is given that you have to find the middle element of union sorted array.
So given an array of size 2n, the middle element can be found in O(1) time.
(P.S. if we have to first combine them, then it would take O(n + n) = O(n) time to combine and then O(1) time to find the middle element. So total time will be O(n) in this case)

 

edited by

Related questions

0 votes
0 votes
2 answers
2
_Madhuri asked Oct 9, 2021
668 views
The complexity of comparison based sorting algorithm is (nlogn) .How?
0 votes
0 votes
1 answer
3
Smishra95 asked Sep 28, 2018
2,072 views
Given an array where numbers are in range from 1 to n6 , which sorting algorithm can beused to sort these number in linear time?A. Not possible to sort in linear timeB: C...
0 votes
0 votes
0 answers
4