Concepts
Binary search tree
Search a binary tree whose subtrees obey the chosen ordering. Cost follows height, not automatically logarithmic without balancing.
Formal Syntax & Structure
javascript syntaxjavascript
while (node) { if (key === node.key) return true; node = key < node.key ? node.left : node.right; }Working Example
Example Snippetjavascript
const root={key:4,left:{key:2,left:null,right:null},right:{key:7,left:null,right:null}};function has(n,key){while(n){if(key===n.key)return true;n=key<n.key?n.left:n.right;}return false;}console.log(has(root,7),has(root,3));