d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Need Help With Tn And On (order Notation) > Offering Fg
Add Reply New Topic New Poll
Member
Posts: 5,988
Joined: May 6 2006
Gold: 30.00
Jun 22 2013 03:07pm
I need this asap, paying 200 fg for it

Basically, I just want to give you a few samples of my code and have you explain what values are added to give both t(n) and O(n)
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jun 22 2013 06:19pm
Post them if you need them ASAP
Member
Posts: 5,988
Joined: May 6 2006
Gold: 30.00
Jun 23 2013 09:04am
Here is one:

Example A:
int variableI = varI();
int variableJ = varJ();
int variable t = varT();
int p = varP();
for (int i = 0; i < variableI; i++ ) {
for (int j = 0; j < variableJ; j++) {
for (int t = 0; t < variableT; t++) {
p = a[i][j] + a [t+1][j] * a[t][j];
System.out.println(p);
} } }
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jun 23 2013 09:14am
a for loop that iterates x times is O(x). if you nest loops, you multiply. so you have O(variableI * variableJ * variableT)
Member
Posts: 5,988
Joined: May 6 2006
Gold: 30.00
Jun 23 2013 09:55am
Hmm, now if I run a method that tracks how much time it takes , i get roughly 10 milliseconds, then when I double the size of the matrix it turns out to be ~42 milliseconds. How do i find this correlation using O(n) if it is O(n^3)??

This post was edited by oOn on Jun 23 2013 09:56am
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jun 23 2013 10:02am
Quote (oOn @ Jun 23 2013 11:55am)
Hmm, now if I run a method that tracks how much time it takes , i get roughly 10 milliseconds, then when I double the size of the matrix it turns out to be ~42 milliseconds. How do i find this correlation using O(n) if it is O(n^3)??


is this a different problem? the one you listed isn't O(n^3), it's O(variableI * variableJ * variableT). plus you mention doubling the size of a matrix. the one you listed is 3 dimensional, but matrixes are only 2 dimensional n x m. and when you say double the size of the matrix, are you really just doubling it (eg: double one side) or are you quadrupling it (doubling both sides)?

if this is the same problem, which variables are you doubling, variableI, variableJ, and/or variableT?

This post was edited by carteblanche on Jun 23 2013 10:03am
Member
Posts: 5,988
Joined: May 6 2006
Gold: 30.00
Jun 23 2013 10:17am
Oh I misunderstood, i thought by variableI * variableJ * variableT you meant it is N * N * N thus order n^3, so i guess its different?

So it is doubling the size of a 2 dimensional matrix (rows and cols), but I am doubling all three variables (variableI, variableJ , and variableT)

I know that 3 variable thing might be confusing, kinda hard to explain, but it is just a 2d matrix that is essentially being doubled.

How do i apply the order N to find the correlation in milliseconds?

edit: if you have skype i can kinda show you the code and ill explain what its doing exactly (i dont want to post it here) and you can help point out details in how it all works (ill offer you fg in return)

This post was edited by oOn on Jun 23 2013 10:20am
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jun 23 2013 10:33am
Quote (oOn @ Jun 23 2013 12:17pm)
Oh I misunderstood, i thought by variableI * variableJ * variableT you meant it is N * N * N thus order n^3, so i guess its different?

Why would you think that? you have three separate variables, not a single one. it's like saying 5 * 12 * 44 is the same as 5^3

"n" is a generic variable in math (and cs) that represents the size of a problem. your size depends on three variables. you can call them whatever you want (n1, n2, n3 or variableI, variableJ, variableT, etc)

Quote
So it is doubling the size of a 2 dimensional matrix (rows and cols), but I am doubling all three variables (variableI, variableJ , and variableT)
I know that 3 variable thing might be confusing, kinda hard to explain, but it is just a 2d matrix that is essentially being doubled.

there's nothing confusing about 3 variables. i think you're not doubling the size of a matrix, i think you're quadrupling it. consider a matrix with r rows and c columns. this has r * c entries. if you double the rows and double the columns, then you have 2r * 2c entries, which is 4 * r * c entries which is 4 times as large.

Quote
int variableI = varI();
int variableJ = varJ();
int variable t = varT();
int p = varP();
for (int i = 0; i < variableI; i++ ) {
for (int j = 0; j < variableJ; j++) {
for (int t = 0; t < variableT; t++) {

p = a[i][j] + a [t+1][j] * a[t][j];
System.out.println(p);
} } }


i assume the bolded lines are the only ones you care about, and everything else is irrelevant. post what values of variableI, variableJ, and variableT are before and after doubling.

i have no idea what varI(), varJ(), varT(), and varP() do. make sure your timings dont include them. your p calculation should also be irrelevant.

also, dont base these correlations on just two data points of a single trial. run each tuple 10-20 times, and use different tuples.
eg: instead of just [variableI, variableJ, variableT] = [1, 1, 1] you should also try [2, 2, 2], [4, 2, 2] [2, 8, 2], etc and do 10-20 trials of each

This post was edited by carteblanche on Jun 23 2013 10:36am
Member
Posts: 5,988
Joined: May 6 2006
Gold: 30.00
Jun 24 2013 12:09pm
Quote (carteblanche @ Jun 23 2013 04:33pm)
Why would you think that? you have three separate variables, not a single one. it's like saying 5 * 12 * 44 is the same as 5^3

"n" is a generic variable in math (and cs) that represents the size of a problem. your size depends on three variables. you can call them whatever you want (n1, n2, n3 or variableI, variableJ, variableT, etc)


there's nothing confusing about 3 variables. i think you're not doubling the size of a matrix, i think you're quadrupling it. consider a matrix with r rows and c columns. this has r * c entries. if you double the rows and double the columns, then you have 2r * 2c entries, which is 4 * r * c entries which is 4 times as large.



i assume the bolded lines are the only ones you care about, and everything else is irrelevant. post what values of variableI, variableJ, and variableT are before and after doubling.

i have no idea what varI(), varJ(), varT(), and varP() do. make sure your timings dont include them. your p calculation should also be irrelevant.

also, dont base these correlations on just two data points of a single trial. run each tuple 10-20 times, and use different tuples.
eg: instead of just [variableI, variableJ, variableT] = [1, 1, 1] you should also try [2, 2, 2], [4, 2, 2] [2, 8, 2], etc and do 10-20 trials of each


I'm pretty new to this all, but thanks, you are making things a little more clear..i just need to read up a good tutorial on this -.-. and yeah i averaged 1000 trials, and got 4n . well the actual method is to multiply two matrices (takes 2x 2d matrix and combine them using matrix multiplication), the real code i have is a little different but still uses 3 for loops (except variableI is rows, variableJ is columns, and variableT changes the algorithm so it corresponds with matrix multiplication). s what you said makes sense, it is 4 * r * c , but with order notation i thought that the constant doesnt matter, so is it just O(n)?

This post was edited by oOn on Jun 24 2013 12:10pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Jun 25 2013 04:47pm
Quote (oOn @ Jun 24 2013 02:09pm)
(except variableI is rows, variableJ is columns, and variableT changes the algorithm so it corresponds with matrix multiplication).

if variableT is just a selector control, then why is it in a loop? if it's separate from the logic, then it looks like quadrupling the size of the matrix will quadruple the time, which is what you observed. so what's the problem?

Quote

what you said makes sense, it is 4 * r * c , but with order notation i thought that the constant doesnt matter, so is it just O(n)?


you're looking at two separate things. assuming variableT is not supposed to be part of the logic, your big Oh is O(variableI * variableJ). if you're looking at roughly how long it'll take, the time changes by a factor of variableI * variableJ. so if you quadruple this, then your time is quadrupled.
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll