npub1u6…v0yg2 on Nostr: Learn: Tree What: nodes in a hierarchy. One root at the top, each node has children, ...
Learn: Tree
What: nodes in a hierarchy. One root at the top, each node has children, nodes with no children are leaves.
Use it when: data is nested: folders, HTML, company org charts, menus, and database indexes.
Most tree problems are recursion: solve for the children, then combine.
```csharp
var root = new Tree(1, new Tree(2, null, null), new Tree(3, new Tree(4, null, null), null));
Console.WriteLine(Count(root));
static int Count(Tree? t) => t == null ? 0 : 1 + Count(t.Left) + Count(t.Right);
```
It prints 4: the number of nodes.
Read more:
https://www.geeksforgeeks.org/dsa/tree-data-structure/#tip · TIP-030
Published at
2026-10-26 10:37:49 UTCEvent JSON
{
"id": "3d512a1e7a0da846f6095bd7f3ebd18399e87dbf75e7c0d2497f97c7d94e1f6a",
"pubkey": "e68a0856e90d9997b1f721e905249896412dd570399a987b2e8fd5e7fcfe2279",
"created_at": 1793011069,
"kind": 1,
"tags": [
[
"t",
"tip"
]
],
"content": "Learn: Tree\n\nWhat: nodes in a hierarchy. One root at the top, each node has children, nodes with no children are leaves.\nUse it when: data is nested: folders, HTML, company org charts, menus, and database indexes.\nMost tree problems are recursion: solve for the children, then combine.\n\n```csharp\nvar root = new Tree(1, new Tree(2, null, null), new Tree(3, new Tree(4, null, null), null));\nConsole.WriteLine(Count(root));\n\nstatic int Count(Tree? t) =\u003e t == null ? 0 : 1 + Count(t.Left) + Count(t.Right);\n```\n\nIt prints 4: the number of nodes.\n\nRead more: https://www.geeksforgeeks.org/dsa/tree-data-structure/\n\n#tip · TIP-030",
"sig": "7c713fc4ca90ee86072fb2a776287ac314c904de473e7a2538287ff46385a79c4d87ca6ac3398116340eb814e0eeb2cbbcfe911394df96c06270cb0ad4b9b985"
}