### sets all cells of row i and column j to 0

Given a matrix of 1s and 0s. Implement an algorithm that sets all cells of row i and column j to 0 if the original matrix has a 0 in cell (i,j). Would the algo change if you have to set it to 1 instead of 0?

I cant understand, is it something like following,

ReplyDeleteinput:

101001

001011

100011

output:

000000

000000

000000

here i am traversing the matrix from left to right.

I have solved it somehow, goto this link

ReplyDeleteMatrix Problem 01

Leave your valuable comment there.

@tanmay there is nothing wrong in this code but for each value mat(i,j) you are changing the value of all rows and cols corresponding to this value.Instead of that you can take the product of particular rows and cols and then evaluate each element.

ReplyDeletefor any array[i][j]; perform the following calc:

ReplyDeletefor (col = 0; col < NUMCOLS; ++col)

{

array[i][j] &&= array[i][col];

}

for (row = 0; row < NUMROWS; ++row)

{

array[i][j] &&= array[row][j];

}

OR you can store the value of inner loop in some array instead of repeating it.

I failed to solve one of your problem's

ReplyDelete"Merge two sorted arrays without redundancy"in the first attempt. I will try it again. Because I liked the problem.However, I also have posted two problems which will seem easy to you as I think you are a very good programmer. But still you can check them out through the following links....

Matrix Problem 02

Problem: In a given matrix all the cells will contain a value of 1 or 0. Change the value of a cell to 1 if the summation of its 8 adjacent cells are 3 or greater than 3, otherwise change the value to 0. Boundary cells can have 3 or 5 or less adjacent cells depending on the size of the matrix, so for boundary cells you will have to calculate over them. The number of rows and columns will be equal. For example, you might be given a 8x8 matrix. The values will be given by the user. You can keep the number of cells 8x8 or you can make it variable or user inputted.

Tic-Tac-Toe Game

Problem: We hope we are all known with the game Tic-Tac-Toe. Well..if we are not, we will be soon. You will not have to build any artificial intelligence for the game as the game will be played by two human, I mean users. Lets get into it.....

Visit the links for explanations with required images and download links of the EXEs of the solutions I made.I dont know why I am not becoming able to comment anywhere, The Comment As option box is not showing anything and preventing from commenting...!! Thats why commenting here from email link.

ReplyDeleteI think I solve a problem of yours: Binary Tree is Sum Tree or Not

However, I used complete binary tree and another limitation is that you will have to use distinct element only. I tried a lot. But it is still creating problem when it is visiting the root array, it is adding redundant entries. So dont use redundant entries.

[The Solution is Here]

Please leave your comment there at my post. Thank you.