Skip to content

Commit f756855

Browse files
Wesley-Arringtonleios
authored andcommitted
Fixing 'Example Code' (#245)
* Fixing gaussian_elimnation.md * Fixing thomas.md * Removing unnecessary lines * Adding 'Example Code' label in Stable Marriage * Making 'Example Code' consistant size with rest of document * Adding Javascript title in Graham Scan * Updating all to ##
1 parent 39656d5 commit f756855

File tree

12 files changed

+20
-13
lines changed

12 files changed

+20
-13
lines changed

chapters/computational_geometry/gift_wrapping/graham_scan/graham_scan.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ In the end, the code should look something like this:
4848

4949
{% references %} {% endreferences %}
5050

51-
### Example Code
51+
## Example Code
5252

5353
{% method %}
5454
{% sample lang="jl" %}
@@ -61,6 +61,7 @@ In the end, the code should look something like this:
6161
### C
6262
[import, lang:"c_cpp"](code/c/graham.c)
6363
{% sample lang="js" %}
64+
### Javascript
6465
[import, lang:"javascript"](code/javascript/graham-scan.js)
6566
{% endmethod %}
6667

chapters/computational_geometry/gift_wrapping/jarvis_march/jarvis_march.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Since this algorithm, there have been many other algorithms that have advanced t
2020

2121
{% references %} {% endreferences %}
2222

23-
### Example Code
23+
## Example Code
2424

2525
{% method %}
2626
{% sample lang="cs" %}

chapters/data_compression/huffman/huffman.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ and `bibbity_bobbity` becomes `01000010010111011110111000100101110`.
4747
As mentioned this uses the minimum number of bits possible for encoding.
4848
The fact that this algorithm is both conceptually simple and provably useful is rather extraordinary to me and is why Huffman encoding will always hold a special place in my heart.
4949

50-
# Example Code
50+
## Example Code
5151
In code, this can be a little tricky. It requires a method to continually sort the nodes as you add more and more nodes to the system.
5252
The most straightforward way to do this in some languages is with a priority queue, but depending on the language, this might be more or less appropriate.
5353
In addition, to read the tree backwards, some sort of [Depth First Search](../../tree_traversal/tree_traversal.md) needs to be implemented.

chapters/decision_problems/stable_marriage/stable_marriage.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ To be clear, even though this algorithm seems conceptually simple, it is rather
1818
I do not at all claim that the code provided here is efficient and we will definitely be coming back to this problem in the future when we have more tools under our belt.
1919
I am incredibly interested to see what you guys do and how you implement the algorithm.
2020

21+
## Example Code
22+
2123
{% method %}
2224
{% sample lang="jl" %}
2325
### Julia

chapters/differential_equations/euler/euler.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Verlet integration has a distinct advantage over the forward Euler method in bot
9191
That said, in practice, due to the instability of the forward Euler method and the error with larger timesteps, this method is rarely used in practice.
9292
That said, variations of this method *are* certainly used (for example Crank-Nicolson and [Runge-Kutta](../runge_kutta/runge_kutta.md), so the time spent reading this chapter is not a total waste!
9393

94-
### Example Code
94+
## Example Code
9595

9696
Like in the case of [Verlet Integration](../../physics_solvers/verlet/verlet.md), the easiest way to test to see if this method works is to test it against a simple test-case.
9797
Here, the most obvious test-case would be dropping a ball from 5 meters, which is my favorite example, but proved itself to be slightly less enlightening than I would have thought.

chapters/euclidean_algorithm/euclidean.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Here, we set `b` to be the remainder of `a%b` and `a` to be whatever `b` was las
7474

7575
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.
7676

77-
# Example Code
77+
## Example Code
7878

7979
{% method %}
8080
{% sample lang="c" %}

chapters/matrix_methods/gaussian_elimination/gaussian_elimination.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,16 +282,17 @@ Even though this seems straightforward, the pseudocode might not be as simple as
282282

283283
Now, as for what's next... Well, we are in for a treat! The above algorithm clearly has 3 `for` loops, and will thus have a complexity of $$\sim O(n^3)$$, which is abysmal! If we can reduce the matrix to a specifically **tridiagonal** matrix, we can actually solve the system in $$\sim O(n)$$! How? Well, we can use an algorithm known as the _Tri-Diagonal Matrix Algorithm_ \(TDMA\) also known as the _Thomas Algorithm_.
284284

285-
### Example Code
286-
287-
The full code can be seen here:
285+
## Example Code
288286

289287
{% method %}
290288
{% sample lang="jl" %}
289+
### Julia
291290
[import, lang:"julia"](code/julia/gaussian_elimination.jl)
292291
{% sample lang="c" %}
292+
### C
293293
[import, lang:"c_cpp"](code/c/gaussian_elimination.c)
294294
{% sample lang="rs" %}
295+
### Rust
295296
[import, lang:"rust"](code/rust/gaussian_elimination.rs)
296297
{% endmethod %}
297298

chapters/matrix_methods/thomas/thomas.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,17 @@ d'_0 = \frac{d_0}{b_0}
3535
\end{align}
3636
$$
3737

38-
In code, this will look like this:
38+
## Example Code
3939

4040
{% method %}
4141
{% sample lang="jl" %}
42+
### Julia
4243
[import, lang:"julia"](code/julia/thomas.jl)
4344
{% sample lang="c" %}
45+
### C
4446
[import, lang:"c_cpp"](code/c/thomas.c)
4547
{% sample lang="py" %}
48+
### Python
4649
[import, lang:"python"](code/python/thomas.py)
4750
{% endmethod %}
4851

chapters/monte_carlo/monte_carlo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ As long as you can write some function to tell whether the provided point is ins
7878
This is obviously an incredibly powerful tool and has been used time and time again for many different areas of physics and engineering.
7979
I can guarantee that we will see similar methods crop up all over the place in the future!
8080

81-
# Example Code
81+
## Example Code
8282
Monte carlo methods are famous for their simplicity.
8383
It doesn't take too many lines to get something simple going.
8484
Here, we are just integrating a circle, like we described above; however, there is a small twist and trick.

chapters/physics_solvers/quantum/split-op/split-op.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ And finally go step-by-step through the simulation:
8181
And that's it.
8282
The Split-Operator method is one of the most commonly used quantum simulation algorithms because of how straightforward it is to code and how quickly you can start really digging into the physics of the simulation results!
8383

84-
# Example Code
84+
## Example Code
8585
{% method %}
8686
{% sample lang="jl" %}
8787
### Julia

chapters/physics_solvers/verlet/verlet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ Unfortunately, this has not yet been implemented in LabVIEW, so here's Julia cod
164164

165165
Even though this method is more used than the simple Verlet method mentioned above, it unforunately has an error term of $$\mathcal{O} \Delta t^2$$, which is two orders of magnitude worse. That said, if you want to have a simulaton with many objects that depend on one another --- like a gravity simulation --- the Velocity Verlet algorithm is a handy choice; however, you may have to play further tricks to allow everything to scale appropriately. These types of simulatons are sometimes called *n-body* simulations and one such trick is the [Barnes-Hut](barnes_hut.md) algorithm, which cuts the complexity of n-body simulations from $$\sim \mathcal{O}(n^2)$$ to $$\sim \mathcal{O}(n\log(n))$$
166166

167-
# Example Code
167+
## Example Code
168168

169169
Both of these methods work simply by iterating timestep-by-timestep and can be written straightforwardly in any language. For reference, here are snippets of code that use both the classic and velocity Verlet methods to find the time it takes for a ball to hit the ground after being dropped from a given height.
170170

chapters/tree_traversal/tree_traversal.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ This has not been implemented in your chosen language, so here is the Julia code
195195
[import:17-20, lang:"haskell"](code/haskell/TreeTraversal.hs)
196196
{% endmethod %}
197197

198-
# Example Code
198+
## Example Code
199199
{% method %}
200200
{% sample lang="jl" %}
201201
### Julia

0 commit comments

Comments
 (0)