Back to questionsDSA Visualizers: 388 Coding Questions Upper Bound visualizer Learn Upper Bound with a step-by-step Binary Search visualizer, JavaScript source code and a worked example. Practice sorted arrays.
INTERACTIVE EXECUTION STUDIOLEARN BY DOING Predict. Execute. Understand. Follow the source code, inspect live state changes, and predict the next operation before revealing it.
1 / 4 Execution step
Prediction modePanel width Reference example · JavaScript
Inspect reference input {
"a": [
1,
3,
3,
5,
7
],
"k": 3,
"upper": true,
"count": false
} Code Visuals
JavaScript reference implementation · highlighted trace statement
1 const solve = ({
2 a,k,upper,count
3 },s)=>{
4 function bound(strict){
5 let l=0 ,r=a.length;
6 while (l<r){
7 let m=(l+r)>>1 ;
8 s("Test boundary",{
9 Array:a,Bounds:[l,m,r],Target:[k]
10 },[m]);
11 if (a[m]<k||strict&&a[m]===k)l=m+1 ;
12 else r=m
13 }
14 return l
15 }
16 return count?bound(true )-bound(false ):bound(upper)
17 };
Execution canvas Active ChangedSTEP 1 Test boundary Inspect the highlighted code and the state below. Click individual cells or nodes to see their values.
Worked example and algorithm walkthrough Topic: Binary Search · Sorted arrays
Follow the computed execution on the reference input. Advance one step at a time, inspect the changing values and compare your prediction with the final output.
Example input {
"a": [
1,
3,
3,
5,
7
],
"k": 3,
"upper": true,
"count": false
} Execution steps Test boundary Computed output 3 JavaScript reference implementation const solve = ({
a,k,upper,count
},s)=>{
function bound(strict){
let l=0,r=a.length;
while(l<r){
let m=(l+r)>>1;
s("Test boundary",{
Array:a,Bounds:[l,m,r],Target:[k]
},[m]);
if(a[m]<k||strict&&a[m]===k)l=m+1;
else r=m
}
return l
}
return count?bound(true)-bound(false):bound(upper)
};Continue learning Practice related DSA questions in the same topic.