I got a list of exercise to do before my exams, they are not graded that's why I did not mark them as homework.
The algorithm take an array of numbers
Given this algorithm:
Algo-X(A)
i=1
j=1
m=0
c=0
while i ≤ |A|
if A[i] == A[j]
c=c+1
j=j+1
if j > |A|
if c > m
m=c
c=0
i=i+1
j=i
return m
Question 1: Analyze the complexity of Algo-X.
Question 2: Write an algorithm that does exactly the same thing as Algo-X but with a strictly better asymptotic time complexity.
Now, the time complexity of this is O(n^2) right?
The algorithm itself from what I understood search inside an array and return number of the maximum repeated number inside an array.
How can I reduce the complexity?
I can not assume that there is a number that is N/2 times present.
Thanks guys
c=c+1 j=j+1is correct?