You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Arrays/top_k_frequent_elements.py
+5-7Lines changed: 5 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -11,11 +11,11 @@
11
11
Output: [1]
12
12
13
13
=========================================
14
-
Using Min Priority Queue, in each step add an element with its frequency and remove the element with the smallest frequency
15
-
if there are more than K elements inside the Priority Queue. This solution isn't much faster than sorting the frequencies.
14
+
Using Min Priority Queue, in each step add an element with its frequency and remove the element with the smallest frequency
15
+
if there are more than K elements inside the Priority Queue. This solution isn't much faster than sorting the frequencies.
16
16
Time Complexity: O(U LogK) , U in this case is the number of unique elements (but all elements from the array could be unique, so because of that U can be equal to N)
17
17
Space Complexity: O(N)
18
-
Using pivoting, this solution is based on the quick sort algorithm (divide and conquer).
18
+
Using pivoting, this solution is based on the quick sort algorithm (divide and conquer).
19
19
Same pivoting solution as the nth_smallest.py.
20
20
Time Complexity: O(U)
21
21
Space Complexity: O(N)
@@ -30,7 +30,7 @@
30
30
31
31
# priority queue comparator class
32
32
# acctualy in this case you don't need a comparator class, because the elements are tuples
33
-
# and comparison operator can work with tuples
33
+
# and comparison operator can work with tuples
34
34
# (The comparison starts with a first element of each tuple. If they do not compare to =,< or > then it proceed to the second element and so on.)
0 commit comments