Skip to content

aennin/recursion-algorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Recursion Algorithms in JavaScript

This project demonstrates the implementation of classic recursive algorithms in JavaScript, including Fibonacci sequence generation and Merge Sort. Both recursive and iterative approaches are explored to highlight the power and trade-offs of recursion.


Project Structure

  • fibonacci.js
    Implements functions to compute the Fibonacci sequence using both iteration and recursion.

  • mergeSort.js
    Implements the Merge Sort algorithm recursively.


Getting Started

1. Clone the repository

git clone https://github.com/your-username/recursion-algorithms.git
cd recursion-algorithm

2. Run the algorithms

You can run the files directly with Node.js:

node fibonacci.js
node mergeSort.js

For automatic restarts on file changes, use nodemon:

nodemon fibonacci.js

Stop nodemon anytime with ctrl + C

Algorithms Implemented

Fibonacci (fibonacci.js)

  • fibs(n): Iterative method to compute the first n Fibonacci numbers.
  • fibsRec(n): Recursive method to compute the first n Fibonacci numbers. Example:
console.log(fibsRec(8)); // [0, 1, 1, 2, 3, 5, 8, 13]

Merge Sort (mergeSort.js)

  • mergeSort(arr): Recursively sorts an array using the divide-and-conquer approach.

Example:

console.log(mergeSort([38, 27, 43, 3, 9])); // [3, 9, 27, 38, 43]

Key Learning Points

  • Recursion allows breaking down problems into smaller subproblems.
  • Iterative methods can sometimes be more efficient, but recursion often makes code cleaner and more elegant.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published