Re: [algogeeks] matrix Multiplication

2013-01-20 Thread mike anastasakis
I need to multiply an array A by it self. Is there an algorithm that does array multiplication with complexity O(n^2)?Doesn't it take at least O(n^3)? On Sun, Jan 20, 2013 at 12:44 AM, Dave dave_and_da...@juno.com wrote: @Guneesh: I think you mean to say that the complexity of both the

Re: [algogeeks] matrix Multiplication

2013-01-20 Thread Dave
@Koup: No, I meant O(n^3 log k). Sorry. Dave On Sunday, January 20, 2013 3:09:00 AM UTC-6, Koup wrote: I need to multiply an array A by it self. Is there an algorithm that does array multiplication with complexity O(n^2)?Doesn't it take at least O(n^3)? On Sun, Jan 20, 2013 at 12:44 AM,

[algogeeks] matrix Multiplication

2013-01-19 Thread Koup
I want to get the power of an matrix. I mean lets say my matrix is A i wanna get the A ^k. I have though the simple algorithm that gives me O(n^3).I though I could do some kind of a change to modify it and be faster. I could use the algorithm that is used to get the power of a number that

Re: [algogeeks] matrix Multiplication

2013-01-19 Thread Guneesh Paul Singh
consider code to find n^k where n is an integer int power() { int ans=1,val=1; while(k) { val=val*n; if(k1)ans=ans*val; k=k1; } return ans; } now if n is is a matrix all you have to do is replace * by matrix multiplication algorithm --

Re: [algogeeks] matrix Multiplication

2013-01-19 Thread Koup
Just to make sure I understood your code that if means that in case the k is an odd number just multiply the accumulator 1 time with the val and continue with even k.A question I have is if a recursive implementation of this would be any faster? Τη Σάββατο, 19 Ιανουαρίου 2013 1:06:25 μ.μ.

Re: [algogeeks] matrix Multiplication

2013-01-19 Thread Guneesh Paul Singh
both recursive and iterative codes are O(nlogn) algos.. but memory will be more in recursion.. so we will prefer iteration --

Re: [algogeeks] matrix Multiplication

2013-01-19 Thread Dave
@Guneesh: I think you mean to say that the complexity of both the iterative and recursive algorithms is O(n^3 log k), using the notation of the original poster (A is n-by-n, and it is to be raised to the power k). If what you really need is a way to calculate A^k * x, for some vector x, it

Re: [algogeeks] matrix Multiplication

2013-01-19 Thread Dave
@Guneesh: I don't think your code is correct. You want val to take on the values n, n^2, n^4, n^8, ..., whereas in your code, val takes on the values 1,n, n^2, n^3, The algorithm should be more like this: int power() { int ans=1,val=n; while(k) { if(k1)ans=ans*val; k=k1;

Re: [algogeeks] matrix Multiplication

2013-01-19 Thread Guneesh Paul Singh
@dave thanks for correcting :) --