Using a for loop, traverse inputArray from index 0 to midIndex and search for first occurrence of K. Here no need to traverse whole array because if a majority element exists for inputArray then at-least it's one occurrence must be before midIndex.

Let the index of first occurrence of K be i. If K is majority element then there must be atleast N/2 continuous occurrences of K in inputArray.

If element at index (i + N/2) is equal to K then K is a majority element else not a majority element.

Time Complexity : O(n)

C program to check whether an element is majority element or not using linear search

#include &lt;stdio.h&gt;
/*
This function checks whether K is present more
than size/2 times in a sorted array or not
*/
void isMajorityElement(int *array, int size, int K) {
int i;
/* Find mid index of given array */
int midIndex = (size%2)? (size/2+1) : (size/2);
/* Search for the first occurence of K in array */
for (i = 0; i &lt;= midIndex; i++) {
/* If first occurence of K is at index i and K is
present in all indexes from i to i + size/2 then
K is a majority element */
if (array[i] == K &amp;&amp; array[i + size/2] == K){
printf(&quot;%d is a Majority Element\n&quot;, K);
return;
}
}
printf(&quot;%d is Not a Majority Element\n&quot;, K);
}
int main(){
int array[9] = {1,1,2,4,4,4,4,4,7};
/* Check if 4 is a Majority Element */
isMajorityElement(array, 9, 4);
/* Check if 1 is a Majority Element */
isMajorityElement(array, 9, 1);
return 0;
}

Output

4 is a Majority Element
1 is Not a Majority Element

Method 2 : By using modified binary search to find index of first occurrence of K
We can optimize above algorithm by using modified binary search to find the index of first occurrence of K instead of linearly searching input array.

This algorithm is similar to above mentioned algorithm except here we are using a modified binary search algorithm to find the index of first occurrence of K instead of linearly searching it.