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

Theory: Compression algorithm that makes some files smaller but none bigger?

瘦欲@ 提交于 2019-12-22 08:00:11
问题 I came across this question; "A lossless compression algorithm claims to guarantee to make some files smaller and no files larger. Is this; a) Impossible b) Possible but may run for an indeterminate amount of time, c) Possible for compression factor 2 or less, d) Possible for any compression factor?" I'm leaning towards (a), but couldn't give a solid explanation as to why. (I'll list the thoughts a friend and I came up with as a possible answer) 回答1: By the pigeon-hole principle, given a

Print a tree in sorted order using heap properties (Cormen)

只谈情不闲聊 提交于 2019-12-22 04:58:16
问题 I am refreshing on algorithm theory (from Cormen). There is an exercise in the chapter for binary tries that asks: Can the min-heap property be used to print out the keys of an n-node tree in sorted order in O(n) time? Show how, or explain why not. I thought yes it is possible. In the min heap the element in a node is smaller than both its children. So the root of the heap is always the smaller element of all the n elements and the left child of the root is the smaller than all the elements

What is a direct reference?

巧了我就是萌 提交于 2019-12-22 04:56:35
问题 One of the strict mode rules (Annex C) states: When a delete operator occurs within strict mode code, a SyntaxError is thrown if its UnaryExpression is a direct reference to a variable, function argument, or function name. So in this code: delete x x is a reference. (I know this because "the result of evaluating an Identifier is always a value of type Reference"). But is it a direct reference? And, are there other kinds of references? Indirect references? (If not, what's the point of using

Algorithm for partially filling a polygonal mesh

▼魔方 西西 提交于 2019-12-22 04:05:38
问题 Overview: I have a simple plastic sandbox represented by a 3D polygonal mesh. I need to be able to determine the water level after pouring a specific amount of water into the sandbox. The water is distributed evenly from above when poured No fluid simulation, the water is poured very slowly It needs to be fast Question: What kind of techniques/algorithms could I use for this problem? I'm not looking for a program or similar that can do this, just algorithms - I'll do the implementation. 回答1:

Difference between two ranges

给你一囗甜甜゛ 提交于 2019-12-21 12:33:06
问题 I can find plenty of questions and example regarding the 'Union' and 'Intersect' VBA methods but I can't find anything much regarding a 'Set Difference' method? Does this exist (other than by using combinations of union and intersect)?. I'm trying to find a simple way of getting all of range1 excluding any of range1 that overlaps range2 without knowing the size or shape of either range. Any help would be greatly appreciated. EDIT. Attempted solution where rng1 is the red section and rng2 is

crossing edges in the travelling salesman problem

末鹿安然 提交于 2019-12-21 03:44:27
问题 Does there exist a travelling salesman problem where the optimal solution has edges that cross? The nodes are in an x-y plane, so crossing in this case means if you were to draw the graph, two line segments connecting four separate nodes would intersect. 回答1: If two edges in a closed polygonal line cross, then there is a polygonal line with the same vertices but with smaller perimeter. This is a consequence of the triangle inequality. So, a solution to the TSP must be a simple polygon. See

Law of Demeter - Data objects

安稳与你 提交于 2019-12-20 12:33:04
问题 I'm trying to follow the Law Of Demeter ( see http://en.wikipedia.org/wiki/Law_of_Demeter , http://misko.hevery.com/code-reviewers-guide/flaw-digging-into-collaborators/ ) as I can see the benefits, however I've become a little stuck when it comes to domain objects. Domain objects do naturally have a chain and sometimes it's necessary to display the information about the entire chain. For instance, a shopping basket: Each order contains a user, delivery info and a list of items Each order

Why use two step approach to deleting multiple items with REST

*爱你&永不变心* 提交于 2019-12-20 08:57:17
问题 We all know the 'standard' way of deleting a single item via REST is to send a single DELETE request to a URI example.com/Items/666 . Grand, let's move on to deleting many at once. As we do not require atomic deleting (or true transaction, ie all or nothing) we could just tell the client 'tough luck, make many requests' but that's not very nice is it. So we need a way to allow a client to request many 'Items' be deleted at once. From my understanding, the 'typical' solution to this problem is

Valid Huffman Codes?

南笙酒味 提交于 2019-12-20 04:08:00
问题 I'm trying to solve a Huffman Coding problem, but I'm not completely sure I understand the topic completely. I am trying to figure out if the following are is a valid Huffman Code: A: 0 B: 01 C: 11 D: 110 E: 111 What I'm thinking is that it is not valid, because A, or 1, would infringe on B, or 01. I'm not positive though. Could someone enlighten me on this? Edit: I'm sorry I meant to type A as 0 and not 1. 回答1: No. A Huffman code is a prefix code, which means that no code can be a prefix of