Join Nostr
2026-10-26 10:37:49 UTC

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