This will work in GCC but not in G++
int main()
{
int new=1;
return 0;
}
There can be many programs of C++ , that cannot be compiled through GCC bcz
C++ is OOP for which G++ is needed.
On Sat, Sep 17, 2011 at 1:50 AM, SAMMM somnath.nit...@gmail.com wrote:
You can try this also this will
For big number mathematics, the multiplication time complexity is not
O(1).
And the programming complexity is to be considered as well.
On Mar 24, 3:36 pm, radha krishnan radhakrishnance...@gmail.com
wrote:
You can do it in (log n) assuming multiplication is O(1)
suppose u are going to
@yoku..r u sure..in 2nd last for loop by just setting if (matrix[0]
[0]==0) e.g. matrix[i][0]=0 and temp=0 e.g. (a[j][0]=0) u r doing
what asked in questionset a[i][j] or a[j][i] =0 if any a[i] or
a[j=0 ..i means r u sure that u r not skipping any row or colum
although u code is working
@bittu
I am 100% sure, it works fine for any 2D Binary matrix.
Algorithm:
Step 1: Store matrix [0][0] value in a temporary variable (Space
Complicity: O(1) ).
Step 2: Apply operation on first column and save it into Temp.
Step 3: Apply operation on first row and save it into
@rajnish:
i think u missed the point , the matrix is binary.. so how will you store -1
in it.
@pacific:
Will you solution work fine if 0 th row has all 1's and 0th column has
atleast one zero.??
On Mon, Mar 7, 2011 at 1:09 AM, yogesh kumar yoku2...@gmail.com wrote:
@pacific: Good Algorithm
@pacific: Good Algorithm
// This is the preface solution of this problem [:)]
// Time complexity: O(n^2)
// Space complexity: O(1)
public class BinaryMatrix
{
public static void main(String arg[])
{
int[][] matrix = new int[][]
Nice explanation n nice code...
On Sun, Feb 27, 2011 at 8:38 PM, gaurav gupta 1989.gau...@googlemail.comwrote:
@pacific in your case a[0][0] might be wrong. So lets do this :
a[0][0] = a[0][0 to n-1] a[1 to n-1][0] // of all elements in first
row and first column
for( int i=1; in; i++)
@pacific Absolutely correct.
Thanks for the explanation.
On Sun, Feb 27, 2011 at 6:14 PM, pacific pacific pacific4...@gmail.comwrote:
1. do operation on all the values in each column and store it in the
first row of each column
2. do operation on all the values in each row and store it in
@pacific in your case a[0][0] might be wrong. So lets do this :
a[0][0] = a[0][0 to n-1] a[1 to n-1][0] // of all elements in
first row and first column
for( int i=1; in; i++)
{
for( int j=1;jn;j++)
{
a[0][i] = a[j][i]; // a[0][i] contains of all
elements of ith
@Rajnish, Your algorithm works fine. If I'm not wrong you want to
differentiate between initial zeros(-1) and zeros(0) inserted by
replacement.
As I said its a binary matrix, So what I meant was the array can contain
only 0's and 1's. Sorry if it was not clear, but the most interesting part
is
@pacific in your case a[0][0] might be wrong. So lets do this :
a[0][0] = a[0][0 to n-1] a[1 to n-1][0] // of all elements in first row
and first column
for( int i=1; in; i++)
{
for( int j=1;jn;j++)
{
a[0][i] = a[j][i]; // a[0][i] contains of all elements
of ith
1. do operation on all the values in each column and store it in the first
row of each column
2. do operation on all the values in each row and store it in the first
column of each row.
(when writing at a[0][0] do operation with the value computed at 1.)
3. Now to find out the value at a[i][j]
If the diagonal elements of the matrix are all 0s, then you'd have to set
every element in the matrix to 0 (i.e. O(N^2) operations ). I don't think,
therefore, that we can do better than O(N^2). The best we can do is to
perhaps, make it output sensitive.
On Sun, Feb 27, 2011 at 6:14 PM,
1.) Traverse the whole matrix and replace each 0 value with -1.
2.) Traverse the matrix again,all the 1 values are replaced with 0 in
the row and column of the index where a -1 value is found.
3.) Set all -1 values to zero and we have the output array.
time complexity: O(n^2)
space complexity:
14 matches
Mail list logo