complexity-theory

GCD algorithms for a large integers

跟風遠走 提交于 2019-12-04 13:56:05
I looking for the information about fast GCD computation algorithms. Especially, I would like to take a look at the realizations of that. The most interesting for me: - Lehmer GCD algorithm, - Accelerated GCD algorithm, - k-ary algorithm, - Knuth-Schonhage with FFT. I have completely NO information about the accelerated GCD algorithm, I just have seen a few articles where it was mentioned as the most effective and fast gcd computation method on the medium inputs (~1000 bits) They looks much difficult for me to understand from the theory view. Could anybody please share the code (preferable on

Associating nearby points with a path

懵懂的女人 提交于 2019-12-04 13:14:18
Given a set of ordered points, and a path made up of ordered lat,lon points that goes near those points (in lat/lon coordinates), I want to associate the points with the path, ideally with good algorithmic complexity (n*log(n)) or better, but maybe that might not be realistic. The below diagram illustrates my question better. The blue line is the ordered path that is provided, and the red points are in the same order as the blue line. The green path is my desired result, which merges the red points and the blue line into a new ordered path. Some threshold would have to be set for the distance

3D Connected Points Labeling based on Euclidean distances

别来无恙 提交于 2019-12-04 12:29:21
Currently, I am working on a project that is trying to group 3d points from a dataset by specifying connectivity as a minimum euclidean distance. My algorithm right now is simply a 3d adaptation of the naive flood fill. size_t PointSegmenter::growRegion(size_t & seed, size_t segNumber) { size_t numPointsLabeled = 0; //alias for points to avoid retyping vector<Point3d> & points = _img.points; deque<size_t> ptQueue; ptQueue.push_back(seed); points[seed].setLabel(segNumber); while (!ptQueue.empty()) { size_t currentIdx = ptQueue.front(); ptQueue.pop_front(); points[currentIdx].setLabel(segNumber)

Prove that n! = O(n^n)

杀马特。学长 韩版系。学妹 提交于 2019-12-04 11:08:32
How can I prove that n! = O(n^n)? I assume that you want to prove that the function n! is an element of the set O(n^n) . This can be proven quite easily: Definition: A function f(n) is element of the set O(g(n)) if there exists a c>0 such that there exists a m such that for all k>m we have that f(k)<=c*g(k) . So, we have to compare n! against n^n . Let's write them one under another: n! = n * (n-1) * (n-2) * (n-3) * ... * 3 * 2 * 1 n^n = n * n * n * n * ... * n * n * n As you can see, the first line ( n! ) and the second line ( n^n ) have both exactly n items on the right side. If we compare

what is the difference between O(nk) and O(n+k) in time complexity?

谁都会走 提交于 2019-12-04 09:59:55
In big O notation of time complexity in algorithmic analysis, when an algorithm depends on n and k, what is the difference between these two notations. Also pls help in the notation to use if there is a nested loop with outer loop running n times and inner loop running k times ? O(nk): for( i=0; i<n; i++ ) { for( j=0; j<k; j++ ) {} } O(n+k): for( i=0; i<n; i++ ) {} for( j=0; j<k; j++ ) {} O(n+k) indicates a linear growth rate in the larger of n or k . Suppose n is greater. Then n + k <= n + n = 2n = O(n) If n is smaller, though, then n + k <= k + k = 2k = O(k). Whether or not n is the larger,

Time-complexity of recursive algorithm for calculating binomial coefficient

橙三吉。 提交于 2019-12-04 09:47:14
I'm studying about algorithm complexity analysis. I have problem with unconformity or C(n, k) . int C(int n, int k){ if(n==k || k==0) return 1; return C(n-1, k) + C(n-1, k-1); } How can I determine its execution complexity or T(n) ? The recurrence you are looking for is T(n,k) = T(n-1,k) + T(n-1,k-1) + O(1) with T(n,n) = T(n,0) = O(1) Obviously n is decreased by one every step. If we ignore (just for the moment) that there is a parameter k, basically the number of calls doubles every step. This happens n times, until n = 1. Now C(1,k) returns 1. So you call C(n,k) at most 2 n times. So C(n,k)

In C++, is the amortized complexity of std::string::push_back() O(1)?

痞子三分冷 提交于 2019-12-04 08:40:22
I know the standard specifies that it is for vectors, but what about strings? Yes, it is amortized constant time. See table 101 on page 716 of this document : Table 101 lists operations that are provided for some types of sequence containers but not others. An implementation shall provide these operations for all container types shown in the “container” column, and shall implement them so as to take amortized constant time. Operation | Description | Container ---------------+----------------------+---------------------------------- a.push_back(t) | Appends a copy of t. | basic_string, deque,

search for multiple strings

天涯浪子 提交于 2019-12-04 08:36:22
I know of efficient ways to look for one string in a file (kmp), or various strings in a file (trie) But, for years now, I've been wondering if there is a way (and ocasionally thinking it impossible) to search multiple files for multiple strings Say I have a million files, and I want to answer queries like "find files that have the strings "banana", "motorboat" and "the white fox"". What would be an efficient algorithm ? Is there one ? Of course, it is possible to do such a search in linear time on the size of the files to search. But that seems very infeasible for a big amount of big files.

Is O(log n) always faster than O(n)

痞子三分冷 提交于 2019-12-04 08:05:45
问题 If there are 2 algorthims that calculate the same result with different complexities, will O(log n) always be faster? If so please explain. BTW this is not an assignment question. 回答1: No. If one algorithm runs in N/100 and the other one in (log N)*100 , then the second one will be slower for smaller input sizes. Asymptotic complexities are about the behavior of the running time as the input sizes go to infinity. 回答2: No, it will not always be faster. BUT, as the problem size grows larger and

Calculate the maximum distance between vectors in an array

房东的猫 提交于 2019-12-04 07:48:26
Assume we have an array that holds n vectors. We want to calculate the maximum euclidean distance between those vectors. The easiest (naive?) approach would be to iterate the array and for each vector calculate its distance with the all subsequent vectors and then find the maximum. This algorithm, however, would grow (n-1)! with respect to the size of the array. Is there any other more efficient approach to this problem? Thanks. Your computation of the naive algorithm's complexity is wonky, it should be O(n(n-1)/2) , which reduces to O(n^2) . Computing the distance between two vectors is O(k)