diff --git a/Dynamic Programming/Nth Factorial/README.md b/Dynamic Programming/Nth Factorial/README.md new file mode 100644 index 00000000..eb8986b7 --- /dev/null +++ b/Dynamic Programming/Nth Factorial/README.md @@ -0,0 +1,9 @@ +# Nth Factorial +Finding the nth Factorial using dynamic programming. + +## Complexity +* **Time**: ![](https://latex.codecogs.com/svg.latex?O(n)) +* **Space**: ![](https://latex.codecogs.com/svg.latex?O(n)) + +## References +* [TutorialsPoint](https://www.tutorialspoint.com/cplusplus-program-to-find-factorial-of-a-number-using-dynamic-programming) \ No newline at end of file diff --git a/Dynamic Programming/Nth Factorial/code.js b/Dynamic Programming/Nth Factorial/code.js new file mode 100644 index 00000000..36536239 --- /dev/null +++ b/Dynamic Programming/Nth Factorial/code.js @@ -0,0 +1,27 @@ +// import visualization libraries { +const { Tracer, Array1DTracer, Layout, VerticalLayout } = require('algorithm-visualizer'); +// } + +// define tracer variables { +const tracer = new Array1DTracer('Sequence'); +Layout.setRoot(new VerticalLayout([tracer])); +const index = 15; +const D = [1]; +for (let i = 1; i < index; i++) { + D.push(0); +} +tracer.set(D); +Tracer.delay(); +// } + +for (let i = 1; i < index; i++) { + D[i] = D[i - 1] * i; + // visualize { + tracer.select(i - 1); + Tracer.delay(); + tracer.patch(i, D[i]); + Tracer.delay(); + tracer.depatch(i); + tracer.deselect(i - 1); + // } +} 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