computer-science

Detect differences between tree structures

无人久伴 提交于 2019-11-27 16:43:41
This is more of a CS question, but an interesting one : Let's say we have 2 tree structures with more or less the same nodes reorganized. How would you find any in some sense minimal sequence of operations MOVE(A, B) - moves node A under node B (with the whole subtree) INSERT(N, B) - inserts a new node N under node B DELETE (A) - deletes the node A (with the whole subtree) that transforms one tree to the other. There might obviously be cases where such transformation is not possible, trivial being root A with child B to root B with child A etc.). In such cases, the algorithm would simply

What are the boundaries of recursion?

末鹿安然 提交于 2019-11-27 16:31:35
Given let doAsynchronousStuff = () => { return new Promise(resolve => { setTimeout(() => { resolve("abcdefg"[Math.floor(Math.random() * 7)]) }, Math.PI * 1 + Math.random()) }) .then(data => console.log(data)) .then(doAsynchronousStuff) } Is the pattern an implementation of recursion; tail-call optimization; iteration; a non-terminating procedure that happens to refer to itself; or; other common pattern that is not listed above? Looking for an answer drawing from credible and/or official sources. I rewrote the code eliminating all non relevant stuff and using a style I feel is more readable and

why IEEE floating point number calculate exponent using a biased form?

穿精又带淫゛_ 提交于 2019-11-27 16:08:30
问题 let's say, for the float type in c, according to the IEEE floating point specification, there are 8-bit used for the fraction filed, and it is calculated as first taken these 8-bit and translated it into an unsigned number, and then minus the BIASE, which is 2^7 - 1 = 127, and the result is an exponent ranges from -127 to 128, inclusive. But why can't we just treat these 8-bit pattern as a signed number, since the resulting range is [-128,127], which is almost the same as the previous one.

Why is {a^nb^n | n >= 0} not regular?

六月ゝ 毕业季﹏ 提交于 2019-11-27 15:03:37
In a CS course I'm taking there is an example of a language that is not regular: {a^nb^n | n >= 0} I can understand that it is not regular since no Finite State Automaton/Machine can be written that validates and accepts this input since it lacks a memory component. (Please correct me if I'm wrong) The wikipedia entry on Regular Language also lists this example, but does not provide a (mathematical) proof why it is not regular. Can anyone enlighten me on this and provide proof for this, or point me too a good resource? cletus What you're looking for is Pumping lemma for regular languages .

OpenCV: Find all non-zero coordinates of a binary Mat image

送分小仙女□ 提交于 2019-11-27 13:12:50
I'm atttempting to find the non-zero (x,y) coordinates of a binary image. I've found a few references to the function countNonZero() which only counts the non-zero coordinates and findNonZero() which I'm unsure how to access or use since it seems to have been removed from the documentation completely. This is the closest reference I found, but still not helpful at all. I would appreciate any specific help. Edit: - To specify, this is using C++ WangYudong Here is an explanation for how findNonZero() saves non-zero elements. The following codes should be useful to access non-zero coordinates of

Why is Binary Search a divide and conquer algorithm?

杀马特。学长 韩版系。学妹 提交于 2019-11-27 13:00:38
问题 I was asked if a Binary Search is a divide and conquer algorithm at an exam. My answer was yes, because you divided the problem into smaller subproblems, until you reached your result. But the examinators asked where the conquer part in it was, which I was unable to answer. They also disapproved that it actually was a divide and conquer algorithm. But everywhere I go on the web, it says that it is, so I would like to know why, and where the conquer part of it is? 回答1: The book Data Structures

How do backreferences in regexes make backtracking required?

别来无恙 提交于 2019-11-27 11:39:20
问题 I read http://swtch.com/~rsc/regexp/regexp1.html and in it the author says that in order to have backreferences in regexs, one needs backtracking when matching, and that makes the worst-case complexity exponential. But I don't see exactly why backreferences introduce the need for backtracking. Can someone explain why, and perhaps provide an example (regex and input)? 回答1: To get directly at your question, you should make a short study of the Chomsky Hierarchy. This is an old and beautiful way

What is the difference between equality and equivalence?

被刻印的时光 ゝ 提交于 2019-11-27 10:48:24
问题 I've read a few instances in reading mathematics and computer science that use the equivalence symbol ≡ , (basically an '=' with three lines) and it always makes sense to me to read this as if it were equality. What is the difference between these two concepts? 回答1: Wikipedia: Equivalence relation: In mathematics, an equivalence relation is a binary relation between two elements of a set which groups them together as being "equivalent" in some way. Let a, b, and c be arbitrary elements of

What is code coverage and how do YOU measure it?

余生长醉 提交于 2019-11-27 08:55:58
问题 What is code coverage and how do YOU measure it? I was asked this question regarding our automating testing code coverage. It seems to be that, outside of automated tools, it is more art than science. Are there any real-world examples of how to use code coverage? 回答1: Code coverage is a measurement of how many lines/blocks/arcs of your code are executed while the automated tests are running. Code coverage is collected by using a specialized tool to instrument the binaries to add tracing calls

What is the best way to implement this composite GetHashCode()

房东的猫 提交于 2019-11-27 07:25:38
I have a simple class: public class TileName { int Zoom, X, Y; public override bool Equals (object obj) { var o = obj as TileName; return (o != null) && (o.Zoom == Zoom) && (o.X == X) && (o.Y == Y); } public override int GetHashCode () { return (Zoom + X + Y).GetHashCode(); } } I was curious if I would get a better distribution of hash codes if I instead did something like: public override int GetHashCode () { return Zoom.GetHashCode() + X.GetHashCode() + Y.GetHashCode(); } This class is going to be used as a Dictionary key, so I do want to make sure there is a decent distribution. Philip