Skip to content

Commit 9f73c5e

Browse files
change the issue
1 parent 5c11398 commit 9f73c5e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

dsa/arrays/Boyer-Moore Majority Voting Algorithm.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
id: Boyer-Moore-Majority-voting-algorithm
2+
id: boyer-moore-majority-voting-algorithm
33
title: Boyer Moore Majority voting algorithm
44
sidebar_label: Boyer Majority voting algorithm
55
tags: [python, java, c++, algorithms, array, counting]
@@ -139,7 +139,7 @@ def majorityElement(v: List[int]) -> List[int]:
139139
Use a better data structure to reduce the number of look-up operations and hence the time complexity. Moreover, we have been calculating the count of the same element again and again – so we have to reduce that also.
140140

141141
#### Approach
142-
- Use a hashmap and store the elements as <key, value>
142+
- Use a hashmap and store the elements as `<key, value> `
143143
pairs. (Can also use frequency array based on the size of nums).
144144
- Here the key will be the element of the array and the
145145
value will be the number of times it occurs.
@@ -225,7 +225,7 @@ def majorityElement(arr):
225225

226226
## Optimal Approach (Extended Boyer Moore’s Voting Algorithm):
227227
#### Intuition
228-
If the array contains the majority of elements, their occurrence must be greater than the floor(N/3). Now, we can say that the count of minority elements and majority elements is equal up to a certain point in the array. So when we traverse through the array we try to keep track of the counts of elements and the elements themselves for which we are tracking the counts.
228+
If the array contains the majority of elements, their occurrence must be greater than the `floor(N/3)`. Now, we can say that the count of minority elements and majority elements is equal up to a certain point in the array. So when we traverse through the array we try to keep track of the counts of elements and the elements themselves for which we are tracking the counts.
229229

230230
After traversing the whole array, we will check the elements stored in the variables. Then we need to check if the stored elements are the majority elements or not by manually checking their counts.
231231

0 commit comments

Comments
 (0)