npub1u6…v0yg2 on Nostr: Learn: When recursion fits Use recursion when a problem contains smaller copies of ...
Learn: When recursion fits
Use recursion when a problem contains smaller copies of itself: trees, folders inside folders, divide and conquer, trying all options (backtracking).
Every recursive function needs a base case and a step toward it.
```csharp
Console.WriteLine(Factorial(5));
static long Factorial(int n) => n <= 1 ? 1 : n * Factorial(n - 1);
```
It prints 120. For very deep inputs, a loop is safer: each call uses stack memory.
Read more:
https://www.geeksforgeeks.org/dsa/recursion-algorithms/#tip · TIP-041
Published at
2026-10-28 06:38:06 UTCEvent JSON
{
"id": "1f217be77cad57929eeb3c420c95b07341a4671ece3c2261ec02c0ad7d6bd7ee",
"pubkey": "e68a0856e90d9997b1f721e905249896412dd570399a987b2e8fd5e7fcfe2279",
"created_at": 1793169486,
"kind": 1,
"tags": [
[
"t",
"tip"
]
],
"content": "Learn: When recursion fits\n\nUse recursion when a problem contains smaller copies of itself: trees, folders inside folders, divide and conquer, trying all options (backtracking).\n\nEvery recursive function needs a base case and a step toward it.\n\n```csharp\nConsole.WriteLine(Factorial(5));\nstatic long Factorial(int n) =\u003e n \u003c= 1 ? 1 : n * Factorial(n - 1);\n```\n\nIt prints 120. For very deep inputs, a loop is safer: each call uses stack memory.\n\nRead more: https://www.geeksforgeeks.org/dsa/recursion-algorithms/\n\n#tip · TIP-041",
"sig": "cd7f6f7f491f7981a3ec65f08563f597032fd8251d6d15a20247b9af1b4655369505fa216297224f7792f2a75eb6055b7003002b6dae260e595c945aace33c80"
}