Learn Boolean Parenthesization with a step-by-step Dynamic Programming visualizer, JavaScript source code and a worked example. Practice partition and interval dp.
INTERACTIVE EXECUTION STUDIO
LEARN BY DOING
Predict. Execute. Understand.
Follow the source code, inspect live state changes, and predict the next operation before revealing it.
Topic: Dynamic Programming · Partition and interval DP
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
"T|F&T"
Execution steps
Combine truth counts at each split
Computed output
2
JavaScript reference implementation
const solve = (a,s)=>{
let n=(a.length+1)/2,d=Array.from({
length:n
},()=>Array.from({
length:n
},()=>[0,0]));
for(let i=0;
i<n;
i++)d[i][i][a[2*i]==="T"?1:0]=1;
for(let len=2;
len<=n;
len++)for(let i=0;
i+len<=n;
i++){
let j=i+len-1;
for(let k=i;
k<j;
k++)for(let x=0;
x<2;
x++)for(let y=0;
y<2;
y++){
let op=a[2*k+1],v=op==="&"?x&y:op==="|"?x|y:x^y;
d[i][j][v]+=d[i][k][x]*d[k+1][j][y]
}
s("Combine truth counts at each split",{
DP:d.map(r=>r.map(x=>x.join("/"))),Interval:[i,j]
})
}
return d[0][n-1][1]
};