Step 2 of 4
Binary Search Lookup
You start from the build so far — your own work where you have written it, the reference build where you have not. Either way this step stands on its own.
Implement search(val) to locate values in $O(\log n)$ average time.
- Starting at
root:- If node is null, return
false. - If
val === node.value, returntrue. - If
val < node.value, continue search in left subtree. - If
val > node.value, continue search in right subtree.
- If node is null, return
Your build
Running is free — Submit is what records the step. Or press ⌘↩
Tests
1 case| call | type | expected | result |
|---|---|---|---|
| runOps([["insert",50],["insert",30],["insert",70],["insert",20],["insert",40],["search",40],["search",70],["search",25]]) | finds existing and absent values across tree | [null,null,null,null,null,true,true,false] | — |
Hints
Stuck? Hints open one at a time, each giving a little more away.
2 hints left