Join Nostr
2026-10-27 09:07:59 UTC
in reply to

codementor on Nostr: Each new value is bigger than everything before it, so it always goes right. You get ...

Each new value is bigger than everything before it, so it always goes right. You get a chain, like a linked list.

```csharp
Node? root = null;
for (int v = 1; v <= 7; v++) root = Insert(root, v);
Console.WriteLine(Height(root));

Node Insert(Node? n, int v)
{
if (n == null) return new Node(v);
if (v < n.Value) n.Left = Insert(n.Left, v); else n.Right = Insert(n.Right, v);
return n;
}
```

It prints 7: one level per value.

Searching that tree is O(n) instead of O(log n). Sorted input is the worst case for a plain BST, and it is common in real data.

#tg002 · TG-002-A3