For the complete documentation index, see llms.txt. Markdown variants are available by appending .md to any URL or sending an Accept: text/markdown header. An agent skill is available at /.well-known/agent-skills/site-skill.md.
0
Sponsor

Tech Talk

An 8-slide technical talk template with code examples and auto-animate transitions.

Tech Talk

Optimizing Fibonacci

From recursion to dynamic programming

Jane Smith2024

Agenda

  • The problem with naive recursion
  • Introducing memoization
  • Dynamic programming approach
  • Benchmark results
Part I

The Problem

Naive Recursion

fibonacci.ts
function fibonacci(n: number): number {
  if (n <= 1) return n;
  return fibonacci(n - 1) + fibonacci(n - 2);
}

O(2ⁿ) time complexity — exponential growth.

Before

function fibonacci(n: number): number {
  if (n <= 1) return n;
  return fibonacci(n - 1) + fibonacci(n - 2);
}

After

function fibonacci(n: number): number {
  const dp = [0, 1];
  for (let i = 2; i <= n; i++) {
    dp[i] = dp[i - 1] + dp[i - 2];
  }
  return dp[n];
}
Part II

Results

Benchmark Results

benchmark.txt
n=10:  recursive 0.02ms  ·  dp 0.01ms
n=20:  recursive 0.15ms  ·  dp 0.01ms
n=30:  recursive 18.2ms  ·  dp 0.02ms
n=40:  recursive 2.3s    ·  dp 0.02ms
n=50:  recursive timeout  ·  dp 0.03ms
Thank You

Questions?

github.com/jane/fib-opt · @janesmith

Installation

$ pnpm dlx shadcn@latest add https://slidecn.dev/r/tech-talk.json

Usage

import { Deck } from "@revealjs/react";
import { TechTalk } from "@/components/slides/blocks/tech-talk";
 
export function MyTechTalk() {
  return (
    <Deck>
      <TechTalk />
    </Deck>
  );
}

Slides

  1. Title — Talk title and speaker info
  2. Agenda — Animated agenda list
  3. Section — Part I divider
  4. Problem — Naive recursion with code
  5. Optimization — Auto-animate code before/after
  6. Section — Part II divider
  7. Results — Benchmark with highlighted lines
  8. Thanks — Q&A with links