diff --git a/src/algebra/fibonacci-numbers.md b/src/algebra/fibonacci-numbers.md index 24a9c1eb1..991679a86 100644 --- a/src/algebra/fibonacci-numbers.md +++ b/src/algebra/fibonacci-numbers.md @@ -134,7 +134,7 @@ There can only be $p$ different remainders modulo $p$, and at most $p^2$ differe We now choose two pairs of identical remainders with the smallest indices in the sequence. Let the pairs be $(F_a,\ F_{a + 1})$ and $(F_b,\ F_{b + 1})$. We will prove that $a = 1$. If this was false, there would be two previous pairs $(F_{a-1},\ F_a)$ and $(F_{b-1},\ F_b)$, which, by the property of Fibonacci numbers, would also be equal. However, this contradicts the fact that we had chosen pairs with the smallest indices, completing our proof. -##Practice Problems +## Practice Problems * [SPOJ - Euclid Algorithm Revisited](http://www.spoj.com/problems/MAIN74/) * [SPOJ - Fibonacci Sum](http://www.spoj.com/problems/FIBOSUM/) diff --git a/src/combinatorics/catalan-numbers.md b/src/combinatorics/catalan-numbers.md index 609668543..a57686c13 100644 --- a/src/combinatorics/catalan-numbers.md +++ b/src/combinatorics/catalan-numbers.md @@ -61,7 +61,7 @@ void init() { } ``` -###Analytical formula +### Analytical formula $$C_n = \frac{1}{n + 1} {\binom{2n}{n}}$$ (here $\binom{n}{k}$ denotes the usual binomial coefficient, i.e. number of ways to select $k$ objects from set of $n$ objects). diff --git a/src/geometry/point-in-convex-polygon.md b/src/geometry/point-in-convex-polygon.md index 2e13cca97..028c4344b 100644 --- a/src/geometry/point-in-convex-polygon.md +++ b/src/geometry/point-in-convex-polygon.md @@ -1,11 +1,11 @@ -#Check if point belongs to the convex polygon in $O(\log N)$ +# Check if point belongs to the convex polygon in $O(\log N)$ Consider the following problem: you are given a convex polygon with integer vertices and a lot of queries. Each query is a point, for which we should determine whether it lies inside or on the boundary of the polygon or not. Suppose the polygon is ordered counter-clockwise. We will answer each query in $O(\log n)$ online. -##Algorithm +## Algorithm Let's pick the point with the smallest x-coordinate. If there are several of them, we pick the one with the smallest y-coordinate. Let's denote it as $p_0$. Now all other points $p_1,\dots,p_n$ of the polygon are ordered by their polar angle from the chosen point (because the polygon is ordered counter-clockwise). @@ -35,7 +35,7 @@ This checks if the area of the triangle $p_0, p_i, p_{i+1}$ has to exact same si If $p$ is outside, then the sum of those three triangle will be bigger than the size of the triangle. If it is inside, then it will be equal. -##Implementation +## Implementation The function `prepair` will make sure that the lexicographical smallest point (smallest x value, and in ties smallest y value) will be $p_0$, and computes the vectors $p_i - p_0$. Afterwards the function `pointInConvexPolygon` computes the result of a query. @@ -107,5 +107,5 @@ bool pointInConvexPolygon(pt point){ } ``` -##Problems +## Problems [SGU253 Theodore Roosevelt](https://codeforces.com/problemsets/acmsguru/problem/99999/253) diff --git a/src/geometry/point-location.md b/src/geometry/point-location.md index 14ac60a10..9b20bca2a 100644 --- a/src/geometry/point-location.md +++ b/src/geometry/point-location.md @@ -286,5 +286,5 @@ vector> point_location(DCEL planar, vector queries) } ``` -##Problems +## Problems [TIMUS1848 - Fly Hunt](http://acm.timus.ru/problem.aspx?space=1&num=1848&locale=en) diff --git a/src/graph/Assignment-problem-min-flow.md b/src/graph/Assignment-problem-min-flow.md index 2d8f12974..20eee6656 100644 --- a/src/graph/Assignment-problem-min-flow.md +++ b/src/graph/Assignment-problem-min-flow.md @@ -1,6 +1,6 @@ -#Solving assignment problem using min-cost-flow +# Solving assignment problem using min-cost-flow The **assignment problem** has two equivalent statements: @@ -9,7 +9,7 @@ The **assignment problem** has two equivalent statements: Here we will consider the solution of the problem based on the algorithm for finding the [minimum cost flow (min-cost-flow)](./graph/min_cost_flow.html), solving the assignment problem in $\mathcal{O}(N^5)$. -##Description +## Description Let's build a bipartite network: there is a source $S$, a drain $T$, in the first part there are $N$ vertices (corresponding to rows of the matrix, or orders), in the second there are also $N$ vertices (corresponding to the columns of the matrix, or machines). Between each vertex $i$ of the first set and each vertex $j$ of the second set, we draw an edge with bandwidth 1 and cost $A_{ij}$. From the source $S$ we draw edges to all vertices $i$ of the first set with bandwidth 1 and cost 0. We draw an edge with bandwidth 1 and cost 0 from each vertex of the second set $j$ to the drain $T$. @@ -17,7 +17,7 @@ We find in the resulting network the maximum flow of the minimum cost. Obviously The complexity of this solution of the assignment problem depends on the algorithm by which the search for the maximum flow of the minimum cost is performed. The complexity will be $\mathcal{O}(N^5)$ using [Dijkstra](./graph/dijkstra.html) or $\mathcal{O}(N^6)$ using [Bellman-Ford](./graph/bellman_ford.html). -##Implementation +## Implementation The implementation given here is long, it can probably be significantly reduced. It uses the [D“Esopo-Pape algorithm](./graph/desopo_pape.html) for finding shortest paths. diff --git a/src/graph/strongly-connected-components.md b/src/graph/strongly-connected-components.md index 88671a7ba..9ca23c3be 100644 --- a/src/graph/strongly-connected-components.md +++ b/src/graph/strongly-connected-components.md @@ -103,11 +103,12 @@ Here, $g$ is graph, $gr$ is transposed graph. Function $dfs1$ implements depth f * Thomas Cormen, Charles Leiserson, Ronald Rivest, Clifford Stein. Introduction to Algorithms [2005]. * M. Sharir. A strong-connectivity algorithm and its applications in data-flow analysis [1979]. -##Practice Problems -- [SPOJ - Submerging Islands](http://www.spoj.com/problems/SUBMERGE/) -- [SPOJ - Good Travels](http://www.spoj.com/problems/GOODA/) -- [SPOJ - Lego](http://www.spoj.com/problems/LEGO/) -- [Codechef - Chef and Round Run](https://www.codechef.com/AUG16/problems/CHEFRRUN) +## Practice Problems + +* [SPOJ - Submerging Islands](http://www.spoj.com/problems/SUBMERGE/) +* [SPOJ - Good Travels](http://www.spoj.com/problems/GOODA/) +* [SPOJ - Lego](http://www.spoj.com/problems/LEGO/) +* [Codechef - Chef and Round Run](https://www.codechef.com/AUG16/problems/CHEFRRUN) * [Dev Skills - A Song of Fire and Ice](https://devskill.com/CodingProblems/ViewProblem/79) * [UVA - 11838 - Come and Go](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2938) * [UVA 247 - Calling Circles](https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=183) diff --git a/src/linear_algebra/rank-matrix.md b/src/linear_algebra/rank-matrix.md index 6a7050a35..3be044ce0 100644 --- a/src/linear_algebra/rank-matrix.md +++ b/src/linear_algebra/rank-matrix.md @@ -1,6 +1,6 @@ -#Finding the rank of a matrix +# Finding the rank of a matrix **The rank of a matrix** is the largest number of linearly independent rows/columns of the matrix. The rank is not only defined for square matrices. @@ -9,16 +9,16 @@ The rank of a matrix can also be defined as the largest order of any non-zero mi Let the matrix be rectangular and have size $N \times M$. Note that if the matrix is square and its determinant is non-zero, then the rank is $N$ ($=M$); otherwise it will be less. Generally, the rank of a matrix does not exceed $\min (N, M)$. -##Algorithm +## Algorithm You can search for the rank using [Gaussian elimination](./linear_algebra/linear-system-gauss.html). We will perform the same operations as when solving the system or finding its determinant. But if at any step in the $i$-th column there are no rows with an non-empty entry among those that we didn't selected already, then we skip this step and decrease the rank by one (initially the rank is set equal to $\max (N, M)$). Otherwise, if we have found a row with a non-zero element in the $i$-th column during the $i$-th step, then we mark this row as a selected one and perform the usual operations of taking this row away from the rest. -##Complexity +## Complexity This algorithm runs in $\mathcal{O}(n^3)$. -##Implementation +## Implementation ```cpp const double EPS = 1E-9; diff --git a/src/num_methods/simpson-integration.md b/src/num_methods/simpson-integration.md index f7f13815f..ec3197f8a 100644 --- a/src/num_methods/simpson-integration.md +++ b/src/num_methods/simpson-integration.md @@ -1,6 +1,6 @@ -#Integration by Simpson's formula +# Integration by Simpson's formula We are going to calculate the value of a definite integral @@ -8,7 +8,7 @@ $$\int_a ^ b f (x) dx$$ The solution described here was published in one of the dissertations of **Thomas Simpson** in 1743. -##Simpson's formula +## Simpson's formula Let $n$ be some natural number. We divide the integration segment $[a; b]$ into $2n$ equal parts: @@ -29,7 +29,7 @@ Adding these values over all segments, we obtain the final **Simpson's formula** $$\int_a ^ b f (x) dx \approx \left(f (x_0) + 4 f (x_1) + 2 f (x_2) + 4f(x_3) + 2 f(x_4) + \ldots + 4 f(x_{2N-1}) + f(x_{2N}) \right)\frac {h} {3} $$ -##Error +## Error The error in approximating an integral by Simpson's formula is $$ -\tfrac{1}{90} \left(\tfrac{b-a}{2}\right)^5 f^{(4)}(\xi)$$ @@ -38,7 +38,7 @@ where $\xi$ is some number between $a$ and $b$. The error is asymptotically proportional to $(b-a)^5$. However, the above derivations suggest an error proportional to $(b-a)^4$. Simpson's rule gains an extra order because the points at which the integrand is evaluated are distributed symmetrically in the interval $[a, b]$. -##Implementation +## Implementation Here $f(x)$ is some user function. diff --git a/src/sequences/k-th.md b/src/sequences/k-th.md index b3291f66e..b71deb2ce 100644 --- a/src/sequences/k-th.md +++ b/src/sequences/k-th.md @@ -1,12 +1,12 @@ -#K-th order statistic in O(N) +# K-th order statistic in O(N) Given an array __A__ of size __N__ and a number __K__. The challenge is to find __K__-th largest number in the array, i.e., __K__-th order statistic. The basic idea - to use the idea of quick sort algorithm. Actually, the algorithm is simple, it is more difficult to prove that it runs in an average of O(N), in contrast to the quick sort. -#Implementation (not recursive): +# Implementation (not recursive): ```cpp template @@ -63,5 +63,7 @@ T order_statistics (std::vector a, unsigned n, unsigned k) ``` To note, in the standard C ++ library, this algorithm has already been implemented - it is called nth_element. + ## Practice Problems - - [CODECHEF: Median](https://www.codechef.com/problems/CD1IT1) \ No newline at end of file + +- [CODECHEF: Median](https://www.codechef.com/problems/CD1IT1) diff --git a/src/string/suffix-array.md b/src/string/suffix-array.md index a999b4219..79ef9f4fd 100644 --- a/src/string/suffix-array.md +++ b/src/string/suffix-array.md @@ -1,5 +1,5 @@ -#Suffix Array +# Suffix Array ## Definition @@ -30,15 +30,15 @@ Therefore the suffix array for $s$ will be $(2,~ 3,~ 0,~ 4,~ 1)$. As a data structure it is widely used in areas such as data compression, bioinformatics and, in general, in any area that deals with strings and string matching problems. -##Construction +## Construction -###$O(n^2 \log n)$ approach +### $O(n^2 \log n)$ approach This is the most naive approach. Get all the suffixes and sort them using quicksort or mergesort and simultaneously retain their original indices. Sorting uses $O(n \log n)$ comparisons, and since comparing two strings will additionally take $O(n)$ time, we get the final complexity of $O(n^2 \log n)$. -###$O(n \log n)$ approach +### $O(n \log n)$ approach Strictly speaking the following algorithm will not sort the suffixes, but rather the cyclic shifts of a string. However we can very easily derive an algorithm for sorting suffixes from it: pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy