I have an array of bits. Bits will be toggled off and on according to following criteria: 1. if the bits left and right of bit is on put the bit to one otherwise zero. 2. boundary condition(leftmost and rightmost bit will only depend on one bit. ie either left of it or right of it.
this array will be processed m times with the following criteria.
I wrote the following code where A is the original array and subsiquent is the array for processing. But this will give me O(nm) where n is the length and m is no of times i want to do the process. Please suggest me some alternative for the solution so that i can decrease my complexity.
for(int k = 0;k < m;k++){
for(int l = 0;l < n;k++){
if(l == 0){
if(A[l+1]==1)
subsiquent[l]=1;
else
subsiquent[l]=0;
//** is there a } missing here?
else if(l==n){
if(A[l-1]==1)
subsiquent[l]=1;
else
subsiquent[l]=0;
} else {
if(A[l+1]==1 && A[l-1]==1 ){
subsiquent[l]=1;
}else{
subsiquent[l]=0;
}
}
//** or is there a } missing here?
}
A = subsiquent;
}