I made a pseudo code algorithm to find repeating values of an array which includes float numbers:
mergeSort(A);
int i <- 0
for i<- A.lenght-1
if Arr[i] == A[i+1]
return A[i]
while A[i] = A[i+1]
i++
else
i++
I want to change the above algorithm to find the repeating values and the number of times they repeat. I have created the following algorithm:
mergeSort(A);
HashMap hashMap;
Int result <-0 int i <- 0
for i<- A.lenght-1
int j <- 0
if A[i] == A[i+1]
j <- j+1
result <- A[i]
while A[i] == A[i+1]
i <- i+1
j<- j+1
hashMap.insert(result , j)
else
i++
return hashMap
Is this an efficient algorithm? Is it a good way to use a hashmap?