再帰

より小さなサブ問題を解決するために自分自身を呼び出す関数。

Recursion is a programming technique where a function calls itself directly or indirectly. It involves a 'base case' to terminate the process and a 'recursive step' that breaks the problem into a simpler version of itself. It is particularly elegant for solving problems involving trees, fractals, and mathematical sequences.

        graph LR
  Center["再帰"]:::main
  Rel_algorithm["algorithm"]:::related -.-> Center
  click Rel_algorithm "/terms/algorithm"
  Rel_adiabatic_quantum_computation["adiabatic-quantum-computation"]:::related -.-> Center
  click Rel_adiabatic_quantum_computation "/terms/adiabatic-quantum-computation"
  Rel_search_algorithm["search-algorithm"]:::related -.-> Center
  click Rel_search_algorithm "/terms/search-algorithm"
  classDef main fill:#7c3aed,stroke:#8b5cf6,stroke-width:2px,color:white,font-weight:bold,rx:5,ry:5;
  classDef pre fill:#0f172a,stroke:#3b82f6,color:#94a3b8,rx:5,ry:5;
  classDef child fill:#0f172a,stroke:#10b981,color:#94a3b8,rx:5,ry:5;
  classDef related fill:#0f172a,stroke:#8b5cf6,stroke-dasharray: 5 5,color:#94a3b8,rx:5,ry:5;
  linkStyle default stroke:#4b5563,stroke-width:2px;

      

🧠 理解度チェック

1 / 1

🧒 5歳でもわかるように説明

階段を数えたいと想像してください。「何段?まあ、1足す残りの段数だね」と言えます。階段がなくなるまで聞き続けます。それが再帰です!

🤓 Expert Deep Dive

末尾呼び出し最適化(TCO)は、末尾再帰関数のスタック増加を排除します。メモ化は、指数関数的なフィボナッチを線形に変換します。継続渡しスタイル(CPS)は、すべての呼び出しを末尾呼び出しにします。Yコンビネータはラムダ計算での再帰を可能にします。

📚 出典