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.
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.
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.
A sampling algorithm could output any real number in range [0,1],but the correct answer is in the range [0.1,0.2+x]("x" is in range [0,1]), the algorithm can output a correct answer with probability more than "0.8", then how to give a good answer with high probability? (such as run it many times, and pick the median as the right answer)
I think the question may be asking about the central limit theorem. If the samplings are independent and identically distributed, the OP could apply the classical form: Classical CLT
Otherwise, I recommend viewing the rest of the Wikepedia article to see if any of the other forms are applicable.
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.
If we have an algorithm which is order N^2*logN, and if it takes 1 ms with input size 64; does it take 2^10*(11/6) ms to run this algorithm with input size 2048? I am using direct proportion here, that's why it seemed defective to me.
Easiest way to solve is probably to divide 2048 by 64, plug the resulting number into the complexity equation, and the result is the number of milliseconds for Input size 2048.
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.
There are several colors of balls. For one specific color, there are more than half of the balls with this color(>n/2). How can I find this color taking only O(n) running time?
You can use Boyer-Moore majority algorithm
Find the color of each ball and tally it up. This doesn't seem to be a sorting at all if you only want to find the most frequent. Just count the number of balls with each color. You could use a hashtable, key is the color and just iterate the spot. Also keep track of the colors.
Edit:
After reading this again, I realized that it did not answer the question.
A) You could just do the tracking at the end by iterating through every available color (assuming you were making that list of colors), as there will be less than n comparisons, it will in the worse case be O(n).
B) While you are tallying the ball count up, keep track of the largest count. Whenever that gets beat, replace it with the current color with the highest count. You probably want to keep track of the color along with the highest number. This way you will do it on a comparison on every run. This again will be O(n) but will have more comparisons.
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.