Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Count Frequency of elements in array using python

def countFreq(arr):
    visited = [False for _ in range(len(arr))]
    
    for i in range(len(arr)):
        count = 1
        if visited[i]:
            continue
        for j in range(i+1, len(arr)):
            if arr[i] == arr[j]:
                count += 1
                visited[j] = True
        visited[i] = True
        print(f'{arr[i]} : {count}')

# Time complexity: O(n * n)
# space complexity: O(n)
Source by localhost #
 
PREVIOUS NEXT
Tagged: #Count #Frequency #elements #array #python
ADD COMMENT
Topic
Name
2+4 =