|
Its an idea for mining out patterns that is evident in football data.
|
|
|
|
|
How do I solve the recurrence T(n) = T (n - 1) + c substitution method?
|
|
|
|
|
Looks like a partial definition of a linear suite.
What do you want to solve ?
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
I have thought of an algorithm that would really aide the work I am doing but cannot think of a name for it to search if there is an online algorithm created for it that I could use.
Algorithm example + explanation: For the work I am doing I have lots of different amounts of money and a total figure. I know that the sum of some of these amounts will equal the total figure but I have no clue which amounts they are and am not too sure how many of these figures would reach the total. I would input the amounts of money and the total figure and the algorithm would have to evaluate every single combination of these amounts of money until it reached the total amount and would output which amounts of money were used to create that total.
I am not asking anyone to create this algorithm I am just asking whether there is a website with this algorithm on it that I could use or if this algorithm is really easy to create + therefore I could create it for myself.
Any comments would be helpful + please ask if you have any queries for clarity! Many thanks!
|
|
|
|
|
this is the "coin change problem".
but, it's not an exceptionally hard problem. and it's probably worth trying to think it through on your own.
|
|
|
|
|
You have a set of data, and you search which subset will match a criteria.
This is a classical problem, I am not sure there is a name to this problem, or as mentioned in previous answer, it is related to the coin change problem.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
Hi.
I was recently interested in literature regarding what a good hash table load factor is for rehashing. Wikipedia mentions 0,7, 0,75 and 2/3, but with no explanation as to why performance degrades at these numbers.
The problem intrigued me, and I came to the conclusion that, mathematically speaking, the load factor threshold is at exactly log 2 (~0,7), which I found rather beautiful in it's own way.
I am posting this in case somebody else finds it interesting as I could not find any reference to a similar solution. Please also reply if you find any errors.
---------------------------------------
Chaining can be avoided and branch prediction exploited by predicting if a bucket is empty or not. A bucket is probably empty if the probability of it being empty exceeds 0,5.
Let s represent the size and n the number of keys added. Using the binomial theorem, the probability of a bucket being empty is:
P(0) = C(n, 0) * (1/s)^0 * (1 - 1/s)^(n - 0).
Thus, a bucket is probably empty if there are less than
log(2)/log(s/(s - 1)) keys.
As s reaches infinity and if the number of keys added is such that P(0) = 0,5, then n/s approaches log(2) rapidly:
lim (log(2)/log(s/(s - 1)))/s as s -> infinity = log(2) ~ 0,7.
|
|
|
|
|
|
Split the larger triangle into two right-angled triangles, and apply Pythagoras:
<br />
L1² = x² + y²<br />
L2² = (X1 - x)² + y² = X1² - 2·X1·x + x² + y²<br />
<br />
L2² - L1² = X1² - 2·X1·x<br />
2·X1·x = X1² - L2² + L1²<br />
<br />
x = (X1² - L2² + L1²) / 2·X1<br />
<br />
y = ± √(L1² - x²)<br />
NB: there will be two solutions - one with a positive value for y , and one with a negative value.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Use Pythagoras.
Let Pen tip = P. We know L1, L2, X1.
Define line segments R1 -> P = L1, R1 -> x = A, (x,0) -> P = B.
A2 + B2 = L12
We know the length of A is X, since it's (0,0) -> (x,0), and we know length of B is y, since it's (x,0) to (x,y)
x2 + y2 = L12
Let R2 -> P = L2, x -> R2 = C
B2 + C2 = L22
A + C = X1 => C = X1 - A
So we have
x2 + y2 = L12
y2 + (X1 - x)2 = L22
Solve these and you get x and y
cheers
Chris Maunder
|
|
|
|
|
Im inputing three numbers of users choice
number 1
number 2
final number
what i want to find out is , how many combinations of number 1 and number 2 would result in final number = number1 *x + number2*y = final number.
I am using nested loops
int i;
int j;
long long int pocet=0;
long long int one;
long long int two;
long long int last;
long long int one_max;
long long int two_max;
long long int add=1;
long long int reduc=1;
if((one%2==0) && (two%2==0)){
if(one>two){
add=two/2;
reduc=one/2;
}
}
one_max=last/one;
two_max=last/two;
for(i=0;i<=one_max;i+=add){
for(j=two_max;j>=0;j-=reduc){
long long int tmp_one=(one*i);
long long int tmp_two=(two*j);
if(tmp_one+tmp_two==last){
two_max=j;
pocet++;
}
}
}
if i input these numbers
one = 10;
two = 13;
final =100;
the only possible combination of first two numbers to result in final number is
10 * 10 + 13 * 0
modified 7-Nov-15 11:37am.
|
|
|
|
|
First of all, I fear your code don't work or is not complete.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
this is not full code , its just half pseudo code for illustrating my problem , i can provide full code if it helps
|
|
|
|
|
If it's pseudo code, ho wdo you know it runs slow?
|
|
|
|
|
i have updated my question , i wrote actual code which does works slow
|
|
|
|
|
You should consider this
long long int MyFunc (long long int one, long long int two, long long int last) {
int i;
int j;
long long int pocet=0; long long int one_max;
long long int two_max;
long long int add=1; long long int reduc=1;
if((one%2==0) && (two%2==0)){
if(one>two){
add=two/2;
reduc=one/2;
}
}
one_max=last/one;
two_max=last/two;
for(i=0;i<=one_max;i+=add){
for(j=two_max;j>=0;j-=reduc){
long long int tmp_one=(one*i);
long long int tmp_two=(two*j);
if(tmp_one+tmp_two==last){
two_max=j;
pocet++;
}
}
}
return pocet;
}
as the source code to provide. Because we can't use your source code as is. In the form of a function, we can do test without changing a single line in this code.
First remark: using int for i and j may be short and should be replaced with long long int to match other variables.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
Here is code with first batch of changes. the code is changed to a function for practical reasons.
long long int MyFunc (long long int one, long long int two, long long int last) {
long long int i;
long long int j;
long long int pocet=0;
for(i=0;i*one <=last;i++){
if ((last - one*i )% two == 0) { j= (last - one*i) / two;
pocet++;
}
}
return pocet;
}
I just stick to the problem here.
I just take advantage of mathematics to change the equation as i is known. This should already improve the runtime.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
thanks for reply , i have also improved my code , but both , my and yours fail to be fast and calculate the number of combinatiosn when big numbers such as
5098109
25279297
36821491225502191
are inputed
|
|
|
|
|
If you compare speed of both solutions with smaller values, mine should consistently faster the yours.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
yes no doubt about that , but both takes very long time to calculate numbers with big values such as i posted earlier
|
|
|
|
|
To go further, change the code to print each solution in order and look at changes between solutions.
Try 3, 4, 150
Try 3, 4, 151
Try 3, 4, 153
And look at each set of answer, you should see a repeating patern. This what Harold is speaking about in http://www.codeproject.com/Messages/5156686/Re-Fastest-way-to-count-nested-loops.aspx[^]
And when you have a repeating pattern, you can know very fast the number of solutions without loop at all.
Patrice
“Everything should be made as simple as possible, but no simpler.” Albert Einstein
|
|
|
|
|
That looks like Bézout's identity[^], the result depends on what algebraic structure you want to use, which is a bit unclear here. What size of integer do you want to consider?
You can see there what form the pairs of (i,j) take if they are solutions (called (x,y) on the wiki page). x increments in steps of b/gcd(a,b) and y decrements in steps of a/gcd(a,b). k can also go negative though. The problem then is counting how many of those things are in the valid range of your integer type. It has some weird edge cases but obviously you can do it without counting every possibility explicitly.
|
|
|
|
|
You don't need any code to solve this!
When (x,y) is a solution to number1 *x + number2*y = final number ,
then so is (x+k*number2, y-k*number1) whatever the value of k.
So the number of solutions is either zero or infinite, depending on the given values.
Then, if you want to limit the solution to some range of values, you can easily figure which values of k are acceptable once you have a first solution (x,y).
|
|
|
|
|
hello everyone... first of all im reading a book about algorithms analysis and im in the topic called counting the primitive operation of an algorithm
and the algorithm is finding the largest element in an array ....
and it comes up to this formula:
the best case is :
2 + 1 + n + 4(n - 1) + 1 = 5n
and the worst case is
2 + 1 + n + 6(n - 1) + 1 = 7n - 2
my question is how does he come up to those answet ? sorry guys im not very good at math.. and im still working on my algebra skills
thanks guys for the help
this.is.the psuecode.that.have been used for the example.in the book
Algorithm arrayMax(A, n):
Currentmax = A[0]
for (i = 1; i < n - 1; i++) do:
If CurrentMax < A[i] do:
CurrentMax = A[i]
return CurrentMax
|
|
|
|
|
Basic algebra:
Member 11897566 wrote: 2 + 1 + n + 4(n - 1) + 1 = 5n
2 + 1 + n + 4(n - 1) + 1
== 2 + 1 + 1 + n + 4(n - 1)
== 4 + n + 4n - 4
== 4 - 4 + 5n
== 5n
Member 11897566 wrote: 2 + 1 + n + 6(n - 1) + 1 = 7n - 2
2 + 1 + n + 6(n - 1) + 1
== 2 + 1 + 1 + n + 6(n - 1)
== 4 + n + 6n - 6
== 4 - 6 + 7n
== -2 + 7n
== 7n - 2
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|