Skip to content

Commit bc7d50e

Browse files
june128zsparal
authored andcommitted
Fix the size of the diagrams. Add res folders. (#170)
* Add res folder for building_blocks and move images into it. Fix the size of the diagrams. * Include images of euler in the same way as in other chapters. * Add res folder for notation and move image. Center image of Complexity Notation chapter. * Add res folder for principles_of_code and move images into it. Include images of Version Control in the same way as in other chapters. * Add something to "website.css", so that all images included via <img> are centered. * Add res folder for taylor and move images into it. Include images of Taylor Series in the same way as in other chapters. * Remove height attribute for all images, that have an width attribute as well. Therefore avoid distortion for images. * Use the width attribute instead of the height attribute in the Bitlogic chapter. * Include the LabView and Scratch image in Verlet Integration like in the same way as in other chapters. * Include the Scratch image in Tree Traversal in the same way as in other chapters. * Add css class and add all images in mds to that class.
1 parent 639bf75 commit bc7d50e

File tree

22 files changed

+81
-47
lines changed

22 files changed

+81
-47
lines changed

chapters/FFT/cooley_tukey.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ If we take a sum sinusoidal functions (like $$\sin(\omega t)$$ or $$\cos(\omega
2828
Each constituent wave can be described by only one value: $$\omega$$.
2929
So, instead of representing these curves as seen above, we could instead describe them as peaks in frequency space, as shown below.
3030

31-
<p align="center">
32-
<img src="res/FT_example.png" width="500" height="250" />
31+
<p>
32+
<img class="center" src="res/FT_example.png" width="500" />
3333
</p>
3434

3535
This is what the Fourier Transform does!
@@ -149,8 +149,8 @@ And at each step, we use the appropriate term.
149149
For example, imagine we need to perform an FFT of an array of only 2 elements.
150150
We can represent this addition with the following (radix-2) butterfly:
151151

152-
<p align="center">
153-
<img src="res/radix-2screen_positive.jpg" width="400" height="225" />
152+
<p>
153+
<img class="center" src="res/radix-2screen_positive.jpg" width="400" />
154154
</p>
155155

156156
Here, the diagram means the following:
@@ -163,8 +163,8 @@ $$
163163

164164
However, it turns out that the second half of our array of $$\omega$$ values is always the negative of the first half, so $$\omega_2^0 = -\omega_2^1$$, so we can use the following butterfly diagram:
165165

166-
<p align="center">
167-
<img src="res/radix-2screen.jpg" width="400" />
166+
<p>
167+
<img class="center" src="res/radix-2screen.jpg" width="400" />
168168
</p>
169169

170170
With the following equations:
@@ -180,17 +180,17 @@ Now imagine we need to combine more elements.
180180
In this case, we start with simple butterflies, as shown above, and then sum butterflies of butterflies.
181181
For example, if we have 8 elements, this might look like this:
182182

183-
<p align="center">
184-
<img src="res/radix-8screen.jpg" width="500" height="500" />
183+
<p>
184+
<img class="center" src="res/radix-8screen.jpg" width="500" />
185185
</p>
186186

187187
Note that we can perform a DFT directly before using any butterflies, if we so desire, but we need to be careful with how we shuffle our array if that's the case.
188188
In the code snippet provided in the previous section, the subdivision was performed in the same function as the concatenation, so the ordering was always correct; however, if we were to re-order with bit-reversal, this might not be the case.
189189

190190
For example, take a look at the ordering of FFT ([found on wikipedia](https://en.wikipedia.org/wiki/Butterfly_diagram)) that performs the DFT shortcut:
191191

192-
<p align="center">
193-
<img src="res/butterfly_diagram.png" width="600" height="500" />
192+
<p>
193+
<img class="center" src="res/butterfly_diagram.png" width="600" />
194194
</p>
195195

196196
Here, the ordering of the array was simply divided into even and odd elements once, but they did not recursively divide the arrays of even and odd elements again because they knew they would perform a DFT soon thereafter.

chapters/data_compression/huffman/huffman.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ Well, here we build it from the bottom up like so:
2828
And that's it.
2929
Here's an image of what this might look like for the phrase `bibbity_bobbity`:
3030

31-
<p align="center">
32-
<img src="res/huffman_tree.png" width="500" height="500" />
31+
<p>
32+
<img class="center" src="res/huffman_tree.png" width="500" />
3333
</p>
3434

3535
This will create a codebook that looks like this:

chapters/differential_equations/euler/euler.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ Now, solving this set of equations in this way is known as the *forward* Euler M
5151
In fact, there is another method known as the [*backward* Euler Method](backward_euler.md), which we will get to soon enough.
5252
For now, it is important to note that the error of these methods depend on the timestep chosen.
5353

54-
<div style="text-align:center"><img src ="res/error.png" /></div>
54+
<p>
55+
<img class="center" src="res/error.png" />
56+
</p>
5557

5658
For example, here we see dramatically different results for different timesteps for solving the ODE $$y' = \frac{x^3}{6}$$, whose solution is $$y = \frac{x^2}{2}$$.
5759
The blue line is the analytical solution, the green is with a timestep of 0.5 and the red is with a timestep of 1.
@@ -67,7 +69,9 @@ The solution here is $$y(t) = e^{-3t}$$ and we can find this solution somewhat e
6769
That said, by choosing a larger timestep, we see the Euler method's solution oscillate above and below 0, which should *never* happen.
6870
If we were to take the Euler method's solution as valid, we would incorrectly assume that $$e^{-3t}$$ will become negative!
6971

70-
<div style="text-align:center"><img src ="res/instability.png" /></div>
72+
<p>
73+
<img class="center" src="res/instability.png" />
74+
</p>
7175

7276
Like above, the blue line is the analytical solution, the green is with a timestep of 0.5 and the red is with a tiemstep of 1.
7377
Here, it's interesting that we see 2 different instability patterns.

chapters/euclidean_algorithm/euclidean.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ The algorithm is a simple way to find the *greatest common divisor* (GCD) of two
3131

3232
Here, we simply line the two numbers up every step and subtract the lower value from the higher one every timestep. Once the two values are equal, we call that value the greatest common divisor. A graph of `a` and `b` as they change every step would look something like this:
3333

34-
<p align="center">
35-
<img src="res/subtraction.png" width="500" height="500" />
34+
<p>
35+
<img class="center" src="res/subtraction.png" width="500" />
3636
</p>
3737

3838
Modern implementations, though, often use the modulus operator (%) like so
@@ -64,8 +64,8 @@ Modern implementations, though, often use the modulus operator (%) like so
6464

6565
Here, we set `b` to be the remainder of `a%b` and `a` to be whatever `b` was last timestep. Because of how the modulus operator works, this will provide the same information as the subtraction-based implementation, but when we show `a` and `b` as they change with time, we can see that it might take many fewer steps:
6666

67-
<p align="center">
68-
<img src="res/modulus.png" width="500" height="500" />
67+
<p>
68+
<img class="center" src="res/modulus.png" width="500" />
6969
</p>
7070

7171
The Euclidean Algorithm is truly fundamental to many other algorithms throughout the history of computer science and will definitely be used again later. At least to me, it's amazing how such an ancient algorithm can still have modern use and appeal. That said, there are still other algorithms out there that can find the greatest common divisor of two numbers that are arguably better in certain cases than the Euclidean algorithm, but the fact that we are discussing Euclid two millenia after his death shows how timeless and universal mathematics truly is. I think that's pretty cool.

chapters/monte_carlo/monte_carlo.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Since it's a square, the $$\text{length}$$ and $$\text{width}$$ are the same, so
1313
If we embed a circle into the square with a radius $$r = \text{length}$$ (shown below), then it's area is $$\text{Area}_{\text{circle}}=\pi r^2$$.
1414
For simplicity, we can also say that $$\text{Area}_{\text{square}}=4r^2$$.
1515

16-
<p align="center">
17-
<img src="res/square_circle.png" width="300"/>
16+
<p>
17+
<img class="center" src="res/square_circle.png" width="300"/>
1818
</p>
1919

2020
Now, let's say we want to find the area of the circle without an equation.
@@ -67,8 +67,8 @@ $$
6767

6868
If we use a small number of points, this will only give us a rough approximation, but as we start adding more and more points, the approximation becomes much, much better (as shown below)!
6969

70-
<p align="center">
71-
<img src="res/monte_carlo.gif" width="400"/>
70+
<p>
71+
<img class="center" src="res/monte_carlo.gif" width="400"/>
7272
</p>
7373

7474
The true power of monte carlo comes from the fact that it can be used to integrate literally any object that can be embedded into the square.

chapters/physics_solvers/verlet/verlet.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,15 +190,19 @@ Both of these methods work simply by iterating timestep-by-timestep and can be w
190190
{% sample lang="scratch" %}
191191
### Scratch
192192
Submitted by Jie
193-
![Scratch 2D implementation](code/scratch/verlet_scratch.png)
193+
<p>
194+
<img class="center" src="code/scratch/verlet_scratch.png" />
195+
</p>
194196
Link: [https://scratch.mit.edu/projects/173039394/](https://scratch.mit.edu/projects/173039394/)
195197
{% sample lang="matlab" %}
196198
### Matlab
197199
[import, lang:"matlab"](code/matlab/verlet.m)
198200
{% sample lang="LabVIEW" %}
199201
### LabVIEW
200202
Submitted by P. Mekhail
201-
![Verlet LabVIEW](code/labview/verlet_labview.png)
203+
<p>
204+
<img class="center" src="code/labview/verlet_labview.png" />
205+
</p>
202206
{% sample lang="javascript" %}
203207
### JavaScript
204208
[import, lang:"javascript"](code/javascript/verlet.js)

chapters/principles_of_code/building_blocks/bitlogic.md

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,27 +94,40 @@ There are more complicated things that can be done with the bitshift operators;
9494
In addition to the bitshift operations, there are a number of logical operations that can be performed on one or two bits together.
9595
These operations are called *gates*, and follow soemwhat straightforward logic.
9696
The *AND* gate, for example, reads in 2 bits and will only output a 1 value if both inputs are 1. This can be seen in the corresponding truth table:
97-
![AND Truth Table](and.jpg)
97+
98+
<p>
99+
<img class="center" src="res/and.jpg" width="423" />
100+
</p>
98101

99102
The *OR* gate will output 1 if either input bits are 1:
100103

101-
![OR Truth Table](or.jpg)
104+
<p>
105+
<img class="center" src="res/or.jpg" width="423" />
106+
</p>
102107

103108
The *exclusive OR* or *XOR* gate is the same as the *OR* gate, but will not output 1 if both bits are 1:
104109

105-
![XOR Truth Table](xor.jpg)
110+
<p>
111+
<img class="center" src="res/xor.jpg" width="423" />
112+
</p>
106113

107114
The *NOT* gate simply flips the input bit:
108115

109-
![NOT Truth Table](not.jpg)
116+
<p>
117+
<img class="center" src="res/not.jpg" width="423" />
118+
</p>
110119

111120
By combining the NOT and AND gates, we get the *NAND* gate:
112121

113-
![NAND Truth Table](nand.jpg)
122+
<p>
123+
<img class="center" src="res/nand.jpg" width="423" />
124+
</p>
114125

115126
And NOT and OR create *NOR*:
116127

117-
![NOR Truth Table](nor.jpg)
128+
<p>
129+
<img class="center" src="res/nor.jpg" width="423" />
130+
</p>
118131

119132
There are a few other gates, but this is enough for most things. We'll add more as the need arises!
120133

chapters/principles_of_code/notation/notation.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,9 @@ We've outlined the most common complexity cases of different algorithms here, bu
171171
Which is better: $$O(n^2)$$ or $$O(log(n))$$?
172172
Well, let's plot all the different cases out, and the answer should become obvious.
173173

174-
![Complexity plot](cplot.png)
174+
<p>
175+
<img class="center" src="res/cplot.png" />
176+
</p>
175177

176178
Here, we see each of the complexity cases as $$n$$ increases.
177179
Clearly, linear time is not bad when compared to polynomial or exponential time; however, if you can manage something in logarithmic or constant time, do it!

chapters/principles_of_code/version_control.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,18 @@ If you just want to get the feel for how git works, I suggest going to [github.c
6060
Note that you will not be able to contribute to any old directory on github, simply because if anyone could contribute any code they wanted to any repository they wanted, the world would become incredibly chaotic.
6161
Because of this, you may want to create a repository under your own github username or make your own copy of someone elses code on github by clicking the *fork* button:
6262

63-
![How to fork](fork.png)
63+
<p>
64+
<img class="center" src="res/fork.png" />
65+
</p>
6466

6567
Note that if you have a fork of a particular code repository, you can ask the owner of the original code repository to pull your changes into their version of the code with a *pull request*, but we are getting ahead of ourselves here.
6668
If you cannot think of what repository to work on and want to collaborate on this project in the future, feel free to fork the [Algorithm Archive](https://github.com/algorithm-archivists/algorithm-archive) and modify that!
6769

6870
Regardless, as long as there is a repository under your username on github, we can continue by linking that remote github location to your local git directory. First, we need to find the url of the github repository, as shown here:
6971

70-
![How to clone](clone.png)
72+
<p>
73+
<img class="center" src="res/clone.png" />
74+
</p>
7175

7276
Note that there are 2 provided urls here, one for *ssh* and another for *https*. From the user's perspective, the difference between the two is minimal: ssh requires the user to type only a password when interacting with the remote github repository, while https requires both a username and password.
7377
Now, you will probably be interacting with github a lot, so ssh will definitely save time and is preferred for many people who use git a lot; however, [there is some initial set-up](https://help.github.com/articles/connecting-to-github-with-ssh/).

chapters/taylor/taylor_series.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,12 @@ Note that here, we assume the acceleration to be constant, but it could technica
3737

3838
Truth be told, the Taylor Series Expansion can be found in the most unusual places and is used as the foundation of many different algorithms throughout this book. At first, it might not seem obvious why, but we can approximate almost any smooth function with a Taylor Series Expansion, and the more terms we include, the better our approximation becomes! For example, take Figure 1. Any function can be approximated as a sum of all the derivatives for that function. If we evaluate these derivatives at any point, we closely approximate the actual function.
3939

40-
![Function sum][function_sum]
40+
<p>
41+
<img class="center" src="res/function_sum.png" />
42+
</p>
4143

4244
This shows the true power of the Taylor Series Expansion. It allows us to more easily tackle complicated functions by approximating them as functions we can actually use and imagine!
4345

44-
[function_sum]: function_sum.png
45-
46-
4746
<script>
4847
MathJax.Hub.Queue(["Typeset",MathJax.Hub]);
4948
</script>

chapters/tree_traversal/tree_traversal.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ This has not been implemented in your chosen language, so here is the Julia code
5555

5656
At least to me, this makes a lot of sense. We fight recursion with recursion! First, we first output the node we are on and then we call `DFS_recursive(...)` on each of its children nodes. This method of tree traversal does what its name implies: it goes to the depths of the tree first before going through the rest of the branches. In this case, the ordering looks like:
5757

58-
<p align="center">
59-
<img src="res/DFS_pre.png" width="500" height="500" />
58+
<p>
59+
<img class="center" src="res/DFS_pre.png" width="500" />
6060
</p>
6161

6262
Note that the in the code above, we are missing a crucial step: *checking to see if the node we are using actually exists!* Because we are using a vector to store all the nodes, we will be careful not to run into a case where we call `DFS_recursive(...)` on a node that has yet to be initialized; however, depending on the language we are using, we might need to be careful of this to avoid recursion errors!
@@ -90,8 +90,8 @@ This has not been implemented in your chosen language, so here is the Julia code
9090
[import:8-9, lang:"haskell"](code/haskell/TreeTraversal.hs)
9191
{% endmethod %}
9292

93-
<p align="center">
94-
<img src="res/DFS_post.png" width="500" height="500" />
93+
<p>
94+
<img class="center" src="res/DFS_post.png" width="500" />
9595
</p>
9696

9797
In this case, the first node visited is at the bottom of the tree and moves up the tree branch by branch. In addition to these two types, binary trees have an *in-order* traversal scheme that looks something like this:
@@ -122,8 +122,8 @@ This has not been implemented in your chosen language, so here is the Julia code
122122
[import:11-15, lang:"haskell"](code/haskell/TreeTraversal.hs)
123123
{% endmethod %}
124124

125-
<p align="center">
126-
<img src="res/DFS_in.png" width="500" height="500" />
125+
<p>
126+
<img class="center" src="res/DFS_in.png" width="500" />
127127
</p>
128128

129129

@@ -165,8 +165,8 @@ This has not been implemented in your chosen language, so here is the Julia code
165165

166166
All this said, there are a few details about DFS that might not be idea, depending on the situation. For example, if we use DFS on an incredibly long tree, we will spend a lot of time going further and further down a single branch without searching the rest of the data structure. In addition, it is not the natural way humans would order a tree if asked to number all the nodes from top to bottom. I would argue a more natural traversal order would look something like this:
167167

168-
<p align="center">
169-
<img src="res/BFS_simple.png" width="500" height="500" />
168+
<p>
169+
<img class="center" src="res/BFS_simple.png" width="500" />
170170
</p>
171171

172172
And this is exactly what Breadth-First Search (BFS) does! On top of that, it can be implemented in the same way as the `DFS_stack(...)` function above, simply by swapping the `stack` for a `queue`, which is similar to a stack, except that it only allows you to interact with the very first element instead of the last. In code, this looks something like:
@@ -225,11 +225,13 @@ MainClass.java
225225
### JavaScript
226226
[import, lang:"javascript"](code/javascript/tree.js)
227227
{% sample lang="py" %}
228-
### Python
228+
### Python
229229
[import, lang:"python"](code/python/Tree_example.py)
230230
{% sample lang="scratch" %}
231231
### Scratch
232-
![scratch tree](code/scratch/scratch_tree.png)
232+
<p>
233+
<img class="center" src="code/scratch/scratch_tree.png" />
234+
</p>
233235
{% sample lang="rs"%}
234236
### Rust
235237
[import, lang:"rust"](code/rust/tree.rs)

styles/website.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,9 @@
99
.book .book-body .page-wrapper {
1010
margin-bottom: 12em;
1111
}
12+
13+
img.center {
14+
display: block;
15+
margin-left: auto;
16+
margin-right: auto;
17+
}

0 commit comments

Comments
 (0)