Skip to content

Implement flat hierarchy. Fix some broken links. #242

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 4 commits into from
Jul 12, 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Unfortunately, this means that we will probably never cover every algorithm ever
That said, we'll still cover a few algorithms for fun that have very little, if any practical purpose.

If you would like to contribute, feel free to go to any chapter with code associated with it and implement that algorithm in your favorite language,
and then submit the code via pull request, following the submission guidelines found in `chapters/how_to_contribute.md` (or [here](chapters/how_to_contribute.md) if you are reading this on gitbook).
and then submit the code via pull request, following the submission guidelines found in `chapters/how_to_contribute.md` (or [here](chapters/introduction/how_to_contribute.md) if you are reading this on gitbook).

Hopefully, this project will grow and allow individuals to learn about and try their hand at implementing different algorithms for fun and (potentially) useful projects.
If nothing else, it will be an enjoyable adventure for our community.
Expand Down
69 changes: 34 additions & 35 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

* [Algorithm Archive](README.md)
* [TODO](TODO.md)
* [Introduction](chapters/introduction.md)
* [A Personal Note](chapters/getting_started.md)
* [How To Contribute](chapters/how_to_contribute.md)
* [Introduction](chapters/introduction/introduction.md)
* [A Personal Note](chapters/introduction/my_introduction_to_hobby_programming.md)
* [How To Contribute](chapters/introduction/how_to_contribute.md)
* [Principles of Code](chapters/principles_of_code/principles_of_code.md)
* [Choosing A Language](chapters/principles_of_code/choosing_a_language/choosing_a_language.md)
* [Compiled Languages](chapters/principles_of_code/choosing_a_language/compiled/compiled.md)
Expand All @@ -20,35 +20,34 @@
* [Bit Logic](chapters/principles_of_code/building_blocks/bitlogic.md)
* [Version Control](chapters/principles_of_code/version_control.md)
* [Complexity Notation](chapters/principles_of_code/notation/notation.md)
* [Convolutions](chapters/convolutions/convolutions.md)
* [Taylor Series](chapters/taylor/taylor_series.md)
* [Sorting and Searching](chapters/sorting_searching/sorting_searching.md)
* [Bubble Sort](chapters/sorting_searching/bubble/bubble_sort.md)
* [Bogo Sort](chapters/sorting_searching/bogo/bogo_sort.md)
* [Tree Traversal](chapters/tree_traversal/tree_traversal.md)
* [Euclidean Algorithm](chapters/euclidean_algorithm/euclidean.md)
* [Multiplication](chapters/multiplication/multiplication.md)
* [Monte Carlo](chapters/monte_carlo/monte_carlo.md)
* [Matrix Methods](chapters/matrix_methods/matrix_methods.md)
* [Gaussian Elimination](chapters/matrix_methods/gaussian_elimination/gaussian_elimination.md)
* [Thomas Algorithm](chapters/matrix_methods/thomas/thomas.md)
* [Computational Geometry](chapters/computational_geometry/computational_geometry.md)
* [Gift Wrapping](chapters/computational_geometry/gift_wrapping/gift_wrapping.md)
* [Jarvis March](chapters/computational_geometry/gift_wrapping/jarvis_march/jarvis_march.md)
* [Graham Scan](chapters/computational_geometry/gift_wrapping/graham_scan/graham_scan.md)
* [Chan's Algorithm](chapters/computational_geometry/gift_wrapping/chan/chans.md)
* [FFT](chapters/FFT/cooley_tukey.md)
* [Decision Problems](chapters/decision_problems/decision_problems.md)
* [Stable Marriage Problem](chapters/decision_problems/stable_marriage/stable_marriage.md)
* [Differential Equation Solvers](chapters/differential_equations/differential_equations.md)
* [Forward Euler Method](chapters/differential_equations/euler/euler.md)
* [Backward Euler Methods](chapters/differential_equations/euler/backward_euler.md)
* [Runge Kutta](chapters/differential_equations/runge_kutta/runge_kutta.md)
* [Physics Solvers](chapters/physics_solvers/physics_solvers.md)
* [Verlet Integration](chapters/physics_solvers/verlet/verlet.md)
* [Barnes-Hut](chapters/physics_solvers/barnes_hut.md)
* [Quantum Systems](chapters/physics_solvers/quantum/quantum.md)
* [Split-Operator Method](chapters/physics_solvers/quantum/split-op/split-op.md)
* [Data Compression](chapters/data_compression/data_compression.md)
* [Huffman Encoding](chapters/data_compression/huffman/huffman.md)
* [Quantum Information](chapters/QI/QI.md)
* [Convolutions](chapters/algorithms/convolutions/convolutions.md)
* [Taylor Series](chapters/general/taylor_series_expansion/taylor_series_expansion.md)
* [Sorting and Searching](chapters/general/sorting_and_searching/sorting_and_searching.md)
* [Bubble Sort](chapters/algorithms/bubble_sort/bubble_sort.md)
* [Bogo Sort](chapters/algorithms/bogo_sort/bogo_sort.md)
* [Tree Traversal](chapters/algorithms/tree_traversal/tree_traversal.md)
* [Euclidean Algorithm](chapters/algorithms/euclidean_algorithm/euclidean_algorithm.md)
* [Multiplication](chapters/general/multiplication/multiplication.md)
* [Monte Carlo](chapters/algorithms/monte_carlo_integration/monte_carlo_integration.md)
* [Matrix Methods](chapters/general/matrix_methods/matrix_methods.md)
* [Gaussian Elimination](chapters/algorithms/gaussian_elimination/gaussian_elimination.md)
* [Thomas Algorithm](chapters/algorithms/thomas_algorithm/thomas_algorithm.md)
* [Computational Geometry](chapters/general/computational_geometry/computational_geometry.md)
* [Gift Wrapping](chapters/general/gift_wrapping/gift_wrapping.md)
* [Jarvis March](chapters/algorithms/jarvis_march/jarvis_march.md)
* [Graham Scan](chapters/algorithms/graham_scan/graham_scan.md)
* [Chan's Algorithm](chapters/algorithms/chans_algorithm/chans_algorithm.md)
* [FFT](chapters/algorithms/cooley_turkey/cooley_tukey.md)
* [Decision Problems](chapters/general/decision_problems/decision_problems.md)
* [Stable Marriage Problem](chapters/algorithms/stable_marriage_problem/stable_marriage_problem.md)
* [Differential Equation Solvers](chapters/general/differential_equations/differential_equations.md)
* [Forward Euler Method](chapters/algorithms/forward_euler_method/forward_euler_method.md)
* [Backward Euler Methods](chapters/algorithms/backward_euler_method/backward_euler_method.md)
* [Physics Solvers](chapters/general/physics_solvers/physics_solvers.md)
* [Verlet Integration](chapters/algorithms/verlet_integration/verlet_integration.md)
* [Barnes-Hut](chapters/algorithms/barnes_hut_algorithm/barnes_hut_algorithm.md)
* [Quantum Systems](chapters/general/quantum_systems/quantum_systems.md)
* [Split-Operator Method](chapters/algorithms/split-operator_method/split-operator_method.md)
* [Data Compression](chapters/general/data_compression/data_compression.md)
* [Huffman Encoding](chapters/algorithms/huffman_encoding/huffman_encoding.md)
* [Quantum Information](chapters/general/quantum_information/quantum_information.md)
7 changes: 6 additions & 1 deletion book.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"wordcount",
"api-language-selector",
"include-codeblock",
"ga"
"ga",
"bulk-redirect"
],
"lunr": {
"maxIndexSize": 1000000000
Expand All @@ -18,6 +19,10 @@
"fixlang": true,
"unindent": true
},
"bulk-redirect": {
"basepath": "/",
"redirectsFile": "redirects.json"
},
"ga": {
"token": "UA-118252470-1"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
### Backward Euler Method

Unlike the forward Euler Method above, the backward Euler Method is an *implicit method*, which means that it results in a system of equations to solve. Luckily, we know how to solve systems of equations (*hint*: [Thomas Algorithm](../../computational_mathematics/matrix_methods/thomas/thomas.md), [Gaussian Elimination](../../computational_mathematics/matrix_methods/gaussian_elimination/gaussian_elimination.md))
Unlike the forward Euler Method above, the backward Euler Method is an *implicit method*, which means that it results in a system of equations to solve. Luckily, we know how to solve systems of equations (*hint*: [Thomas Algorithm](../thomas_algorithm/thomas_algorithm.md), [Gaussian Elimination](../gaussian_elimination/gaussian_elimination.md))

MORE TO COME!!!

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##### Dependencies
* [Verlet Integration](verlet.md)
* [Verlet Integration](../verlet_integration/verlet_integration.md)

# Barnes Hut Algorithm

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Now, let me tell you about a bit of black computational magic:

That is crazy!
It's also incredibly hard to explain, so let me do my best.
As described in the chapter on [Fourier Transforms](chapters/FFT/cooley_tukey.md), Fourier Transforms allow programmers to move from real space to frequency space.
As described in the chapter on [Fourier Transforms](../cooley_turkey/cooley_tukey.md), Fourier Transforms allow programmers to move from real space to frequency space.
When we transform a wave into frequency space, we see a single peak in frequency space related to the frequency of that wave.
No matter what function we send into a Fourier Transform, the frequency-space image can be interpreted as a series of different waves with a specified frequency.

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# The Forward Euler Method

The Euler methods are some of the simplest methods to solve ordinary differential equations numerically.
They introduce a new set of methods called the [Runge Kutta](../runge_kutta/runge_kutta.md) methods, which will be discussed in the near future!
They introduce a new set of methods called the [Runge Kutta](../runge_kutta_methods/runge_kutta_methods.md) methods, which will be discussed in the near future!

As a physicist, I tend to understand things through methods that I have learned before.
In this case, it makes sense for me to see Euler methods as extensions of the [Taylor Series Expansion](../../taylor/taylor_series.md).
In this case, it makes sense for me to see Euler methods as extensions of the [Taylor Series Expansion](../general/taylor_series_expansion/taylor_series_expansion.md).
These expansions basically approximate functions based on their derivatives, like so:

$$
Expand Down Expand Up @@ -48,7 +48,7 @@ $$
$$

Now, solving this set of equations in this way is known as the *forward* Euler Method.
In fact, there is another method known as the [*backward* Euler Method](backward_euler.md), which we will get to soon enough.
In fact, there is another method known as the [*backward* Euler Method](../backward_euler_method/backward_euler_method.md), which we will get to soon enough.
For now, it is important to note that the error of these methods depend on the timestep chosen.

<p>
Expand Down Expand Up @@ -83,17 +83,17 @@ $$
$$
Which means that the forward Euler method is actually unstable for most values!
If we want to stick to using the forward Euler method exclusively, the only solution is to decrease the timestep until it is within this stability region, and that's not necessarily easy for all cases.
So now it might be obvious that another, more stable method should be used instead; however, many other stable methods are *implicit*, which means that in order to find the solution, we need to solve a system of equations via the [Thomas Algorithm](../../matrix_methods/thomas/thomas.md) or [Gaussian Elimination](../../matrix_methods/gaussian_elimination/gaussian_elimination.md).
So now it might be obvious that another, more stable method should be used instead; however, many other stable methods are *implicit*, which means that in order to find the solution, we need to solve a system of equations via the [Thomas Algorithm](../thomas_algorithm/thomas_algorithm.md) or [Gaussian Elimination](../gaussian_elimination/gaussian_elimination.md).
Which is an entire layer of complexity that most people don't want to mess with!

Now, here is where we might want to relate the method to another algorithm that is sometimes used for a similar use-case: [Verlet Integration](../../physics_solvers/verlet/verlet.md).
Now, here is where we might want to relate the method to another algorithm that is sometimes used for a similar use-case: [Verlet Integration](../verlet_integration/verlet_integration.md).
Verlet integration has a distinct advantage over the forward Euler method in both error and stability with more coarse-grained timesteps; however, Euler methods are powerful in that they may be used for cases other than simple kinematics.
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.
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!
That said, variations of this method *are* certainly used (for example Crank-Nicolson and [Runge-Kutta](../runge_kutta_methods/runge_kutta_methods.md), so the time spent reading this chapter is not a total waste!

## Example Code

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.
Like in the case of [Verlet Integration](../verlet_integration/verlet_integration.md), the easiest way to test to see if this method works is to test it against a simple test-case.
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.
So, this time, let's remove ourselves from any physics and instead solve the following ODE: $$y' = 5y$$. Note that in this case, the velocity is directly given by the ODE and the acceleration is not part of the model.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Graham Scan

At around the same time of the [Jarvis March](jarvis_march.md), R. L. Graham was also developing an algorithm to find the convex hull of a random set of points {{ "gs1972" | cite }}.
At around the same time of the [Jarvis March](../jarvis_march/jarvis_march.md), R. L. Graham was also developing an algorithm to find the convex hull of a random set of points {{ "gs1972" | cite }}.
Unlike the Jarvis March, which is an $$\mathcal{O}(nh)$$ operation, the Graham Scan is $$\mathcal{O}(n\log(n))$$, where $$n$$ is the number of points and $$h$$ is the size fo the hull.
This means that the complexity of the Graham Scan is not output-sensitive; moreover, there are some cases where the Jarvis March is more optimal, depending on the size of the hull and the number of points to wrap.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ He managed to rip the heart out of the methods described by leaders of the field
It was in that moment, I knew I would never amount to anything.
I have since accepted that fact and moved on.

Huffman encoding follows from the problem described in the [Data Compression](../data_compression.md) section.
Huffman encoding follows from the problem described in the [Data Compression](../../general/data_compression/data_compression.md) section.
We have a string that we want to encode into bits.
Huffman encoding ensures that our encoded bitstring is as small as possible without losing any information.
Because it is both lossless and guarantees the smallest possible bit length, it outright replaces both Shannon and Shannon-Fano encoding in most cases, which is a little weird because the method was devised while Huffman was taking a course from Fano, himself!
Expand Down Expand Up @@ -50,7 +50,7 @@ The fact that this algorithm is both conceptually simple and provably useful is
## Example Code
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.
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.
In addition, to read the tree backwards, some sort of [Depth First Search](../../tree_traversal/tree_traversal.md) needs to be implemented.
In addition, to read the tree backwards, some sort of [Depth First Search](../tree_traversal/tree_traversal.md) needs to be implemented.
Whether you use a stack or straight-up recursion also depends on the language, but the recursive method is a little easier to understand in most cases.

{% method %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ $$
i \hbar \frac{\partial \Psi(\mathbf{r},t)}{\partial t} = \left[-\frac{\hbar^2}{2m}\nabla^2 + g|\Psi(\mathbf{r},t)|^2 \right] \Psi(\mathbf{r},t),
$$

which follows from the notation provided in the [quantum systems](../quantum.md) chapter: $$\Psi(\mathbf{r},t)$$ is a quantum wave-function with spatial ($$\mathbf{r}$$) and time ($$t$$) dependence and $$\nabla^2$$ is a laplacian; however, in this case, we also add an interaction tern $$g$$ next to a nonlinear $$|\Psi(\mathbf{r},t)|^2$$ term.
which follows from the notation provided in the [quantum systems](../../general/quantum_systems/quantum_systems.md) chapter: $$\Psi(\mathbf{r},t)$$ is a quantum wave-function with spatial ($$\mathbf{r}$$) and time ($$t$$) dependence and $$\nabla^2$$ is a laplacian; however, in this case, we also add an interaction tern $$g$$ next to a nonlinear $$|\Psi(\mathbf{r},t)|^2$$ term.
By adding in the $$V(\mathbf{r})$$ term, we get an equation used to study superfluid Bose--Einstein Condensate (BEC) systems:

$$
Expand All @@ -15,9 +15,9 @@ $$

This is the system I studied for most of my PhD (granted, we played a few tricks with parallelization and such, so it was _slightly_ more complicated).

At it's heart, the split-op method is nothing more than a pseudo-spectral differential equation solver... That is to say, it solves the Schrodinger equation with [FFT's](../../../FFT/cooley_tukey.md).
At it's heart, the split-op method is nothing more than a pseudo-spectral differential equation solver... That is to say, it solves the Schrodinger equation with [FFT's](../cooley_turkey/cooley_tukey.md).
In fact, there is a large class of spectral and pseudo-spectral methods used to solve a number of different physical systems, and we'll definitely be covering those in the future.
As mentioned in the [quantum systems](../quantum.md) section, we can represent a a quantum wavefunction in momentum space, which is parameterized with the wavevector $$k$$.
As mentioned in the [quantum systems](../../general/quantum_systems/quantum_systems.md) section, we can represent a a quantum wavefunction in momentum space, which is parameterized with the wavevector $$k$$.
In the hamiltonian shown above, we can split our system into real-space components, $$\hat{H}_R = \left[V(\mathbf{r}) + g|\Psi(\mathbf{r},t)|^2 \right] \Psi(\mathbf{r},t)$$, and momentum space components, $$\hat{H}_M = \left[-\frac{\hbar^2}{2m}\nabla^2 \right]\Psi(\mathbf{r},t)$$.
If we assume a somewhat general solution to our quantum system:

Expand All @@ -38,7 +38,7 @@ $$
\Psi(\mathbf{r},t+dt) = \left[e^{-\frac{i\hat{H}_Rdt}{2\hbar}}e^{-\frac{i\hat{H}_Mdt}{\hbar}}e^{-\frac{i\hat{H}_Rdt}{2\hbar}} \right]\Psi(\mathbf{r},t) + \mathcal{O}(dt^3)
$$

We can then address each part of this solution in chunks, first in real space, then in momentum space, then in real space again by using [Fourier Transforms](../../../FFT/cooley_tukey.md).
We can then address each part of this solution in chunks, first in real space, then in momentum space, then in real space again by using [Fourier Transforms](../cooley_turkey/cooley_tukey.md).
Which looks something like this:

$$
Expand Down
Loading