Skip to content

Commit 3472517

Browse files
committed
Algorithms added
1 parent 4b03f61 commit 3472517

File tree

17 files changed

+492
-11
lines changed

17 files changed

+492
-11
lines changed

README.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Follow the link [https://interview-docs.readthedocs.io](https://interview-docs.r
2727
### Gitter Community
2828
All the discussions related to the **Interview** and **Data Structures and Algorithms** are discussed on the Gitter Community Channel.
2929

30-
Follow the link [https://gitter.im/data-structure-and-algorithms/community](https://gitter.im/data-structure-and-algorithms/community) or click the Gitter Logo below to join the community
30+
Follow the link [https://gitter.im/data-structure-and-algorithms/community](https://gitter.im/data-structure-and-algorithms/community) or click the Gitter Logo on the left to join the community
3131

3232
<br>
3333
<hr>
@@ -116,9 +116,11 @@ Follow the link [https://gitter.im/data-structure-and-algorithms/community](http
116116

117117
## Issues
118118
[![GitHub issues](https://img.shields.io/github/issues/ramanaditya/data-structure-and-algorithms?logo=github)](https://github.com/ramanaditya/data-structure-and-algorithms/issues)
119-
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat&logo=git&logoColor=white)](https://github.com/ramanaditya/data-structure-and-algorithms/pulls)
120119
[![GitHub last commit](https://img.shields.io/github/last-commit/ramanaditya/data-structure-and-algorithms?logo=github)](https://github.com/ramanaditya/data-structure-and-algorithms/)
121120

121+
[![GitHub pull requests](https://img.shields.io/github/issues-pr-raw/ramanaditya/data-structure-and-algorithms?logo=git&logoColor=white)](https://github.com/ramanaditya/data-structure-and-algorithms/compare)
122+
[![GitHub pull requests](https://img.shields.io/github/issues-pr-closed-raw/ramanaditya/data-structure-and-algorithms?logo=git&logoColor=white)](https://github.com/ramanaditya/data-structure-and-algorithms/pulls?q=is%3Apr+is%3Aclosed)
123+
122124
> 1. Graph Algorithm
123125
> 2. Solutions of CLRS
124126
> 3. String Algorithms
@@ -130,10 +132,7 @@ Follow the link [https://gitter.im/data-structure-and-algorithms/community](http
130132
[![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/ramanaditya/data-structure-and-algorithms?logo=github)](https://github.com/ramanaditya/data-structure-and-algorithms/)
131133
[![GitHub commit activity](https://img.shields.io/github/commit-activity/m/ramanaditya/data-structure-and-algorithms?color=blue&logo=github)](https://github.com/ramanaditya/data-structure-and-algorithms/commits/)
132134
[![GitHub repo size](https://img.shields.io/github/repo-size/ramanaditya/data-structure-and-algorithms?logo=github)](https://github.com/ramanaditya/data-structure-and-algorithms/)
133-
134-
[![GitHub pull requests](https://img.shields.io/github/issues-pr-raw/ramanaditya/data-structure-and-algorithms?logo=git&logoColor=white)](https://github.com/ramanaditya/data-structure-and-algorithms/compare)
135-
[![GitHub pull requests](https://img.shields.io/github/issues-pr-closed-raw/ramanaditya/data-structure-and-algorithms?logo=git&logoColor=white)](https://github.com/ramanaditya/data-structure-and-algorithms/pulls?q=is%3Apr+is%3Aclosed)
136-
[![GitHub contributors](https://img.shields.io/github/contributors/ramanaditya/data-structure-and-algorithms?logo=github)](https://github.com/ramanaditya/data-structure-and-algorithms/graphs/contributors)
135+
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat&logo=git&logoColor=white)](https://github.com/ramanaditya/data-structure-and-algorithms/pulls)
137136

138137
- Write clear meaningful git commit messages (Do read [this](http://chris.beams.io/posts/git-commit/)).
139138

@@ -152,6 +151,8 @@ Follow the link [https://gitter.im/data-structure-and-algorithms/community](http
152151
- Refer [this](https://github.com/ramanaditya/data-structure-and-algorithms/blob/master/CONTRIBUTING.md) for more.
153152

154153
## Contributor
154+
[![GitHub contributors](https://img.shields.io/github/contributors/ramanaditya/data-structure-and-algorithms?logo=github)](https://github.com/ramanaditya/data-structure-and-algorithms/graphs/contributors)
155+
155156
[![](https://sourcerer.io/fame/ramanaditya/ramanaditya/data-structure-and-algorithms/images/0)](https://sourcerer.io/fame/ramanaditya/ramanaditya/data-structure-and-algorithms/links/0)
156157
[![](https://sourcerer.io/fame/ramanaditya/ramanaditya/data-structure-and-algorithms/images/1)](https://sourcerer.io/fame/ramanaditya/ramanaditya/data-structure-and-algorithms/links/1)
157158
[![](https://sourcerer.io/fame/ramanaditya/ramanaditya/data-structure-and-algorithms/images/2)](https://sourcerer.io/fame/ramanaditya/ramanaditya/data-structure-and-algorithms/links/2)
8.63 KB
Binary file not shown.
2.71 KB
Binary file not shown.

docs/build/doctrees/index.doctree

211 Bytes
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
Array
2+
======
3+
4+
Boyer–Moore majority vote algorithm
5+
------------------------------------
6+
7+
Reference : `wiki <https://en.wikipedia.org/wiki/Boyer%E2%80%93Moore_majority_vote_algorithm>`__
8+
9+
Description
10+
````````````
11+
12+
To find the majority element from the sequence, majority means the element should be present more than n/2
13+
times the total length, n, of the sequence.
14+
15+
If the no such element occurs, then algorithm can return any arbitrary element, that is not guaranteed that this element
16+
will be the mode or occurred maximum number of times.
17+
18+
.. code-block:: text
19+
20+
Linear TIme
21+
Constant Space
22+
23+
Python
24+
````````
25+
.. code-block:: python
26+
27+
def boyer_moore_voting_algorithm(arr: list) -> int:
28+
"""
29+
:param arr: list
30+
:return: int
31+
"""
32+
res = arr[0] # Initialization
33+
counter = 0 # Counter
34+
35+
for i in range(len(arr)):
36+
if counter == 0:
37+
res = arr[i]
38+
counter = 1
39+
elif res == arr[i]:
40+
counter += 1
41+
else:
42+
counter -= 1
43+
44+
return res
45+
46+
Implementation
47+
````````````````
48+
.. role:: green
49+
.. role:: orange
50+
.. role:: red
51+
52+
53+
.. list-table:: LeetCode
54+
:header-rows: 1
55+
:widths: 5, 5, 15, 15, 10
56+
57+
* - Sl No
58+
- Level
59+
- Questions
60+
- Solutions
61+
- Tags
62+
63+
* - 169
64+
- :green:`Easy`
65+
- `Majority Element <https://leetcode.com/problems/majority-element/>`__
66+
- `Python <https://github.com/ramanaditya/data-structure-and-algorithms/blob/master/leetcode/array/majority-element.py>`__
67+
-

docs/build/html/_sources/index.rst.txt

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ Welcome to Interview Documentation!
1313
data-structures/list
1414
data-structures/linked-list
1515

16+
.. toctree::
17+
:maxdepth: 2
18+
:caption: Algorithms
19+
20+
algorithms/array
21+
1622
.. toctree::
1723
:maxdepth: 2
1824
:caption: Resources

0 commit comments

Comments
 (0)