complexity-theory

String to string correction problem np-completeness proof

﹥>﹥吖頭↗ 提交于 2019-12-23 05:08:19
问题 I have this assignment to prove that this problem: Finite alphabet £, two strings x,y € £*, and a positive integer K. Is there a way to derive the string y from the string x by a sequence of K or fewer operations of single symbol deletion or adjacent symbol interchange? is np-complete. I already figured out I have to make transformation from decision version of set covering problem, but I have no clue how to do this. Any help would be appreciated. 回答1: It looks like modified Levenshtein

Computational complexity for the case of many answers or multiple parameters

淺唱寂寞╮ 提交于 2019-12-23 04:46:12
问题 How is computational complexity defined if the algorithm: ...yields many results? As a total (then an algorithm producing a set of k cannot be faster than O(k) ) or per element (then the estimate must be multiplied to compare it with non-set-producing algorithms)? What about storage complexity - does an estimate reflect if the entire set needs to be present in memory at once or each consecutive element can be produced and discarded? ...has multiple parameters? A separate figure for each

Question about NP-Completeness of the Independent Set Problem

别等时光非礼了梦想. 提交于 2019-12-23 04:29:12
问题 I thought that, when proving that a problem P is NP-Complete, we were supposed to reduce a known NPC problem to P. But, looking at the solution to the Independent Set problem, it seems to not go this way. To prove that Independent Set is NP-Complete, you take a graph G, find its inverse G', and then compute CLIQUE(G'). But, this is doing the other way around: it's taking a problem P I DON'T know if it's NPC and then reduces it to a know NPC problem. Here's an example of the solution. What am

why is Insertion sort best case big O complexity O(n)?

江枫思渺然 提交于 2019-12-22 10:46:07
问题 Following is my insertion sort code: void InsertionSort(vector<int> & ioList) { int n = ioList.size(); for (int i = 1 ; i < n ; ++i) { for (int j = 0 ; j <= i ; ++j) { //Shift elements if needed(insert at correct loc) if (ioList[j] > ioList[i]) { int temp = ioList[j]; ioList[j] = ioList[i]; ioList[i] = temp; } } } } The average complexity of the algorithm is O(n^2). From my understanding of big O notation, this is because we run two loops in this case(outer one n-1 times and inner one 1,2,..

What is the runtime complexity of Python's deepcopy()?

孤人 提交于 2019-12-22 10:42:11
问题 I'm trying to improve the speed of an algorithm and, after looking at which operations are being called, I'm having difficulty pinning down exactly what's slowing things up. I'm wondering if Python's deepcopy() could possibly be the culprit or if I should look a little further into my own code. 回答1: Looking at the code (you can too), it goes through every object in the tree of referenced objects (e.g. dict's keys and values, object member variables, ...) and does two things for them: see if

Can i check if subsequence faster then O(n*n)

夙愿已清 提交于 2019-12-22 10:29:23
问题 So my question is in topic's name. Does exists an algorithm that checks if B is subsequence of A faster, than O(N^2), for example O(NlogN) or simply O(N)? Only way found is simple brut-force for(int i = 0; i < a.Length - b.Length; i++) { if (IsSubsequence(a,b,i)) return i; } return -1; 回答1: Here's a recursive characterization of David Eisenstat's algorithm. (Note that this algorithm is tail recursive and can therefore be written as a loop; I describe it as recursive because doing so is a nice

algorithm complexity - what double star means

大城市里の小女人 提交于 2019-12-22 08:14:37
问题 Does anybody know what means doubled-star in complexity algorithm like this O(N**3) ? I found that one in PHP's similar_text() function and do not understand it. thx 回答1: ** means power. Hence, n**3 means n^3. Complexity is of the order n^3 or O(n^3) 回答2: This double star is the exponentiation operator in PHP(^ operator in general for exponentiation). As per PHP manual, $a ** $b ---- Exponentiation Operator Result of raising $a to the $b'th power. Introduced in PHP 5.6. hence, here the

What would be the time complexity of counting the number of all structurally different binary trees?

十年热恋 提交于 2019-12-22 08:08:31
问题 Using the method presented here: http://cslibrary.stanford.edu/110/BinaryTrees.html#java 12. countTrees() Solution (Java) /** For the key values 1...numKeys, how many structurally unique binary search trees are possible that store those keys? Strategy: consider that each value could be the root. Recursively find the size of the left and right subtrees. */ public static int countTrees(int numKeys) { if (numKeys <=1) { return(1); } else { // there will be one value at the root, with whatever

What is the worst case for KMP string search algorithm? [closed]

谁都会走 提交于 2019-12-22 06:16:34
问题 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 6 years ago . Can anyone suggest me a worst case "text string - pattern pair" for testing a KMP algorithm implementation? 回答1: I would say a pattern like xx........x | n times | and a string like xxx.........xyx...........xy..

Is minimization of boolean expressions NP-Complete?

守給你的承諾、 提交于 2019-12-22 05:10:28
问题 I know that boolean satisfiability is NP-Complete, but is the minimization/simplification of a boolean expression, by which I mean taking a given expression in symbolic form and producing an equivalent but simplified expression in symbolic form, NP-Complete? I'm not sure that there's a reduction from satisfiability to minimization, but I feel like there probably is. Does anyone know for sure? 回答1: Well, look at it this way: using a minimizing algorithm, you can compact any non-satisfiable