closed by
393 views
2 votes
2 votes
closed with the note: Question booklet questions are not allowed here
a sorted array of n elements contains 0 and 1. to find out majority of 0 and 1 how much ime it will take?

1)O(1)

2)O(logn)

3)O(n)

4)O(n^2)
closed by

2 Answers

1 votes
1 votes

As the array elements are previously sorted ,we will check for middle elements of the array only, i.e:

If n is odd then we will check for (n/2)th element (element at the center) and if it is 0 then 0 is in majority , otherwise 1 is in majority.

if n is even then we will first check for (n/2)th element and if it is 0 then 0 is in majority and if it is 1 then we will check for (n/2-1)th element , if it is 1 then 1 is in majority. 

In both cases number of comparison required are of O(1)

Hence 1) is the correct answer...

0 votes
0 votes
we can do it using binary search..so i think it should be O(logn)..please correct me if i am wrong

Related questions

0 votes
0 votes
1 answer
1
aaru14 asked Dec 6, 2017
242 views
https://gateoverflow.in/?qa=blob&qa_blobid=12037309044418228871someone plz solve this question??
0 votes
0 votes
2 answers
2
viral8702 asked Sep 21, 2023
288 views
The Total Combinations Possible of Min heap with 8 Distinct elements are ?
0 votes
0 votes
1 answer
3
iamdeepakji asked Jan 27, 2019
278 views
If there is negative edge cycle then dijkstra algorithm will give correct path or not same thing about bellman ford also?Bellman ford always halts or not?
0 votes
0 votes
1 answer
4
iamdeepakji asked Dec 27, 2018
410 views
Please solve this by taking some exampleBack edgecross edgetree edgeThankyou.