Describe an algorithm that, given a list of n numbers, decides in linear time whether the list contains at least ⌈n/2⌉ numbers, all with equal value.
What if we want to know if there are at least ⌈ n/100 ⌉ numbers with equal value?
Hint: suppose some number, x, occurs ⌈n/2⌉ times. Where could all of these copies end up if we sorted? (This is not a suggestion we should actually sort). Wherever they end up, find one invariant.
`Hey,
Note: Brother if you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
To run the algo for n/2 use it as checkSame(A,2)
To run it as n/100 use it as checkSame(A,100)
The Time complexity of above algo is O(n*log(n))
Kindly revert for any queries
Thanks.
Get Answers For Free
Most questions answered within 1 hours.