Skip to content

Commit 7edcef0

Browse files
author
Shawn Toubeau
committed
moved algorithm desc to algo files
1 parent 7d3f553 commit 7edcef0

File tree

7 files changed

+62
-55
lines changed

7 files changed

+62
-55
lines changed

src/algos.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/components/Maze/algorithms/A*.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,17 @@ const runAstar = (props: Props) => {
118118
}, 100 / currentSpeed);
119119
};
120120

121-
export default runAstar;
121+
const aStarDesc =
122+
" ### A* Info\
123+
\nA* pronounced A-Star was originally created in an attempt to create a general purpose robot as part of the Shakey\
124+
project in the 1960’s and 70’s. A* is a best-first search algorithm.\
125+
\n### Runtime: \
126+
\nThe time complexity is polynomial when the search space is a tree, there is a single goal state,\
127+
and the heuristic function h meets the following condition:\
128+
\n| h ( x ) − h ∗ ( x ) | = O ( log ⁡ h ∗ ( x ) ) \
129+
\nwhere h* is the optimal heuristic, the exact cost to get from x to the goal.\
130+
\n### Helpful links:\
131+
\n[The Coding Train (video part1)] (https://www.youtube.com/watch?v=aKYlikFAV4k&t=968s) \
132+
\n[Computerphile (video)] (https://www.youtube.com/watch?v=ySN5Wnu88nE )";
133+
134+
export { runAstar, aStarDesc };

src/components/Maze/algorithms/BFS.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,14 @@ const runBFS = (props: Props) => {
7070
return;
7171
};
7272

73-
export default runBFS;
73+
const bfsDesc =
74+
"### BFS Info\
75+
\nBreadth-First Search is a graph or tree traversing algorithm that looks at all nodes at the current level \
76+
before moving onto the next deepest set of nodes. It was created by Konrad Zuse in 1945 and later reinvented by Edward F. Moore in 1959. \
77+
\n### Runtime:\
78+
\nO( | V | + | E |) where V is the number of nodes and E the number of edges.\
79+
\n### Helpful links: \
80+
\n[TheHippieCat (video)] (https://www.youtube.com/watch?v=WvR9voi0y2I)\
81+
\n[Nesbox (README)] (https://github.com/nesbox/TIC-80/wiki/Pathfinding%EA%9E%89-BFS-Algorithm)";
82+
83+
export { runBFS, bfsDesc };

src/components/Maze/algorithms/DFS.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,14 @@ const runDFS = (props: Props) => {
6767
}, 100 / currentSpeed);
6868
};
6969

70-
export default runDFS;
70+
const dfsDesc =
71+
"### DFS Info\
72+
\nDepth-first search is a pathfinding or tree spanning algorithm that follows one branch to its deepest point before backtracking. \
73+
It was created in the 19th century by French mathematician Charles Pierre Trémaux. \
74+
\n### Runtime:\
75+
\nO( | V | + | E |) where V is the number of nodes and E the number of edges.\
76+
\n### Helpful links:\
77+
\n[Brilliant (articel)] (https://brilliant.org/wiki/depth-first-search-dfs)\
78+
\n[Go GATE IIT (video)](https://www.youtube.com/watch?v=iaBEKo5sM7w)";
79+
80+
export { runDFS, dfsDesc };

src/components/Maze/algorithms/Djikstras.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,15 @@ const runDjikstras = (props: Props) => {
9696
}, 100 / currentSpeed);
9797
};
9898

99-
export default runDjikstras;
99+
const djikstrasDesc =
100+
"### Djikstra's Algorithm Info\
101+
\nDjikstra's shortest path first Algorithm is a pathfinding algorithm created by Edsger W. Djikstra in 1956. \
102+
It uses a min-priority queue to find the shortest path of a weighted graph. \
103+
\n### Runtime: \
104+
\n(Min-priority queue) O(| V | +| E |log| V |) (where | V | s the number of nodes and | E | is the number of edges)\
105+
\n(Array) O(V^2)\
106+
\n### Helpful links:\
107+
\n[Computerphile (video)](https://www.youtube.com/watch?v=GazC3A4OQTE)\
108+
\n[Clément Mihailescu (video)] (https://www.youtube.com/watch?v=msttfIHHkak&t=2826s)";
109+
110+
export { runDjikstras, djikstrasDesc };

src/components/Maze/algorithms/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import _ from "lodash";
2-
import runBFS from "./BFS";
3-
import runDFS from "./DFS";
4-
import runAstar from "./A*";
5-
import runDjikstras from "./Djikstras";
2+
import { runBFS, bfsDesc } from "./BFS";
3+
import { runDFS, dfsDesc } from "./DFS";
4+
import { runAstar, aStarDesc } from "./A*";
5+
import { runDjikstras, djikstrasDesc } from "./Djikstras";
66
import { Coord, MazeInfo } from "../../../models/maze";
77
import { SpaceTypes } from "../../Space/types";
88
import { getMazeSize } from "../Maze";
@@ -159,4 +159,8 @@ export {
159159
getLowestFScore,
160160
getValidNeighbors,
161161
removeFromArr,
162+
aStarDesc,
163+
bfsDesc,
164+
dfsDesc,
165+
djikstrasDesc,
162166
};

src/components/Menu/index.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ import * as yup from "yup";
2323
import { Maze } from "../../models/maze";
2424
import { SpaceTypes } from "../Space/types";
2525
import { Algorithms } from "../Maze/algorithms/types";
26-
import algos from "../../algos";
2726
import { getMazeSize } from "../Maze/Maze";
27+
// Algorithm information
28+
import { aStarDesc, bfsDesc, dfsDesc, djikstrasDesc } from "../Maze/algorithms";
2829

2930
import "./Menu.scss";
3031

@@ -228,13 +229,13 @@ class MenuBar extends React.Component<MenuProps, _MenuState> {
228229
if (al === null) {
229230
al = "Select an algorithm";
230231
} else if (al === Algorithms.astar) {
231-
al = algos.a;
232+
al = aStarDesc;
232233
} else if (al === Algorithms.bfs) {
233-
al = algos.BFS;
234+
al = bfsDesc;
234235
} else if (al === Algorithms.dfs) {
235-
al = algos.DFS;
236+
al = dfsDesc;
236237
} else if (al === Algorithms.djikstras) {
237-
al = algos.Djikstras;
238+
al = djikstrasDesc;
238239
}
239240
return al as string;
240241
};

0 commit comments

Comments
 (0)