• retagged by
2,263 views
0 0 votes
A Sorted array of n elements contains 0 and 1 to find out majority of 0 and 1.How much time it will take???

and please explain  Meaning -majority of 0 and 1??

1 Answer

5 5 votes
I think the answer should be O(1) as the middle element can be found in constant time as the n/2th element is the middle element in. Once found, it can be compared. If it is found to be 1 then the majority is 1 otherwise 0 as it is given as sorted array.
Position:
Show:

Related questions

7 7 votes
1 1 answer
440
440 views
GO Classes asked Jul 3
440 views
A sequence of $n$ elements is implemented in two ways:As a normal array with contiguous memory and no extra empty slot. As a singly linked list with only a $\texttt{head}...
1 1 vote
1 1 answer
1.1k
1.1k views
Souvik33 asked Dec 17, 2022
1,086 views
What is the worst case time complexity of an efficient algorithm (in order of n) to get the last index for an actually filled element, in an array, given the condition th...
0 0 votes
0 0 answers
804
804 views
kauray asked Jan 6, 2019
804 views
A two dimensional array is stored in column major form in memory if the elements are stored in the following sequence $$A[0][0] A [0] A [0]...A[n_1-1][0] ... A[0] A .....
1 1 vote
1 1 answer
4.5k
4.5k views
sripo asked Nov 15, 2018
4,523 views
This question is in CLRS,if we have a max heap it is always in sorted order(descending) order.And by extension if we have min heap the array is sorted in ascending order....