Impleminyation of MAJPRITY ALGORITHM
i want to write MAJORITY ALGORITHM in bothrecursive as well asiterative manner.
i tryed but i could not , can any one help me please.
this is the algorithm:
Algorithm MAJORITY
Input An array A[100n] of n element
Output The majorty element if it exist; otherwise none.
1. c < candidate(1)
2. count < 0
3. for j < 1 to n
4.if A[j]= c then
count= count+1
5. end for
6. if count >n/2then return c
7. else return none
Precedure candidate (m)
1. j < m; c< A[m]; count < 1
2. while j<n and count >0
3. j < j+1
4.if A[j]=c then count < count+ 1
5.else count < count-1
6.end while
7. if j=n then return c
8. else return candidate (j+1)
Best regard

