Skip to content

Commit 90ed7e7

Browse files
committed
init
0 parents  commit 90ed7e7

20 files changed

+654
-0
lines changed

.editorconfig

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
# EditorConfig
3+
# https://EditorConfig.org
4+
#
5+
# Build with init-editorconfig
6+
# https://github.com/abranhe/init-editorconfig
7+
8+
root = true
9+
10+
[*]
11+
indent_style = tab
12+
end_of_line = lf
13+
charset = utf-8
14+
trim_trailing_whitespace = true
15+
insert_final_newline = true
16+
17+
[*.yml]
18+
indent_style = space
19+
indent_size = 2

.gitignore

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
*.egg-info/
24+
.installed.cfg
25+
*.egg
26+
MANIFEST
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*.cover
47+
.hypothesis/
48+
.pytest_cache/
49+
50+
# Translations
51+
*.mo
52+
*.pot
53+
54+
# Django stuff:
55+
*.log
56+
local_settings.py
57+
db.sqlite3
58+
59+
# Flask stuff:
60+
instance/
61+
.webassets-cache
62+
63+
# Scrapy stuff:
64+
.scrapy
65+
66+
# Sphinx documentation
67+
docs/_build/
68+
69+
# PyBuilder
70+
target/
71+
72+
# Jupyter Notebook
73+
.ipynb_checkpoints
74+
75+
# pyenv
76+
.python-version
77+
78+
# celery beat schedule file
79+
celerybeat-schedule
80+
81+
# SageMath parsed files
82+
*.sage.py
83+
84+
# Environments
85+
.env
86+
.venv
87+
env/
88+
venv/
89+
ENV/
90+
env.bak/
91+
venv.bak/
92+
93+
# Spyder project settings
94+
.spyderproject
95+
.spyproject
96+
97+
# Rope project settings
98+
.ropeproject
99+
100+
# mkdocs documentation
101+
/site
102+
103+
# mypy
104+
.mypy_cache/

.travis.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
group: travis_latest
2+
language: python
3+
cache:
4+
directories:
5+
- $HOME/.cache/pip
6+
matrix:
7+
include:
8+
- python: 3.4
9+
env: TOX_ENV=py34
10+
- python: 3.5
11+
env: TOX_ENV=py35,coverage
12+
- python: 3.6
13+
env: TOX_ENV=py36
14+
install:
15+
- pip install -r tests/test_requirements.txt
16+
before_script:
17+
# stop the build if there are Python syntax errors or undefined names
18+
- flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics
19+
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
20+
- flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
21+
script:
22+
- pip3 install -e .
23+
- tox -e $TOX_ENV
24+
# Check python uninstall package
25+
- pip3 uninstall -y algorithms
26+
notifications:
27+
email: false
28+
29+
30+
language: python
31+
32+
python:
33+
- "3.3"
34+
- "3.4"
35+
36+
install:
37+
- pip install codecov
38+
39+
script:
40+
- coverage run test.py
41+
42+
notifications:
43+
email: false

allalgorithms/.editorconfig

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# EditorConfig
2+
# https://EditorConfig.org
3+
#
4+
# Build with init-editorconfig
5+
# https://github.com/abranhe/init-editorconfig
6+
7+
root = true
8+
9+
[*]
10+
indent_style = tab
11+
end_of_line = lf
12+
charset = utf-8
13+
trim_trailing_whitespace = true
14+
insert_final_newline = true
15+
16+
[*.yml]
17+
indent_style = space
18+
indent_size = 2

allalgorithms/__init__.py

Whitespace-only changes.

allalgorithms/searches/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .binary_search import *
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: UTF-8 -*-
2+
#
3+
# Binary search works for a sorted array.
4+
# The All ▲lgorithms library for python
5+
#
6+
# Contributed by: Carlos Abraham Hernandez
7+
# Github: @abranhe
8+
#
9+
def binary_search(arr, query):
10+
lo, hi = 0, len(arr) - 1
11+
while lo <= hi:
12+
mid = (hi + lo) // 2
13+
val = arr[mid]
14+
if val == query:
15+
return mid
16+
elif val < query:
17+
lo = mid + 1
18+
else:
19+
hi = mid - 1
20+
return None

allalgorithms/sorting/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .merge_sort import *

allalgorithms/sorting/merge_sort.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: UTF-8 -*-
2+
#
3+
# Merge Sort Algorithm
4+
# The All ▲lgorithms library for python
5+
#
6+
# Contributed by: Carlos Abraham Hernandez
7+
# Github: @abranhe
8+
#
9+
def merge_sort(arr):
10+
if len(arr) == 1:
11+
return arr
12+
13+
left = merge_sort(arr[:(len(arr)//2)])
14+
right = merge_sort(arr[(len(arr)//2):])
15+
out = []
16+
17+
while bool(left) or bool(right):
18+
if bool(left) ^ bool(right):
19+
alias = left if left else right
20+
else:
21+
alias = left if left[0] < right[0] else right
22+
23+
out.append(alias[0])
24+
alias.remove(alias[0])
25+
26+
return out

changelog.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<div align="left">
2+
<img src="https://cdn.abraham.gq/projects/algorithms/algorithms.svg" alt="Algorithms"> <img src="http://konpa.github.io/devicon/devicon.git/icons/python/python-original.svg" width="50px">
3+
<div>
4+
5+
# Version `0.0.0`
6+
7+
Date: October 9, 2018
8+
9+
### Algorithms:
10+
11+
- Sorting
12+
- Bubble Sort
13+
- Searches
14+
- Merge Sort

docs/readme.md

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<div align="center">
2+
<a href="https://pypi.org/project/allalgorithms"><img src="https://cdn.abranhe.com/projects/algorithms/logo.svg" width="30%"></a>
3+
<br>
4+
<br>
5+
<br>
6+
<br>
7+
The All ▲lgorithms Python library
8+
<br>
9+
<br>
10+
</p>
11+
12+
[![All Algorithms Badge][1]][2]
13+
[![Travis][travis-img]][travis-link]
14+
[![License][license-img]][license-link]
15+
[![pypi][pypi]][pypi-link]
16+
17+
<br>
18+
<br>
19+
<br>
20+
<br>
21+
22+
[`python.allalgorithms.com`](https://python.allalgorithms.com)
23+
24+
</div>
25+
26+
# Why?
27+
28+
- Why not 😂
29+
- Clean and focused
30+
- Actively maintained
31+
- Because All Algorithms should easy to use in Python
32+
33+
## Install
34+
35+
```
36+
pip install allalgorithms
37+
```
38+
39+
## Usage Example
40+
41+
```py
42+
from allalgorithms.searches import binary_search
43+
44+
arr = [-2, 1, 2, 7, 10, 77]
45+
46+
print(binary_search(arr, 7))
47+
# -> 3
48+
49+
print(binary_search(arr, 3))
50+
# -> None
51+
```
52+
53+
# Tree
54+
55+
- Searches
56+
- [Binary Search](binary_search)
57+
- Sorting
58+
- [Merge Sort](merge_sort)
59+
60+
61+
# Related
62+
63+
- [javascript-lib](https://github.com/abranhe/javascript-lib): All ▲lgorithms Javascript library
64+
65+
# Maintainers
66+
67+
|[![Carlos Abraham Logo][3]][4]|
68+
| :--------------------------: |
69+
| [Carlos Abraham][4] |
70+
71+
72+
# License
73+
74+
[MIT][5] License © [Carlos Abraham][4]
75+
76+
<!-------------------Markdown Images Links ---------------------------------->
77+
[1]: https://cdn.abranhe.com/projects/algorithms/badge.svg
78+
[2]: https://github.com/abranhe/python-lib
79+
[3]: https://avatars3.githubusercontent.com/u/21347264?s=50
80+
[4]: https://github.com/abranhe
81+
[5]: https://github.com/abranhe/python-lib/blob/master/LICENSE
82+
[travis-link]: https://travis-ci.org/abranhe/python-lib
83+
[travis-img]: https://img.shields.io/travis/abranhe/python-lib.svg?logo=travis
84+
[license-link]: https://github.com/abranhe/python-lib/blob/master/LICENSE
85+
[license-img]: https://img.shields.io/github/license/abranhe/python-lib.svg
86+
[pypi]: https://img.shields.io/pypi/v/allalgorithms.svg
87+
[pypi-link]: https://pypi.org/project/allalgorithms
88+
<!-------------------Markdown Images Links ---------------------------------->
89+
90+
<div align="center">
91+
<a href="https://github.com/abranhe/algorithms">
92+
<img src="https://cdn.abranhe.com/projects/algorithms/logo.svg" width="50px">
93+
</a>
94+
<br>
95+
</div>

docs/searches/binary-search.md

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Binary Search
2+
3+
In computer science, binary search, also known as half-interval search, logarithmic search, or binary chop, is a search algorithm that finds the position of a target value within a sorted array
4+
5+
## Install
6+
7+
```
8+
pip install allalgorithms
9+
```
10+
11+
## Usage
12+
13+
```py
14+
from allalgorithms.searches import binary_search
15+
16+
arr = [-2, 1, 2, 7, 10, 77]
17+
18+
print(binary_search(arr, 7))
19+
# -> 3
20+
21+
print(binary_search(arr, 3))
22+
# -> None
23+
```
24+
25+
## API
26+
27+
### binary_search(array, query)
28+
29+
> Return array index if its found, otherwise returns `None`
30+
31+
##### Params:
32+
33+
- `array`: Sorted Array
34+
- `query`: Element to search for in the array

0 commit comments

Comments
 (0)