Changing a node value in place can violate the ordering invariant. Updating 3 to 100 while leaving it in the left subtree makes future search results wrong. A safe update is delete plus insert, or rebuilding the affected structure.
Complexity
For a balanced tree, search and insert are O(log n). For a badly skewed tree, both degrade to O(n)—a linked list wearing a tree costume.
Production containers use balancing strategies such as AVL or red-black trees when worst-case behavior matters. This implementation is deliberately unbalanced because its job is to expose the invariant, not to impersonate a standard library.
Data.define requires modern Ruby. On older Ruby versions, replace it with Struct.new(:value, :left, :right, keyword_init: true).