kdocs
GitHub
SC - DSA
SC - DSA
  • Complexity or Asymptotic Behavior
  • Data Structures
    • Graphs
    • Trees
  • Algorithms
    • Search
    • Sort
Powered by GitBook
On this page
  • Greedy
  • Divide and Conquer
  • Recursion
  • Dynamic Programming

Algorithms

PreviousTreesNextSearch

Last updated 6 months ago

Greedy

Greedy algorithms basically check the entire input and doesn't care to try reducing it.

Ex.:

Divide and Conquer

Split your input into chunks, analyse it then re-split it and on and on... to hopefully solve things faster.

Ex.: Recursion or

Recursion

Resolve something by breaking down the problem and re-looking at it until you reach a base case.

function factorial(n: number): number {
    // Base case
    if (n === 1) return 1;
    
    // Recurse
    return n * factorial(n - 1);
}

3 sections of recursion

Recursive functions can be broken down in three sections:

function factorial(n: number): number {
    /**
     * Pre-recurse, things to do before recursing
     */
     
     /**
      * Recurse
      */
     factorial(n - 1);
     
    /**
     * Post-recurse, things to do after recursing
     */
}

Dynamic Programming

Linear Search
Binary Search