From 29688f838b59e01dcacdb8348444e0f6c892fbe5 Mon Sep 17 00:00:00 2001 From: Nelson Brochado Date: Thu, 5 Oct 2017 04:01:56 +0200 Subject: [PATCH] A few small changes --- .gitignore | 2 + ands/algorithms/README.md | 47 ++++++++++++++++++------ ands/algorithms/dac/README.md | 25 ++++++++++++- ands/algorithms/dp/README.md | 9 +---- ands/algorithms/greedy/README.md | 14 ++----- ands/algorithms/matching/gale_shapley.py | 2 +- ands/algorithms/numerical/README.md | 14 +------ ands/algorithms/parsing/README.md | 4 +- ands/algorithms/recursion/README.md | 6 +-- ands/algorithms/sorting/README.md | 10 +---- 10 files changed, 71 insertions(+), 62 deletions(-) diff --git a/.gitignore b/.gitignore index 20ec64be..36c265c3 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,8 @@ ands/algorithms/graphs/ ands/algorithms/unclassified/ /ands/algorithms/math/combinatorics/ /ands/algorithms/math/ +ands/algorithms/numerical/neville.py +ands/algorithms/dp/previous_larger_element.py *.eggx *.py[cod] diff --git a/ands/algorithms/README.md b/ands/algorithms/README.md index f1a124d9..48b01bb3 100644 --- a/ands/algorithms/README.md +++ b/ands/algorithms/README.md @@ -1,18 +1,41 @@ # Algorithms -I would like to include algorithms regarding the following topics: - -- Linear algebra (Guassian, RREF, Jacobi, determinants, ...) -- Numerical computing (PDE, ODE, Poisson, Social Networks, Graph Partioning, Conjugate Gradient, Page Rank, Horner...) -- Linear programming -- Artificial intelligence (Swarm intelligence, A*, Genetic algorithms, ...) -- Geometrical algorithms (Convex hull, ...) -- Generation of random numbers -- Error correction codes -- CNF, DNF, 2-satisfiability -- Equations (quadratic, cubic and quartic equations formulas ...) -- Heuristics to NP-complete problems +Algorithms I am particularly interested in are: +- Neville's algorithm (for polynomial interpolation) +- Jacobi +- PageRank +- PowerMethod +- Graph partitioning algorithms +- Conjugate gradient (gradient descent and ascent) +- Cuthill–McKee algorithm +- Gauss-Newton algorithm +- Gauss–Seidel method +- Guassian elimination +- Guassian elimination with pivoting +- LU decomposition (or factorization) +- Cholesky decomposition (for symmetric positive definite matrices) +- Bisection method +- Fixed-point iteration +- Secant method +- A* +- MCTS +- Christofides algorithm +- Fisher–Yates shuffle +- Alpha-beta pruning +- Minmax +- Graham's scan +- Gift wrapping algorithm +- RSA +- AKS primality test +- Miller–Rabin primality test +- Edmonds–Karp algorithm +- Floyd–Warshall algorithm +- Mersenne twister (pseudo-random generator) +- Euclidean algorithm (to compute the greatest common divisor) +- CYK algorithm +- Levenshtein edit distance +- Kosaraju's algorithm A more exhaustive list of interesting algorithms can be found here: diff --git a/ands/algorithms/dac/README.md b/ands/algorithms/dac/README.md index 566c819a..c1516897 100644 --- a/ands/algorithms/dac/README.md +++ b/ands/algorithms/dac/README.md @@ -1,3 +1,24 @@ -# Divide and conquer algorithms +# [Divide and conquer algorithms](https://en.wikipedia.org/wiki/Divide_and_conquer_algorithm) -- [https://en.wikipedia.org/wiki/Divide\_and\_conquer\_algorithms](https://en.wikipedia.org/wiki/Divide_and_conquer_algorithms) \ No newline at end of file +A divide and conquer algorithm works by _recursively_ breaking down a problem into +two or more _sub-problems_ of the same or related type, until these become simple +enough to be solved directly. + +The solutions to the sub-problems are then combined to give a solution to the +original problem. + +The correctness of a divide and conquer algorithm is usually proved by +_mathematical induction_, and its computational cost is often determined by +solving _recurrence relations_. + +## Important concepts + +- [Recursion](https://en.wikipedia.org/wiki/Recursion_(computer_science)) +- Sub-problems +- [Mathematical induction](https://en.wikipedia.org/wiki/Mathematical_induction) +- [Recurrence relations](https://en.wikipedia.org/wiki/Recurrence_relation) +- [Master theorem](https://en.wikipedia.org/wiki/Master_theorem) + +### Resources + +- [https://brilliant.org/wiki/master-theorem/](https://brilliant.org/wiki/master-theorem/) \ No newline at end of file diff --git a/ands/algorithms/dp/README.md b/ands/algorithms/dp/README.md index b25d5898..e9a10020 100644 --- a/ands/algorithms/dp/README.md +++ b/ands/algorithms/dp/README.md @@ -1,4 +1,4 @@ -# Dynamic Programming +# [Dynamic Programming](https://en.wikipedia.org/wiki/Dynamic_programming) ## TODO @@ -9,9 +9,4 @@ - Counting boolean parenthesization - Two-CNF-SAT - Longest bi-tonic subsequence -- Min cost path - -## Resources - -- [Dynamic Programming](https://en.wikipedia.org/wiki/Dynamic_programming), Wikipedia's article -- [Introduction to Algorithms](https://mitpress.mit.edu/books/introduction-algorithms), 3rd edition, by CLRS +- Min-cost path \ No newline at end of file diff --git a/ands/algorithms/greedy/README.md b/ands/algorithms/greedy/README.md index cc888802..a723598c 100644 --- a/ands/algorithms/greedy/README.md +++ b/ands/algorithms/greedy/README.md @@ -1,19 +1,11 @@ -# Greedy Algorithms +# [Greedy Algorithms](https://en.wikipedia.org/wiki/Greedy_algorithm) -Note that algorithms that you might find under [graphs](../graphs), such as [Kruskal](../graphs/kruskal.py)'s and [Prim](../graphs/prim.py)'s or the [Reverse-delete algorithm](Reverse-delete algorithm) algorithms to find minimum-spanning are greedy algorithms. Dijkstra's shortest path algorithm is also a greedy algorithm. +## TODO -## References - -- [https://en.wikipedia.org/wiki/Greedy_algorithm](https://en.wikipedia.org/wiki/Greedy_algorithm) - -- [Introduction to Algorithms](https://mitpress.mit.edu/books/introduction-algorithms) (3rd edition) by CLRS +- [Reverse-delete algorithm](https://en.wikipedia.org/wiki/Reverse-delete_algorithm) to find a minimum spanning tree. -## TODO - Greedy graph coloring (does not produce an optimal solution!) - Change making, which does not produce always an optimal solution. I have already implemented a change making algorithm, which produces an optimal solution, using dynamic programming. - -- [Reverse-delete algorithm](https://en.wikipedia.org/wiki/Reverse-delete_algorithm) to find a minimum spanning tree. - diff --git a/ands/algorithms/matching/gale_shapley.py b/ands/algorithms/matching/gale_shapley.py index 39a71be3..9cd91585 100644 --- a/ands/algorithms/matching/gale_shapley.py +++ b/ands/algorithms/matching/gale_shapley.py @@ -230,7 +230,7 @@ def _validate_inputs(men_preferences: list, women_preferences: list, n: int): raise ValueError("Preferences must be in range [0, n - 1].") -def _build_inverses(women_preferences: list) -> tuple: +def _build_inverses(women_preferences: list) -> list: """Builds the inverse matrix of the preferences matrix for women, according to the algorithm described in the doc-strings above of this module. diff --git a/ands/algorithms/numerical/README.md b/ands/algorithms/numerical/README.md index 354cab6a..494921f1 100644 --- a/ands/algorithms/numerical/README.md +++ b/ands/algorithms/numerical/README.md @@ -1,13 +1 @@ -# Numerical Algorithms - -## TODO - -- Bisection method -- Fixed-point iteration -- Secant method -- Neville's algorithm (for polynomial interpolation) - -- Guassian Elimination -- LU Decomposition (or Factorization) -- Guassian Elimination with Pivoting -- Cholesky Decomposition (for symmetric positive definite matrices) \ No newline at end of file +# Numerical Algorithms \ No newline at end of file diff --git a/ands/algorithms/parsing/README.md b/ands/algorithms/parsing/README.md index bd1fbd86..8f6e6d53 100644 --- a/ands/algorithms/parsing/README.md +++ b/ands/algorithms/parsing/README.md @@ -1,3 +1 @@ -# Parsing - -Read the [this article](https://en.wikipedia.org/wiki/Parsing) if you want to know more about parsing. \ No newline at end of file +# [Parsing](https://en.wikipedia.org/wiki/Parsing) \ No newline at end of file diff --git a/ands/algorithms/recursion/README.md b/ands/algorithms/recursion/README.md index 39cd2674..70165e0a 100644 --- a/ands/algorithms/recursion/README.md +++ b/ands/algorithms/recursion/README.md @@ -1,4 +1,4 @@ -# Recursion +# [Recursion](https://en.wikipedia.org/wiki/Recursion_(computer_science)) Algorithms which are, in my opinion, good and simple examples to show how recursion works. @@ -6,8 +6,6 @@ Algorithms which are, in my opinion, good and simple examples to show how recurs There are other recursive algorithms in this project that would also be good examples to show how recursion works (for example [`quick_sort`](../sorting/quick_sort.py)), but I thought they would be better examples of other concepts. -## Possibly useful resources - -- [https://en.wikipedia.org/wiki/Recursion_(computer_science)](https://en.wikipedia.org/wiki/Recursion_(computer_science)) +## Resources - [https://www.khanacademy.org/computing/computer-science/algorithms/recursive-algorithms/a/recursion](https://www.khanacademy.org/computing/computer-science/algorithms/recursive-algorithms/a/recursion) \ No newline at end of file diff --git a/ands/algorithms/sorting/README.md b/ands/algorithms/sorting/README.md index adfb72cc..35be9bd5 100644 --- a/ands/algorithms/sorting/README.md +++ b/ands/algorithms/sorting/README.md @@ -1,4 +1,4 @@ -# Sorting Algorithms +# [Sorting Algorithms](https://en.wikipedia.org/wiki/Sorting_algorithm) Under this folder you can find some of the most famous sorting algorithms, such as @@ -10,12 +10,6 @@ All algorithms in this folder are in-place except from merge sort. The time complexities of the algorithms can be found in the doc-strings of the function. Unless otherwise specified, time complexities are for the worst case. -Other descriptions might be provided, but this is not sure (for now). - -In general, I try to specify the type of each argument, -but I might also have forgotten to do it in some places. - - ## TODO - Tim sort @@ -31,8 +25,6 @@ but I might also have forgotten to do it in some places. ## Resources -- [Sorting Algorithm](https://en.wikipedia.org/wiki/Sorting_algorithm) - - [Sorting and Searching](http://interactivepython.org/runestone/static/pythonds/index.html#sorting-and-searching), section by of an online book at [http://interactivepython.org](http://interactivepython.org) - Introduction to Algorithm (3rd ed.), book by CRLS. \ No newline at end of file