I have a theory on how CBP is trained to scan people, that seems more plausible without assuming malicious intent: they're not expecting you to know exactly how to balance a BST, but just enough to hold a conversation about it while they look for telltale signs. My guess is that even a reply like, "Look, I'm a self-taught web developer and I don't deal with algorithms day-to-day, sorry. But you can ask me web dev questions if you wish." would work.