complexity-theory

Kolmogorov Complexity Approximation Algorithm

為{幸葍}努か 提交于 2019-12-04 17:54:58
问题 I'm looking for a algorithm that can compute an approximation of the Kolmogorov complexity of given input string. So if K is the Kolmogorov complexity of a string S, and t represents time, then the function would behave something like this.. limit(t->inf)[K_approx(t,S)] = K. 回答1: In theory, a program could converge on the Kolmogorov complexity of its input string as the running time approaches infinity. It could work by running every possible program in parallel that is the length of the

How fast is operation on KeyCollection returned by Dictionary.Keys ? (.NET)

偶尔善良 提交于 2019-12-04 17:14:13
IDictionary<TK, TV> defines method IDictionary.ContainsKey(in TK) and property IDictionary.Keys (of type ICollection ). I'm interested in (asymptotic) complexity of this method and property in Dictionary implementation of IDictionary<TK, TV> . Consider definitions IDictionary<int, string> dict = new Dictionary<int, string>(); int k = new Random().Next(); and consider that we have added to the dictionary dict n unique KeyValuePair s. What is expected (asymptotic) complexity of a call dict.ContainsKey(k) ? I hope it's in O(1) but I did not find it in documentation of Dictionary.ContainsKey .

Merge sort worst case running time for lexicographic sorting?

旧巷老猫 提交于 2019-12-04 17:04:35
A list of n strings each of length n is sorted into lexicographic order using the merge sort algorithm. The worst case running time of this computation is? I got this question as a homework. I know merge sort sorts in O(nlogn) time. For lexicographic order for length in is it n times nlogn ? or n^2 ? amit Each comparison of the algorithm is O(n) [comparing two strings is O(n) worst case - you might detect which is "bigger" only on the last character], You have O(nlogn) comparisons in mergesort. Thus you get O(nlogn * n) = O(n^2 * logn) But according to the recurrence relation T(n) = 2T(n/2) +

why O(2n^2) and O(100 n^2) same as O(n^2) in algorithm complexity?

北战南征 提交于 2019-12-04 16:48:06
I am new in the algorithm analysis domain. I read here in the Stack Overflow question " What is a plain English explanation of "Big O" notation? " that O(2n^2) and O(100 n^2) are the same as O(n^2) . I don't understand this, because if we take n = 4, the number of operations will be: O(2 n^2) = 32 operations O(100 n^2) = 1600 operations O(n^2) = 16 operations Can any one can explain why we are supposed to treat these different operation counts as equivalent? Why this is true can be derived directly from the formal definition . More specifically, f(x) = O(g(n)) if and only if |f(x)| <= M|g(x)|

Possible Combination of Knapsack problem and?

瘦欲@ 提交于 2019-12-04 16:19:44
Alright quick overview I have looked into the knapsack problem http://en.wikipedia.org/wiki/Knapsack_problem and i know it is what i need for my project, but the complicated part of my project would be that i need multiple sacks inside a main sack. The large knapsack that holds all the "bags" can only carry x amount of "bags" (lets say 9 for sake of example). Each bag has different values; Weight Cost Size Capacity and so on, all of those values are integer numbers. Lets assume from 0-100. The inner bag will also be assigned a type, and there can only be one of that type within the outer bag,

Time complexity for Search and Insert operation in sorted and unsorted arrays that includes duplicate values

本小妞迷上赌 提交于 2019-12-04 16:19:06
1-)For sorted array I have used Binary Search. We know that the worst case complexity for SEARCH operation in sorted array is O(lg N), if we use Binary Search, where N are the number of items in an array. What is the worst case complexity for the search operation in the array that includes duplicate values, using binary search?? Will it be the be the same O(lg N)?? Please correct me if I am wrong!! Also what is the worst case for INSERT operation in sorted array using binary search?? My guess is O(N).... is that right?? 2-) For unsorted array I have used Linear search. Now we have an unsorted

Data structure for O(log N) find and update, considering small L1 cache

我是研究僧i 提交于 2019-12-04 15:52:08
问题 I'm currently working on an embedded device project where I'm running into performance problems. Profiling has located an O(N) operation that I'd like to eliminate. I basically have two arrays int A[N] and short B[N] . Entries in A are unique and ordered by external constraints. The most common operation is to check if a particular value a appears in A[] . Less frequently, but still common is a change to an element of A[] . The new value is unrelated to the previous value. Since the most

Complexity of edit distance (Levenshtein distance) recursion top down implementation

霸气de小男生 提交于 2019-12-04 15:01:27
I have been working all day with a problem which I can't seem to get a handle on. The task is to show that a recursive implementation of edit distance has the time complexity Ω(2 max(n,m) ) where n & m are the length of the words being measured. The implementation is comparable to this small python example def lev(a, b): if("" == a): return len(b) # returns if a is an empty string if("" == b): return len(a) # returns if b is an empty string return min(lev(a[:-1], b[:-1])+(a[-1] != b[-1]), lev(a[:-1], b)+1, lev(a, b[:-1])+1) From: http://www.clear.rice.edu/comp130/12spring/editdist/ I have

Time complexity of this for loop: for (i = 2; i < N; i = i * i)?

ε祈祈猫儿з 提交于 2019-12-04 14:46:22
We're learning about time complexity right now and I'm having a ton of trouble with this one example. for (i = 2; i < n; i = i * i) { ... do something ... } The prof said that it was O(sqrt(N)), but I'm not sure that I'm convinced. After all, if N=16, it only runs 2 times, not 4 right? My approach to solution: 2^(2k) = N, where k is the number of times the loop runs. Removing the constant factors, k runs log(N) times. Where am I going wrong here? Thanks for any advice on the matter. You are correct that your instructor is wrong (at least, their bound isn't tight), and I like the analysis you

Cyclomatic Complexity in piece of code with multiple exit points

非 Y 不嫁゛ 提交于 2019-12-04 14:04:49
问题 I have this method that validates a password: /** * Checks if the given password is valid. * * @param password The password to validate. * @return {@code true} if the password is valid, {@code false} otherwise. */ public static boolean validatePassword(String password) { int len = password.length(); if (len < 8 || len > 20) return false; boolean hasLetters = false; boolean hasDigits = false; for (int i=0; i<len; i++) { if (!Character.isLetterOrDigit(password.charAt(i))) return false;