Skip to content

Commit 145cc57

Browse files
frankymacster64json
authored andcommitted
Add Dynamic Progamming/Nth Factorial (#18)
1 parent 5cc8741 commit 145cc57

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Nth Factorial
2+
Finding the nth Factorial using dynamic programming.
3+
4+
## Complexity
5+
* **Time**: ![](https://latex.codecogs.com/svg.latex?O(n))
6+
* **Space**: ![](https://latex.codecogs.com/svg.latex?O(n))
7+
8+
## References
9+
* [TutorialsPoint](https://www.tutorialspoint.com/cplusplus-program-to-find-factorial-of-a-number-using-dynamic-programming)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// import visualization libraries {
2+
const { Tracer, Array1DTracer, Layout, VerticalLayout } = require('algorithm-visualizer');
3+
// }
4+
5+
// define tracer variables {
6+
const tracer = new Array1DTracer('Sequence');
7+
Layout.setRoot(new VerticalLayout([tracer]));
8+
const index = 15;
9+
const D = [1];
10+
for (let i = 1; i < index; i++) {
11+
D.push(0);
12+
}
13+
tracer.set(D);
14+
Tracer.delay();
15+
// }
16+
17+
for (let i = 1; i < index; i++) {
18+
D[i] = D[i - 1] * i;
19+
// visualize {
20+
tracer.select(i - 1);
21+
Tracer.delay();
22+
tracer.patch(i, D[i]);
23+
Tracer.delay();
24+
tracer.depatch(i);
25+
tracer.deselect(i - 1);
26+
// }
27+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy