Skip to content

Commit 21299e7

Browse files
committed
add_script updates?
1 parent 862a10b commit 21299e7

23 files changed

+120
-42
lines changed

src/algebra/factorization.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ If $p$ is smaller than $\sqrt{n}$, the repetition will likely start in $O(\sqrt[
246246
Here is a visualization of such a sequence $\{x_i \bmod p\}$ with $n = 2206637$, $p = 317$, $x_0 = 2$ and $f(x) = x^2 + 1$.
247247
From the form of the sequence you can see very clearly why the algorithm is called Pollard's $\rho$ algorithm.
248248

249-
<center>![Pollard's rho visualization](pollard_rho.png)</center>
249+
<div style="text-align: center;">
250+
<img src="pollard_rho.png" alt="Pollard's rho visualization">
251+
</div>
250252

251253
Yet, there is still an open question.
252254
How can we exploit the properties of the sequence $\{x_i \bmod p\}$ to our advantage without even knowing the number $p$ itself?

src/algebra/sieve-of-eratosthenes.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ And we continue this procedure until we have processed all numbers in the row.
1919

2020
In the following image you can see a visualization of the algorithm for computing all prime numbers in the range $[1; 16]$. It can be seen, that quite often we mark numbers as composite multiple times.
2121

22-
<center>![Sieve of Eratosthenes](sieve_eratosthenes.png)</center>
22+
<div style="text-align: center;">
23+
<img src="sieve_eratosthenes.png" alt="Sieve of Eratosthenes">
24+
</div>
2325

2426
The idea behind is this:
2527
A number is prime, if none of the smaller prime numbers divides it.

src/data_structures/fenwick.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ where $|$ is the bitwise OR operator.
128128
The following image shows a possible interpretation of the Fenwick tree as tree.
129129
The nodes of the tree show the ranges they cover.
130130

131-
<center>![Binary Indexed Tree](binary_indexed_tree.png)</center>
131+
<div style="text-align: center;">
132+
<img src="binary_indexed_tree.png" alt="Binary Indexed Tree">
133+
</div>
132134

133135
## Implementation
134136

src/geometry/basic-geometry.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ The dot (or scalar) product $\mathbf a \cdot \mathbf b$ for vectors $\mathbf a$
112112
Geometrically it is product of the length of the first vector by the length of the projection of the second vector onto the first one.
113113
As you may see from the image below this projection is nothing but $|\mathbf a| \cos \theta$ where $\theta$ is the angle between $\mathbf a$ and $\mathbf b$. Thus $\mathbf a\cdot \mathbf b = |\mathbf a| \cos \theta \cdot |\mathbf b|$.
114114

115-
<center>![](https://upload.wikimedia.org/wikipedia/commons/thumb/3/3e/Dot_Product.svg/300px-Dot_Product.svg.png)</center>
115+
<div style="text-align: center;">
116+
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/3e/Dot_Product.svg/300px-Dot_Product.svg.png" alt="">
117+
</div>
116118

117119
The dot product holds some notable properties:
118120

@@ -181,7 +183,9 @@ To see the next important property we should take a look at the set of points $\
181183
You can see that this set of points is exactly the set of points for which the projection onto $\mathbf a$ is the point $C \cdot \dfrac{\mathbf a}{|\mathbf a|}$ and they form a hyperplane orthogonal to $\mathbf a$.
182184
You can see the vector $\mathbf a$ alongside with several such vectors having same dot product with it in 2D on the picture below:
183185

184-
<center>![Vectors having same dot product with a](https://i.imgur.com/eyO7St4.png)</center>
186+
<div style="text-align: center;">
187+
<img src="https://i.imgur.com/eyO7St4.png" alt="Vectors having same dot product with a">
188+
</div>
185189

186190
In 2D these vectors will form a line, in 3D they will form a plane.
187191
Note that this result allows us to define a line in 2D as $\mathbf r\cdot \mathbf n=C$ or $(\mathbf r - \mathbf r_0)\cdot \mathbf n=0$ where $\mathbf n$ is vector orthogonal to the line and $\mathbf r_0$ is any vector already present on the line and $C = \mathbf r_0\cdot \mathbf n$.
@@ -192,14 +196,18 @@ In the same manner a plane can be defined in 3D.
192196
### Definition
193197

194198
Assume you have three vectors $\mathbf a$, $\mathbf b$ and $\mathbf c$ in 3D space joined in a parallelepiped as in the picture below:
195-
<center>![Three vectors](https://upload.wikimedia.org/wikipedia/commons/thumb/3/3e/Parallelepiped_volume.svg/240px-Parallelepiped_volume.svg.png)</center>
199+
<div style="text-align: center;">
200+
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/3/3e/Parallelepiped_volume.svg/240px-Parallelepiped_volume.svg.png" alt="Three vectors">
201+
</div>
196202

197203
How would you calculate its volume?
198204
From school we know that we should multiply the area of the base with the height, which is projection of $\mathbf a$ onto direction orthogonal to base.
199205
That means that if we define $\mathbf b \times \mathbf c$ as the vector which is orthogonal to both $\mathbf b$ and $\mathbf c$ and which length is equal to the area of the parallelogram formed by $\mathbf b$ and $\mathbf c$ then $|\mathbf a\cdot (\mathbf b\times\mathbf c)|$ will be equal to the volume of the parallelepiped.
200206
For integrity we will say that $\mathbf b\times \mathbf c$ will be always directed in such way that the rotation from the vector $\mathbf b$ to the vector $\mathbf c$ from the point of $\mathbf b\times \mathbf c$ is always counter-clockwise (see the picture below).
201207

202-
<center>![cross product](https://upload.wikimedia.org/wikipedia/commons/thumb/b/b0/Cross_product_vector.svg/250px-Cross_product_vector.svg.png)</center>
208+
<div style="text-align: center;">
209+
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/b/b0/Cross_product_vector.svg/250px-Cross_product_vector.svg.png" alt="cross product">
210+
</div>
203211

204212
This defines the cross (or vector) product $\mathbf b\times \mathbf c$ of the vectors $\mathbf b$ and $\mathbf c$ and the triple product $\mathbf a\cdot(\mathbf b\times \mathbf c)$ of the vectors $\mathbf a$, $\mathbf b$ and $\mathbf c$.
205213

src/geometry/convex_hull_trick.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ The idea of this approach is to maintain a lower convex hull of linear functions
1717
Actually it would be a bit more convenient to consider them not as linear functions, but as points $(k;b)$ on the plane such that we will have to find the point which has the least dot product with a given point $(x;1)$, that is, for this point $kx+b$ is minimized which is the same as initial problem.
1818
Such minimum will necessarily be on lower convex envelope of these points as can be seen below:
1919

20-
<center> ![lower convex hull](convex_hull_trick.png) </center>
20+
<div style="text-align: center;">
21+
<img src="convex_hull_trick.png" alt="lower convex hull">
22+
</div>
2123

2224
One has to keep points on the convex hull and normal vectors of the hull's edges.
2325
When you have a $(x;1)$ query you'll have to find the normal vector closest to it in terms of angles between them, then the optimum linear function will correspond to one of its endpoints.
@@ -90,7 +92,9 @@ Assume we're in some vertex corresponding to half-segment $[l,r)$ and the functi
9092
9193
Here is the illustration of what is going on in the vertex when we add new function:
9294
93-
<center>![Li Chao Tree vertex](li_chao_vertex.png)</center>
95+
<div style="text-align: center;">
96+
<img src="li_chao_vertex.png" alt="Li Chao Tree vertex">
97+
</div>
9498
9599
Let's go to implementation now. Once again we will use complex numbers to keep linear functions.
96100

src/geometry/delaunay.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ Because of the duality, we only need a fast algorithm to compute only one of $V$
3030
## Quad-edge data structure
3131

3232
During the algorithm $D$ will be stored inside the quad-edge data structure. This structure is described in the picture:
33-
<center>![Quad-Edge](quad-edge.png)</center>
33+
<div style="text-align: center;">
34+
<img src="quad-edge.png" alt="Quad-Edge">
35+
</div>
3436

3537
In the algorithm we will use the following functions on edges:
3638

src/geometry/intersecting_segments.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,24 @@ The naive solution algorithm is to iterate over all pairs of segments in $O(n^2)
1616
Let's draw a vertical line $x = -\infty$ mentally and start moving this line to the right.
1717
In the course of its movement, this line will meet with segments, and at each time a segment intersect with our line it intersects in exactly one point (we will assume that there are no vertical segments).
1818

19-
<center>![sweep line and line segment intersection](sweep_line_1.png)</center>
19+
<div style="text-align: center;">
20+
<img src="sweep_line_1.png" alt="sweep line and line segment intersection">
21+
</div>
2022

2123
Thus, for each segment, at some point in time, its point will appear on the sweep line, then with the movement of the line, this point will move, and finally, at some point, the segment will disappear from the line.
2224

2325
We are interested in the **relative order of the segments** along the vertical.
2426
Namely, we will store a list of segments crossing the sweep line at a given time, where the segments will be sorted by their $y$-coordinate on the sweep line.
2527

26-
<center>![relative order of the segments across sweep line](sweep_line_2.png)</center>
28+
<div style="text-align: center;">
29+
<img src="sweep_line_2.png" alt="relative order of the segments across sweep line">
30+
</div>
2731

2832
This order is interesting because intersecting segments will have the same $y$-coordinate at least at one time:
2933

30-
<center>![intersection point having same y-coordinate](sweep_line_3.png)</center>
34+
<div style="text-align: center;">
35+
<img src="sweep_line_3.png" alt="intersection point having same y-coordinate">
36+
</div>
3137

3238
We formulate key statements:
3339

src/geometry/lattice-points.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ We have two cases:
3838
This amount is the same as the number of points such that $0 < y \leq (k - \lfloor k \rfloor) \cdot x + (b - \lfloor b \rfloor)$.
3939
So we reduced our problem to $k'= k - \lfloor k \rfloor$, $b' = b - \lfloor b \rfloor$ and both $k'$ and $b'$ less than $1$ now.
4040
Here is a picture, we just summed up blue points and subtracted the blue linear function from the black one to reduce problem to smaller values for $k$ and $b$:
41-
<center>![Subtracting floored linear function](lattice.png)</center>
41+
<div style="text-align: center;">
42+
<img src="lattice.png" alt="Subtracting floored linear function">
43+
</div>
4244

4345
- $k < 1$ and $b < 1$.
4446

@@ -51,7 +53,9 @@ We have two cases:
5153

5254
which returns us back to the case $k>1$.
5355
You can see new reference point $O'$ and axes $X'$ and $Y'$ in the picture below:
54-
<center>![New reference and axes](mirror.png)</center>
56+
<div style="text-align: center;">
57+
<img src="mirror.png" alt="New reference and axes">
58+
</div>
5559
As you see, in new reference system linear function will have coefficient $\tfrac 1 k$ and its zero will be in the point $\lfloor k\cdot n + b \rfloor-(k\cdot n+b)$ which makes formula above correct.
5660

5761
## Complexity analysis

src/geometry/manhattan-distance.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ $$d(p,q) = |x_p - x_q| + |y_p - y_q|$$
1212

1313
Defined this way, the distance corresponds to the so-called [Manhattan (taxicab) geometry](https://en.wikipedia.org/wiki/Taxicab_geometry), in which the points are considered intersections in a well designed city, like Manhattan, where you can only move on the streets horizontally or vertically, as shown in the image below:
1414

15-
<center>![Manhattan Distance](https://upload.wikimedia.org/wikipedia/commons/thumb/0/08/Manhattan_distance.svg/220px-Manhattan_distance.svg.png)</center>
15+
<div style="text-align: center;">
16+
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/0/08/Manhattan_distance.svg/220px-Manhattan_distance.svg.png" alt="Manhattan Distance">
17+
</div>
1618

1719
This images show some of the smallest paths from one black point to the other, all of them with length $12$.
1820

@@ -77,7 +79,9 @@ Also, we may realize that $\alpha$ is a [spiral similarity](https://en.wikipedia
7779

7880
Here's an image to help visualizing the transformation:
7981

80-
<center>![Chebyshev transformation](chebyshev-transformation.png)</center>
82+
<div style="text-align: center;">
83+
<img src="chebyshev-transformation.png" alt="Chebyshev transformation">
84+
</div>
8185

8286
## Manhattan Minimum Spanning Tree
8387

src/geometry/minkowski.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ We repeat the following steps while $i < |P|$ or $j < |Q|$.
4141

4242
Here is a nice visualization, which may help you understand what is going on.
4343

44-
<center>![Visual](minkowski.gif)</center>
44+
<div style="text-align: center;">
45+
<img src="minkowski.gif" alt="Visual">
46+
</div>
4547

4648
## Distance between two polygons
4749
One of the most common applications of Minkowski sum is computing the distance between two convex polygons (or simply checking whether they intersect).

src/geometry/planar.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ It's quite clear that the complexity of the algorithm is $O(m \log m)$ because o
5353

5454
At the first glance it may seem that finding faces of a disconnected graph is not much harder because we can run the same algorithm for each connected component. However, the components may be drawn in a nested way, forming **holes** (see the image below). In this case the inner face of some component becomes the outer face of some other components and has a complex disconnected border. Dealing with such cases is quite hard, one possible approach is to identify nested components with [point location](point-location.md) algorithms.
5555

56-
<center>![Planar graph with holes](planar_hole.png)</center>
56+
<div style="text-align: center;">
57+
<img src="planar_hole.png" alt="Planar graph with holes">
58+
</div>
5759

5860
## Implementation
5961
The following implementation returns a vector of vertices for each face, outer face goes first.
@@ -147,7 +149,9 @@ std::vector<std::vector<size_t>> find_faces(std::vector<Point> vertices, std::ve
147149
148150
Sometimes you are not given a graph explicitly, but rather as a set of line segments on a plane, and the actual graph is formed by intersecting those segments, as shown in the picture below. In this case you have to build the graph manually. The easiest way to do so is as follows. Fix a segment and intersect it with all other segments. Then sort all intersection points together with the two endpoints of the segment lexicographically and add them to the graph as vertices. Also link each two adjacent vertices in lexicographical order by an edge. After doing this procedure for all edges we will obtain the graph. Of course, we should ensure that two equal intersection points will always correspond to the same vertex. The easiest way to do this is to store the points in a map by their coordinates, regarding points whose coordinates differ by a small number (say, less than $10^{-9}$) as equal. This algorithm works in $O(n^2 \log n)$.
149151
150-
<center>![Implicitly defined graph](planar_implicit.png)</center>
152+
<div style="text-align: center;">
153+
<img src="planar_implicit.png" alt="Implicitly defined graph">
154+
</div>
151155
152156
## Implementation
153157
```{.cpp file=planar_implicit}

src/geometry/point-location.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ This problem may arise when you need to locate some points in a Voronoi diagram
1515
Firstly, for each query point $p\ (x_0, y_0)$ we want to find such an edge that if the point belongs to any edge, the point lies on the edge we found, otherwise this edge must intersect the line $x = x_0$ at some unique point $(x_0, y)$ where $y < y_0$ and this $y$ is maximum among all such edges.
1616
The following image shows both cases.
1717

18-
<center>![Image of Goal](point_location_goal.png)</center>
18+
<div style="text-align: center;">
19+
<img src="point_location_goal.png" alt="Image of Goal">
20+
</div>
1921

2022
We will solve this problem offline using the sweep line algorithm. Let's iterate over x-coordinates of query points and edges' endpoints in increasing order and keep a set of edges $s$. For each x-coordinate we will add some events beforehand.
2123

@@ -27,7 +29,9 @@ Finally, for each query point we will add one _get_ event for its x-coordinate.
2729
For each x-coordinate we will sort the events by their types in order (_vertical_, _get_, _remove_, _add_).
2830
The following image shows all events in sorted order for each x-coordinate.
2931

30-
<center>![Image of Events](point_location_events.png)</center>
32+
<div style="text-align: center;">
33+
<img src="point_location_events.png" alt="Image of Events">
34+
</div>
3135

3236
We will keep two sets during the sweep-line process.
3337
A set $t$ for all non-vertical edges, and one set $vert$ especially for the vertical ones.

src/geometry/tangents-to-two-circles.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ The described algorithm will also work in the case when one (or both) circles de
1414
## The number of common tangents
1515
The number of common tangents to two circles can be **0,1,2,3,4** and **infinite**.
1616
Look at the images for different cases.
17-
<center>!["Different cases of tangents common to two circles"](tangents-to-two-circles.png)</center>
17+
<div style="text-align: center;">
18+
<img src="tangents-to-two-circles.png" alt=""Different cases of tangents common to two circles"">
19+
</div>
1820

1921
Here, we won't be considering **degenerate** cases, i.e *when the circles coincide (in this case they have infinitely many common tangents), or one circle lies inside the other (in this case they have no common tangents, or if the circles are tangent, there is one common tangent).*
2022

src/geometry/vertical_decomposition.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ For simplicity we will show how to do this for an upper segment, the algorithm f
3939

4040
Here is a graphic representation of the three cases.
4141

42-
<center>![Visual](triangle_union.png)</center>
42+
<div style="text-align: center;">
43+
<img src="triangle_union.png" alt="Visual">
44+
</div>
4345

4446
Finally we should remark on processing all the additions of $1$ or $-1$ on all stripes in $[x_1, x_2]$. For each addition of $w$ on $[x_1, x_2]$ we can create events $(x_1, w),\ (x_2, -w)$
4547
and process all these events with a sweep line.

src/graph/2SAT.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ b \Rightarrow a & \lnot b \Rightarrow \lnot a & b \Rightarrow \lnot a & c \Right
3939

4040
You can see the implication graph in the following image:
4141

42-
<center>!["Implication Graph of 2-SAT example"](2SAT.png)</center>
42+
<div style="text-align: center;">
43+
<img src="2SAT.png" alt=""Implication Graph of 2-SAT example"">
44+
</div>
4345

4446
It is worth paying attention to the property of the implication graph:
4547
if there is an edge $a \Rightarrow b$, then there also is an edge $\lnot b \Rightarrow \lnot a$.
@@ -59,7 +61,9 @@ The following image shows all strongly connected components for the example.
5961
As we can check easily, neither of the four components contain a vertex $x$ and its negation $\lnot x$, therefore the example has a solution.
6062
We will learn in the next paragraphs how to compute a valid assignment, but just for demonstration purposes the solution $a = \text{false}$, $b = \text{false}$, $c = \text{false}$ is given.
6163

62-
<center>!["Strongly Connected Components of the 2-SAT example"](2SAT_SCC.png)</center>
64+
<div style="text-align: center;">
65+
<img src="2SAT_SCC.png" alt=""Strongly Connected Components of the 2-SAT example"">
66+
</div>
6367

6468
Now we construct the algorithm for finding the solution of the 2-SAT problem on the assumption that the solution exists.
6569

0 commit comments

Comments
 (0)