Welcome to the Recursion Algorithms repository! π
This project showcases recursive and iterative approaches to two popular problems: Fibonacci sequence generation and Merge Sort. Each problem is implemented in JavaScript and demonstrates the power of recursion in problem-solving.
This file contains:
fibs(num): Generates the firstnumFibonacci numbers using an iterative approach.fibsRec(num, memo): Generates the firstnumFibonacci numbers using a recursive approach with memoization for optimization.
This repository contains an implementation of the Merge Sort algorithm in JavaScript. Merge Sort is an efficient, general-purpose, comparison-based sorting algorithm that uses a divide-and-conquer approach to recursively split the array and merge sorted subarrays.
π How It Works
- Divide: The input array is recursively divided into two halves until each subarray contains a single element (or no elements).
- Conquer: The sorted subarrays are merged together by comparing elements and creating a new sorted array.
- Combine: This process continues until all subarrays are merged into a fully sorted array.
π§© Key Functions
mergeSort(array): Recursively splits and sorts the array.merge(leftArray, rightArray): Merges two sorted arrays into a single sorted array.
console.log(fibs(9)); // Output: [0,1,1,2,3,5,8,13,21]
console.log(fibsRec(9)); // Output: [0,1,1,2,3,5,8,13,21]
Merge:
let sample = [105, 79, 100, 110];
console.log(mergeSort(sample)); // Output: [79, 100, 105, 110]