Skip to content

Commit 5cba46c

Browse files
committed
Merging from origin, again
2 parents f7a5306 + 16ca5bf commit 5cba46c

File tree

10 files changed

+101
-49
lines changed

10 files changed

+101
-49
lines changed

.editorconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ indent_size = 4
7070
indent_style = space
7171
indent_size = 2
7272

73+
# Matlab
74+
[*.m]
75+
indent_style = space
76+
indent_size = 4
77+
7378
# Markdown
7479
[*.md]
7580
indent_style = space
@@ -85,6 +90,11 @@ indent_size = 2
8590
indent_style = space
8691
indent_size = 4
8792

93+
# Racket
94+
[*.rkt]
95+
indent_style = space
96+
indent_size = 2
97+
8898
# Rust
8999
[*.rs]
90100
indent_style = space

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ Chinmaya Mahesh
1313
Unlambder
1414
Kjetil Johannessen
1515
CDsigma
16+
DominikRafacz

chapters/FFT/cooley_tukey.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ Truth be told, I didn't understand it fully until I discretized real and frequen
5858

5959
In principle, the Discrete Fourier Transform (DFT) is simply the Fourier transform with summations instead of integrals:
6060

61-
$$X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2 \pi k n / N}$$
61+
$$X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2 \pi i k n / N}$$
6262

6363
and
6464

65-
$$x_n = \frac{1}{N} \sum_{k=0}^{N-1} X_k \cdot e^{2 \pi k n / N}$$
65+
$$x_n = \frac{1}{N} \sum_{k=0}^{N-1} X_k \cdot e^{2 \pi i k n / N}$$
6666

6767
Where $$X_n$$ and $$x_n$$ are sequences of $$N$$ numbers in frequency and real space, respectively.
6868
In principle, this is no easier to understand than the previous case!
@@ -72,7 +72,7 @@ For some reason, though, putting code to this transformation really helped me fi
7272
{% sample lang="jl" %}
7373
[import:2-11, lang:"julia"](code/julia/fft.jl)
7474
{% sample lang="c" %}
75-
[import:7-19, lang:"c_cpp"](code/c/fft.c)
75+
[import:8-19, lang:"c_cpp"](code/c/fft.c)
7676
{% sample lang="cpp" %}
7777
[import:2-11, lang:"julia"](code/julia/fft.jl)
7878
{% sample lang="hs" %}
@@ -117,7 +117,7 @@ In the end, the code looks like:
117117
{% sample lang="jl" %}
118118
[import:14-31, lang:"julia"](code/julia/fft.jl)
119119
{% sample lang="c" %}
120-
[import:21-40, lang:"c_cpp"](code/c/fft.c)
120+
[import:20-39, lang:"c_cpp"](code/c/fft.c)
121121
{% sample lang="cpp" %}
122122
[import:27-57, lang:"c_cpp"](code/c++/fft.cpp)
123123
{% sample lang="hs" %}
@@ -138,12 +138,12 @@ Butterfly Diagrams show where each element in the array goes before, during, and
138138
As mentioned, the FFT must perform a DFT.
139139
This means that even though we need to be careful about how we add elements together, we are still ultimately performing the following operation:
140140

141-
$$X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2 \pi k n / N}$$
141+
$$X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2 \pi i k n / N}$$
142142

143143
However, after shuffling the initial array (by bit reversing or recursive subdivision), we perform the matrix multiplication of the $$e^{-2 \pi k n / N}$$ terms in pieces.
144144
Basically, we split the array into a series of omega values:
145145

146-
$$\omega_N^k = e^{-2 \pi k / N}$$
146+
$$\omega_N^k = e^{-2 \pi i k / N}$$
147147

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

chapters/differential_equations.md

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//submitted by DominikRafacz
2+
import java.util.Random;
3+
4+
public class MonteCarlo {
5+
6+
public static void main(String[] args) {
7+
monteCarlo(10_000_000);
8+
}
9+
10+
//function to check whether point (x,y) is in unit circle
11+
private static boolean inCircle(double x, double y) {
12+
return x * x + y * y < 1;
13+
}
14+
15+
//function to calculate estimation of pi
16+
public static void monteCarlo(int samples) {
17+
int piCount = 0;
18+
19+
Random random = new Random();
20+
21+
for (int i = 0; i < samples; i++) {
22+
double x = random.nextDouble();
23+
double y = random.nextDouble();
24+
if (inCircle(x, y)) {
25+
piCount++;
26+
}
27+
}
28+
29+
double estimation = 4.0 * piCount / samples;
30+
31+
System.out.println("Estimated pi value: " + estimation);
32+
System.out.printf("Percent error: %.4f%%",
33+
100 * (Math.PI - estimation) / Math.PI);
34+
}
35+
}

chapters/monte_carlo/monte_carlo.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ each point is tested to see whether it's in the circle or not:
5353
[import:2-5, lang:"d"](code/d/monte_carlo.d)
5454
{% sample lang="go" %}
5555
[import:12-14, lang:"golang"](code/go/monteCarlo.go)
56+
{% sample lang="java" %}
57+
[import:11-13, lang:"java"](code/java/MonteCarlo.java)
5658
{% endmethod %}
5759

5860
If it's in the circle, we increase an internal count by one, and in the end,
@@ -108,6 +110,9 @@ Feel free to submit your version via pull request, and thanks for reading!
108110
{%sample lang="go" %}
109111
### Go
110112
[import, lang:"golang"](code/go/monteCarlo.go)
113+
{% sample lang="java" %}
114+
### Java
115+
[import, lang:"java"](code/java/MonteCarlo.java)
111116
{% endmethod %}
112117

113118

chapters/sorting_searching/bogo/bogo_sort.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ imagine you have an array of $$n$$ elements that you want sorted.
88
One way to do it is to shuffle the array at random and hope that all the elements will be magically in order after shuffling.
99
If they are not in order, just shuffle everything again.
1010
And then again. And again.
11-
In the best case, this algorithm runs with a complexity of $$\Omega(1)$$, and in the worst, $$\mathcal{O}(\infty)$$.
11+
In the best case, this algorithm runs with a complexity of $$\Omega(n)$$, and in the worst, $$\mathcal{O}(\infty)$$.
1212

1313
In code, it looks something like this:
1414

@@ -18,9 +18,9 @@ In code, it looks something like this:
1818
{% sample lang="cs" %}
1919
[import:9-15, lang:"csharp"](code/cs/BogoSort.cs)
2020
{% sample lang="clj" %}
21-
[import:2-10, lang:"clojure"](code/clojure/bogo.clj)
21+
[import:2-11, lang:"clojure"](code/clojure/bogo.clj)
2222
{% sample lang="c" %}
23-
[import:4-27, lang:"c_cpp"](code/c/bogo_sort.c)
23+
[import:4-29, lang:"c_cpp"](code/c/bogo_sort.c)
2424
{% sample lang="java" %}
2525
[import:2-17, lang:"java"](code/java/bogo.java)
2626
{% sample lang="js" %}

chapters/sorting_searching/bubble/bubble_sort.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This means that we need to go through the vector $$\mathcal{O}(n^2)$$ times with
1313
{% sample lang="cs" %}
1414
[import:9-27, lang:"csharp"](code/cs/BubbleSort.cs)
1515
{% sample lang="c" %}
16-
[import:3-21, lang:"c_cpp"](code/c/bubble_sort.c)
16+
[import:4-22, lang:"c_cpp"](code/c/bubble_sort.c)
1717
{% sample lang="java" %}
1818
[import:2-12, lang:"java"](code/java/bubble.java)
1919
{% sample lang="js" %}

chapters/tree_traversal/code/python/Tree_example.py

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
class Node:
2-
32
def __init__(self):
43
self.data = None
54
self.children = []
65

6+
77
def create_tree(node, num_row, num_child):
88
node.data = num_row
99

@@ -14,12 +14,37 @@ def create_tree(node, num_row, num_child):
1414

1515
return node
1616

17+
1718
def DFS_recursive(node):
18-
if len(node.children) > 0:
19+
if node.data != None:
20+
print(node.data)
21+
22+
for child in node.children:
23+
DFS_recursive(child)
24+
25+
26+
def DFS_recursive_postorder(node):
27+
for child in node.children:
28+
DFS_recursive(child)
29+
30+
if node.data != None:
1931
print(node.data)
2032

21-
for child in node.children:
22-
DFS_recursive(child)
33+
34+
# This assumes only 2 children, but accounts for other possibilities
35+
def DFS_recursive_inorder_btree(node):
36+
if (len(node.children) == 2):
37+
DFS_recursive_inorder_btree(node.children[1])
38+
print(node.data)
39+
DFS_recursive_inorder_btree(node.children[2])
40+
elif (len(node.children) == 1):
41+
DFS_recursive_inorder_btree(node.children[1])
42+
print(node.data)
43+
elif (len(node.children) == 0):
44+
print(node.data)
45+
else:
46+
print("Not a binary tree!")
47+
2348

2449
def DFS_stack(node):
2550
stack = []
@@ -34,6 +59,7 @@ def DFS_stack(node):
3459
for child in temp.children:
3560
stack.append(child)
3661

62+
3763
def BFS_queue(node):
3864
queue = []
3965
queue.append(node)
@@ -47,6 +73,7 @@ def BFS_queue(node):
4773
for child in temp.children:
4874
queue.append(child)
4975

76+
5077
def main():
5178
tree = create_tree(Node(), 3, 3)
5279

@@ -59,5 +86,7 @@ def main():
5986
print("Queue:")
6087
BFS_queue(tree)
6188

62-
main()
89+
90+
if __name__ == '__main__':
91+
main()
6392

chapters/tree_traversal/tree_traversal.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Trees are naturally recursive data structures, and because of this, we cannot ac
1717
This has not been implemented in your chosen language, so here is the Julia code
1818
[import:3-7, lang:"julia"](code/julia/Tree.jl)
1919
{% sample lang="py" %}
20-
[import:1-5, lang:"python"](code/python/Tree_example.py)
20+
[import:1-4, lang:"python"](code/python/Tree_example.py)
2121
{% sample lang="scratch" %}
2222
This has not been implemented in your chosen language, so here is the Julia code
2323
[import:3-7, lang:"julia"](code/julia/Tree.jl)
@@ -43,7 +43,7 @@ Because of this, the most straightforward way to traverse the tree might be recu
4343
{% sample lang="js" %}
4444
[import:12-15, lang:"javascript"](code/javascript/tree.js)
4545
{% sample lang="py" %}
46-
[import:7-15, lang:"python"](code/python/Tree_example.py)
46+
[import:18-23, lang:"python"](code/python/Tree_example.py)
4747
{% sample lang="scratch" %}
4848
This has not been implemented in your chosen language, so here is the Julia code
4949
[import:9-16, lang:"julia"](code/julia/Tree.jl)
@@ -79,8 +79,7 @@ This has not been implemented in your chosen language, so here is the Julia code
7979
{% sample lang="js" %}
8080
[import:17-20, lang:"javascript"](code/javascript/tree.js)
8181
{% sample lang="py" %}
82-
This has not been implemented in your chosen language, so here is the Julia code
83-
[import:18-26, lang:"julia"](code/julia/Tree.jl)
82+
[import:26-31, lang:"python"](code/python/Tree_example.py)
8483
{% sample lang="scratch" %}
8584
This has not been implemented in your chosen language, so here is the Julia code
8685
[import:18-26, lang:"julia"](code/julia/Tree.jl)
@@ -112,8 +111,7 @@ This has not been implemented in your chosen language, so here is the Julia code
112111
{% sample lang="js" %}
113112
[import:22-34, lang:"javascript"](code/javascript/tree.js)
114113
{% sample lang="py" %}
115-
This has not been implemented in your chosen language, so here is the Julia code
116-
[import:28-43, lang:"julia"](code/julia/Tree.jl)
114+
[import:34-46, lang:"python"](code/python/Tree_example.py)
117115
{% sample lang="scratch" %}
118116
This has not been implemented in your chosen language, so here is the Julia code
119117
[import:28-43, lang:"julia"](code/julia/Tree.jl)
@@ -154,7 +152,7 @@ In code, it looks like this:
154152
{% sample lang="js" %}
155153
[import:36-43, lang:"javascript"](code/javascript/tree.js)
156154
{% sample lang="py" %}
157-
[import:24-35, lang:"python"](code/python/Tree_example.py)
155+
[import:49-60, lang:"python"](code/python/Tree_example.py)
158156
{% sample lang="scratch" %}
159157
This has not been implemented in your chosen language, so here is the Julia code
160158
[import:45-56, lang:"julia"](code/julia/Tree.jl)
@@ -187,7 +185,7 @@ And this is exactly what Breadth-First Search (BFS) does! On top of that, it can
187185
{% sample lang="js" %}
188186
[import:45-52, lang:"javascript"](code/javascript/tree.js)
189187
{% sample lang="py" %}
190-
[import:37-48, lang:"python"](code/python/Tree_example.py)
188+
[import:63-74, lang:"python"](code/python/Tree_example.py)
191189
{% sample lang="scratch" %}
192190
This has not been implemented in your chosen language, so here is the Julia code
193191
[import:58-69, lang:"julia"](code/julia/Tree.jl)

0 commit comments

Comments
 (0)