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).
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 9 years ago.
I have this question about why the big O for this equation is n cube ?
else if(key == 'x')
C = matrixMult(A, B);
Thanks very much
The resulting matrix has n^2 entries. The computation of each entry can be done by a sum of n products, yielding n^3.
This is only valid for the textbook algorithm, as there exist faster algorithms, e.g. Strassen's algorithm or the fastest known algorithm.
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.
How can one give Big O, Big Theta or Big Omega for a function like
T(n) = n + 10*log n
Can someone please tell me how I can get the complexity for such a thing?
Drop all lower-order terms and constants and you get:
Θ(T(n)) = Θ(n + 10*log(n)) = Θ(n)
Since this is a tight bound (Θ) we also infer upper and lower bounds as O(n) and Ω(n).
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.
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.
Can anyone suggest me a worst case "text string - pattern pair" for testing a KMP algorithm implementation?
I would say a pattern like
xx........x
| n times |
and a string like
xxx.........xyx...........xy....
| n-1 times | | n-1 times |
would be one of the worst cases, but it's still O(m+n)
You can find anything on KMP algorithm here :
KMP ALGORITHM
Quick extract :
Knuth, Morris and Pratt discovered first linear time string-matching
algorithm by following a tight analysis of the naïve algorithm.
Knuth-Morris-Pratt algorithm keeps the information that naïve approach
wasted gathered during the scan of the text. By avoiding this waste of
information, it achieves a running time of O(n + m), which is optimal
in the worst case sense. That is, in the worst case Knuth-Morris-Pratt
algorithm we have to examine all the characters in the text and
pattern at least once.
You should be able to calrify what you understand of the algorithm and find what you need there.
hope it helps