Skip to content

Fixup headings #329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/algebra/fibonacci-numbers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down
2 changes: 1 addition & 1 deletion src/combinatorics/catalan-numbers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
8 changes: 4 additions & 4 deletions src/geometry/point-in-convex-polygon.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<!--?title Check if point belongs to the convex polygon in O(log N) -->
#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).

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -107,5 +107,5 @@ bool pointInConvexPolygon(pt point){
}
```

##Problems
## Problems
[SGU253 Theodore Roosevelt](https://codeforces.com/problemsets/acmsguru/problem/99999/253)
2 changes: 1 addition & 1 deletion src/geometry/point-location.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,5 +286,5 @@ vector<pair<int, int>> point_location(DCEL planar, vector<pt> queries)
}
```

##Problems
## Problems
[TIMUS1848 - Fly Hunt](http://acm.timus.ru/problem.aspx?space=1&num=1848&locale=en)
6 changes: 3 additions & 3 deletions src/graph/Assignment-problem-min-flow.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

<!--?title Assignment problem solution using min-cost-flo< -->
#Solving assignment problem using min-cost-flow
# Solving assignment problem using min-cost-flow

The **assignment problem** has two equivalent statements:

Expand All @@ -9,15 +9,15 @@ 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$.

We find in the resulting network the maximum flow of the minimum cost. Obviously, the value of the flow will be $N$. Further, for each vertex $i$ of the first segment there is exactly one vertex $j$ of the second segment, such that the flow $F_{ij}$ = 1. Finally, this is a one-to-one correspondence between the vertices of the first segment and the vertices of the second part, which is the solution to the problem (since the found flow has a minimal cost, then the sum of the costs of the selected edges will be the lowest possible, which is the optimality criterion).

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.
Expand Down
11 changes: 6 additions & 5 deletions src/graph/strongly-connected-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/linear_algebra/rank-matrix.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--?title Rank of a matrix-->

#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.

Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/num_methods/simpson-integration.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<!--?title Simpson integration -->

#Integration by Simpson's formula
# Integration by Simpson's formula

We are going to calculate the value of a definite integral

$$\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:

Expand All @@ -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)$$
Expand All @@ -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.

Expand Down
8 changes: 5 additions & 3 deletions src/sequences/k-th.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<!--?title K-th order statistic in O(N)-->

#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 <class T>
Expand Down Expand Up @@ -63,5 +63,7 @@ T order_statistics (std::vector<T> 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)

- [CODECHEF: Median](https://www.codechef.com/problems/CD1IT1)
8 changes: 4 additions & 4 deletions src/string/suffix-array.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--?title Suffix Array-->
#Suffix Array
# Suffix Array

## Definition

Expand Down Expand Up @@ -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:
Expand Down
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