Wednesday, February 15, 2012

Majority Element in an array

Question 1: Majority element
Write a C function to find if a given integer appears more than n/2 times in an array of n integers.
Basically, we need to write a function say isMajority() that takes an array (arr[] ), array’s size (n) and a number to be searched (x) as parameters and returns true if x is a majority element (present more than n/2 times).

http://www.geeksforgeeks.org/majority-element/

Question 2:Check for Majority Element in a sorted array
Write a C function to find if a given integer x appears more than n/2 times in a sorted array of n integers
http://www.geeksforgeeks.org/check-for-majority-element-in-a-sorted-array/

Question 3:Elements in array that appear more than n/k times

Given an array of size n, find all elements in array that appear more than n/k times. For example, if the input arrays is {3, 1, 2, 2, 1, 2, 3, 3} and k is 4, then the output should be [2, 3]. Note that size of array is 8 (or n = 8), so we need to find all elements that appear more than 2 (or 8/4) times. There are two elements that appear more than two times, 2 and 3.
http://www.geeksforgeeks.org/given-an-array-of-of-size-n-finds-all-the-elements-that-appear-more-than-nk-times/

1 comment: