Skip to content

Commit

Permalink
Intial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
bhanutejags committed Feb 19, 2022
0 parents commit ce6b76e
Show file tree
Hide file tree
Showing 63 changed files with 1,797 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
insert_final_newline = true
max_line_length = 120
tab_width = 2

[*.py]
profile = black

[*.{yaml,yml}]
indent_size = 2

[*.{md,markdown}]
indent_size = 2

[justfile]
indent_size = 2
19 changes: 19 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 2
updates:
# Maintain dependencies for GitHub Actions
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
day: "sunday"
time: "06:00"
timezone: "America/New_York"

# Maintain dependencies for Pip
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
day: "sunday"
time: "06:00"
timezone: "America/New_York"
50 changes: 50 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Build and Test
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main

jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
- uses: psf/black@stable

- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --statistics
- name: Lint with isort
run: |
isort .
- name: Spell Check with codespell
run: |
codespell --skip="./.mypy_cache,./pytest_cache,.coverage,./htmlcov,./site,./.venv"
- name: Lint with mypy
run: |
mypy
- name: Test with pytest include Doc Test
run: |
pytest --cov --doctest-modules --cov-report html
26 changes: 26 additions & 0 deletions .github/workflows/doc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build and Publish docs via GitHub Pages
on:
push:
branches:
- main

jobs:
build:
name: Deploy docs
runs-on: ubuntu-latest
steps:
- name: Checkout main
uses: actions/checkout@v2

- uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
- name: Deploy docs
run: mkdocs gh-deploy --force
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Jetbrains IDE
.idea/

# iPython Notebooks
.ipynb_checkpoints
*/.ipynb_checkpoints/*
.DS_Store

# Cache
.pytest_cache/
.mypy_cache/
__pycache__/
*.py[cod]
*$py.class
*.so
__pypackages__/
.hypothesis/

# Virtual Env
.venv

# MkDocs output
site/

# Coverage
.coverage
htmlcov/

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Initial Commit.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Data Structures and Algorithms in Python
[![Build and Test](https://github.com/bhanutejags/python-dsa/actions/workflows/ci.yml/badge.svg)](https://github.com/bhanutejags/python-dsa/actions/workflows/ci.yml)
* [GitHub Pages Site](https://bhanutejags.github.io/python-dsa/)
102 changes: 102 additions & 0 deletions docs/algorithms/analysis_of_algorithms.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
---
tags:
- algorithms
---
# Analysis of Algorithms

## Key characteristics of algorithms
* Input
* Output
* Definiteness -> Clear and Unambiguous
* Finiteness ->
* Effectiveness -> Nothing superfluous

## Important Metrics of Algorithm performance
* Time
* Space
* Network Consumption
* Power Consumption

???+ note "CPU registers"
For device drivers and other low-level algorithms, another metric of analyses could be the number of CPU registers the algorithm utilizes.

* Datatypes are decided at Program time, we don’t usually care when we write pseudocode.
* Every simple statement, we assume takes 1 unit of time,
* Of course, this is really shallow, at machine-code this can change
* How deep we would want to go in an analysis is up to us.

???+ example "Example 1: Calculating Time and Space Complexity"
```python
{
temp = a;
a = b;
b = temp;
}
```
$f(n) = 3$

## Frequency Count Method
??? example "Sum of all elements in an array."
```python
sum (A, n) {
s = 0;
for (i = 0; i < n; i++){
s = s + A[i]
}
return s;
}
```
_Analyses_:
=== "Time Complexity"
* `i` changes n+1 times, inside the loop the statements executed for n times. The first and return statement add 2 more the time complexity.
* $f(n) = 2n + 3 = O(n)$ -> Order of n.
=== "Space Complexity"
* A, n, s, I
* Just 3 variables, each is one word, and one array of size n.
* $S(n) = n + 3 = O(n)$ -> Order of n.

??? example "Sum of two matrices"
```python
add(A, B, n) {
for(i = 0; i < n; i++) { # -> n + 1
for (j = 0; j < n; j++) { # -> n x (n + 1)
C[i,j] = A[i,j] + B[i,j]; # -> n x n
}
}
}
```
_Analyses_
=== "Time Complexity"
* $f(n) = n + 1 + n^2 + n + n^2 = 2*n^2 + 2*n + 1 = O(n^2)$ -> Order of $n^2$.
=== "Space Complexity"
* $A$ -> $n^2$, $B$ -> $n^2$, $C$ -> $n^2$, $n$ -> $1$, $I$ -> $1$, $j$ -> $1$
* Total: $2*n^2 + 3 = O(n^2)$ -> Order of $n^2$.

## Time Complexity
* Ceil of non-integer count
* Conditional statements -> Worst and Best case statements

### Class of Time Functions
* $O(1)$ -> Constant
* $O(log n)$ -> Logarithmic
* $O(n)$ -> Linear
* $O(n^2)$ -> Quadratic
* $O(n^3)$ -> Cubix
* $O(2^n)$ -> Exponential

???+ note "Class of Time Functions"
$1 < log n < root(n) < n < n * (log n) < n^2 < n^3 ... < 2^n < 3^n < ... < n^n$

### Asymptotic Notation
* Comes from Mathematics
* O -> big-oh -> Upper Bound of a Function
* Ω -> big—omega -> Lower Bound of function
* θ -> theta -> Average Bound

### Best and Average


## Recurrence Relations - Recursive Algorithms
### Master Theorem
$T(n) = aT(b/n) + f(n)$
[Brilliant - Master Theorem](https://brilliant.org/wiki/master-theorem/)
6 changes: 6 additions & 0 deletions docs/algorithms/divide_and_conquer/binary_search.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Binary Search
* Requires a sorted array.
* Time Complexity: $O(log n)$

???+ note "Implementation of Binary Search in Python"
::: dsa.algorithms.divide_and_conquer.binary_search.imperative_binary_search
Loading

0 comments on commit ce6b76e

Please sign in to comment.