It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Anyone know how to implement binomial coefficient calculation in parallel ?
Any resource for multi-core or CUDA would be helpful, thank you.
I would start off by doing the following.
Create an array of size (n + 1) and fill it with 1, 1, 2, 3, .... n.
Perform an inclusive scan on this array with a product operation. At
this point you will have array[n] = n!. i.e. array[0] = 0!, array1
= 1! array[100] = 100! and so on.
Now that you have every factorial from 0! to n!, you can perform (n! / p! * (n - p)!) very easily.
The first and the last operations may need custom kernels. The second operation can be done using thrust and the inclusive_scan operation.
EDIT
As for the drawbacks, as mentioned above in the comments, there will be precison issues even with 64 bit integers at reasonable large size of n. But this is the basic algorithm that you would need to use.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
Is there way to write down a list of comparisons of Merge-Sort recursive alghoritm (on a given input) without run it?
I will have an exam where there will be asked something like that, and I couldn't do it on computer.
For example on that input A = { 2, 3, 1, 4, 5, 0, 4, 2, 7, 8 }
You can use this Demo : MergeSort demo with comparison bounds
This page demonstrates MergeSort. At the same time, it shows the number of comparisons actually used, and a worst case upper bound on this number.
You can watch people dancing the Merge Sort algorithm
http://www.youtube.com/watch?v=XaqR3G_NVoo
Have fun
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
Given n coins, some of which are heavier, algorithm for finding the number of heavy coins using O(log^2 n) weighings. Note that all heavy coins have the same weight and all the light ones share the same weight too.
You are given a balance using which you can compare the weights of two disjoint subsets of coins. Note that the balance only indicates which subset is heavier, or whether they have equal weights, and not the absolute weights.
I won't give away the whole answer, but I'll help you break it down.
Find a O(log(n)) algorithm to find a single heavy coin.
Find a O(log(n)) algorithm to split a set into two sets with equal number of heavy and light counts plus up to two leftovers (for when there are not even amounts of each).
Combine algorithms #1 and #2.
Hints:
Algorithm #1 is independent of algorithm #2.
O(log(n)) hints at binary search
How might you end up with O(log^2(n)) with two O(log(n)) algorithms?
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Assuming that N is very large, can anybody help me in ordering the following list for Big O running times from Slowest to Fastest.
O(N^2)
O(N)
O(1)
O(N!)
O(2^N)
O(N log N)
O(N^3)
O(log N)
Divide O(A/B) to see if O(A) is asymptotically larger than O(B). (Take the limit as n->infinity. For example N^2/N = N, which blows up to infinity, so N^2>N asymptotically. Alternately, N/N^2 = 1/N which approaches 0, so N
Then you can graph them to check your work and get intuition (though graphs like this can easily "lie" if you graph them too close to the origin, and/or there are smaller hidden terms).
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
How will you compute x/y in O(log(n)) time.
n=x/y, x & y are integers
You can't use the / operator.
One implementation is to add y q times till the result is less than x i.e.
y * q < x
What about 10**(log(x) - log(y))
Big O() notation only applies to how a problem scales with different number of inputs.
The question doesn't make sense unless you mean 'n' is the number of digits in x and y
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to write fastest possible algorithm for 2 number multiplications.
Each number has max digits around 1000000 and is contained in string.
Anyone want to tell about this problem? I searching really speed solution.
You should convert your string to a binary representation of the number. After that, one of the fastest multiplication algorithms I know of is Karatsuba's.
Just to expand on Pablo's answer, suppose each number is a string 1000008 decimal digits long. You could convert that to be 111112 9-digit decimal numbers, each stored in a UInt32. Do your multiplication algorithm on those. (Note you will have to use UInt64 to hold the result of multiplying two UInt32 sections, so you may want a 64-bit machine.) That should give you a factor of 9^2 or 9^log2(3) speedup over base 10, depending on the algorithm.