|
sounds like a programming question!
Is this a homework?
(..I don't think i am in The Lounge anymore...")
Anyway, Are there negatives values in that array?
-- modified at 6:10 Wednesday 11th October, 2006
|
|
|
|
|
That's what pop into my mind:
<br />
sumx(A[],x)<br />
{<br />
Array S[x/2];<br />
for(i=0,i<S.lenght;i++) S[i]=0;
for(i=0,i<A.lenght;i++)<br />
{ <br />
a=A[i];<br />
if(a<0 || a>x/2) continue;<br />
if(a<x/2) S[a] |= 1;<br />
if(a>x/2) S[x-a] |= 2;<br />
}<br />
return S;<br />
}<br />
You get an array S.
For a number k<(x/2) you have:
if S[k] is 0 then neither number k, nor (x-k) is in the input array.
if S[k] is 1 then only number k was in the input array.
if S[k] is 2 then only number (x-k) was in the input array.
if S[k] is 3 then k and (x-k) was in the input array. The sum of those two is k+(x-k)=k+x-k=x. bingo!
For a number j>(x/2) you have k=(x-j) and continue as above.
The array S can be more comlex, like storing the index of two number in the input array A, if you like. Dealling with negative numbers as well might need a more complex aproach.
|
|
|
|
|
Small bug:
Kastellanos Nikos wrote: if(a<0 || a>x/2) continue;
if(a<0 || a>x) continue;
To put the algorithm in simple words, do a counting sort for numbers <x , so O(n).
lookup is O(1) for a hash table; will have to do x/2 lookups, so O(x).
Overall O(x+n).
The complexity of algorithm is O(x+n); If x is reasonably small, then the algorithm is good enough.
If x>n*log n; a quick sort followed by a binary search is better, but will be managable only in O(n*log n)
|
|
|
|
|
i have written a code to find the determinant of a matrix, i would like to ask is it fishy or can it be devoloped? thanks to you all for replies... my code is written in vb.. and one more thing... i wonder is it the right place to post? thanks anyway...
here is my code...
Sub deneme()
Dim a(1 To 10, 1 To 10) As Double
Dim t As Integer
a1 = 1
t = 0
GoTo git
For i = 1 To 3
For j = 1 To 3
t = t + 1
a(i, j) = t
Next j
Next i
git:
a(1, 1) = -1
a(1, 2) = 0
a(1, 3) = -50
a(2, 1) = 1
a(2, 2) = 4.92
a(2, 3) = -2
a(3, 1) = -1.4
a(3, 2) = 3
a(3, 3) = 1
For i = 1 To 3
For j = 1 To 3
If i = j Then
If a(i, i) = 0 Then GoTo devam
For g = i + 1 To 3
tut = a(g, i)
For b = 1 To 3
a(g, b) = a(g, b) - (a(i, b) * (tut / a(i, i)))
Next b
Next g
End If
Next j
Next i
devam:
For i = 1 To 3
For j = 1 To 3
Cells(i, j) = a(i, j)
Next j
Next i
For i = 1 To 3
a1 = a1 * a(i, i)
Next i
Cells(1, 10) = a1
End Sub
|
|
|
|
|
Well I don't know what your formula does, but why not use the Laplace Expansion?
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
first of all thanks for replying... i've examined the laplace expansion. But in high order matrices finding the minor matrices or the cofactors is hard to code for me and i think, i can turn the square matrice to the triangle square matrice. so i just multiply the a[j,j] s then i find the determinant of it.. by the way.. my code is just turn the square matrice to a triangle square matrice. thanks for comments...
|
|
|
|
|
Hi,
I do not know if your code works or not, but if I were you I would use the definition of determinant to compute it.
The hardest part is to code a function to get permutations.
Regards
|
|
|
|
|
thanks for replying my message. my code is working for me for all inputs and it works only square matrices you know... and yeah you are very right... and by the way if you want to try it you can use excel microsoft vb.. thanks for advance...
|
|
|
|
|
But ... determinants are only defined for a square matrix... isn't then the range what you want to compute ?
Regards
|
|
|
|
|
sure i am... i need only square matrices... n unkowns n linear equations. best regards....
|
|
|
|
|
Hey all,
I'm not sure this is the right forum, as I'm not sure what I'm looking for is an algorithm.
I have an IP address along with a port.
My goal is to determine which running application is using this port.
Googling taught me that this process is called Port-To-Application Mapping (aka PAM),
but I couldn't find any code which does that...
The best thing I found was a program which knows how to do it.
Anyone knows any PAM algorithms?
Thanks in advance,
Shy.
|
|
|
|
|
anyone know step by step mathematical processes for image convolution using laplacian? plz explain...
|
|
|
|
|
|
Hi,
If I remember well ...
If your image M is considered as a x*y matrix (ie gray scaled) of pixels and a point P is then described as P(i,j) where 0 <= i < n and 0 <= j < n, and the laplacian is considered as a 3*3 matrix L defined as [[a,b,a],[b,c,b],[a,b,a]], the discrete convolution gives you another n*m matrix R where R(x, y) = Sum(i=0, i < 3, Sum(j=0, j < 3, L(i,j)*P(x + i - 1, y + j -1))) (0 outbounds)
Regards
|
|
|
|
|
anyone can help find out any source code for prediction using bayesian belief network algorithm pls...A.S.A.P
respect,relax,respon
|
|
|
|
|
|
i am looking for bayes network free source code for my preliminary analysis research...
respect,relax,respon
|
|
|
|
|
anyone know about this technique...amswering me pls???
respect,relax,respon
|
|
|
|
|
is there an algorithm(c++/c#) or existing database, which can be used to turn English words from tense or plural form to their original form?
thx~
http://chinajuanbob.spaces.live.com/
|
|
|
|
|
acording to MS, you shouldn't try to do this because while it's (barely) possible to do it for a single language, internationalizing will require writing a set of special rules for every language supported. Instead write your text in a plurality nuetral fashion. Instead of "1 cat, 2 dogs" use "cats: 1, dogs: 2".
|
|
|
|
|
|
You wrote that? That's cool.
|
|
|
|
|
Holy crap. My head hurts. I give you a 5 for being smarter than I.
---
Shawn Poulson
spoulson@explodingcoder.com
|
|
|
|
|
Im having a problem with a A* path finding algorithm I made. Its able to find the path but it will rarely make diagonal moves when it should.
Strart
X
X
X X X End
I think I got the math right, its the algorithm that isnt working right. Iv googled around and found some good articals but most fail to explain how to impliment it. Some come with source code but is too complex and bloated for me to grasp. Im close to giving up on using the internet to help solve my problem.
static int Sqrt(int x) { if (x<0) throw new ArgumentOutOfRangeException(); int temp, y=0, b=0x8000, bshft=15, v=x; do { if (v>=(temp=(y<<1)+b<<bshft--)) {="" y+="b;" v-="temp;" }="" while="" ((b="">>=1)>0); return y;
|
|
|
|
|
Henize wrote: it will rarely make diagonal moves when it should
Are diagonal cells considered as neighbours in your algorithm ? If no, then that is your problem
|
|
|
|