function result = computeP(i,j, p, bStar)
%i, j are indexes of the string
    result = p{i,j};
    for k=i:j
        temp = bStar{k,j};
        result = unique([result;temp],'rows');
        result_sum = sum(result,1);
		% Checks the validity of the output
        if size(result,1)>2 
            if result_sum(1) ~= 0 && result_sum(2) ~=0 && result_sum(3) ~=0
                temp2 = convhulln(result);
                temp3 = unique((reshape(temp2,size(temp2,1)*3,1)),'rows');
                result = result(temp3,:);
            else
                if result_sum(1) ~= 0 && result_sum(2) ~=0
                    result = result(convhull(result(:,1),result(:,2)),:);
                end
        
                if result_sum(2) ~= 0 && result_sum(3) ~=0
                    result = result(convhull(result(:,2),result(:,3)),:);
                end  
        
                if result_sum(1) ~= 0 && result_sum(3) ~=0
                    result = result(convhull(result(:,1),result(:,3)),:);
                end 
            end
        
        end
    end
end