computer-science

Detect differences between tree structures

僤鯓⒐⒋嵵緔 提交于 2019-11-26 18:44:27
问题 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

What are the boundaries of recursion?

∥☆過路亽.° 提交于 2019-11-26 18:40:52
问题 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

Implementing an N process barrier using semaphores

ε祈祈猫儿з 提交于 2019-11-26 18:07:08
问题 I'm currently training for an OS exam with previous iterations and I came across this: Implement a "N Process Barrier", that is, making sure that each process out of a group of them waits, at some point in its respective execution, for the other processes to reach their given point. You have the following ops available: init(sem,value), wait(sem) and signal(sem) N is an arbitrary number. I can make it so that it works for a given number of processes, but not for any number. Any ideas? It's OK

Is there a difference between foreach and map?

旧时模样 提交于 2019-11-26 18:04:37
Ok this is more of a computer science question, than a question based on a particular language, but is there a difference between a map operation and a foreach operation? Or are they simply different names for the same thing? Different. foreach iterates over a list and applies some operation with side effects to each list member (such as saving each one to the database for example) map iterates over a list, transforms each member of that list, and returns another list of the same size with the transformed members (such as converting a list of strings to uppercase) The important difference

What is “entropy and information gain”?

一笑奈何 提交于 2019-11-26 18:02:20
I am reading this book ( NLTK ) and it is confusing. Entropy is defined as : Entropy is the sum of the probability of each label times the log probability of that same label How can I apply entropy and maximum entropy in terms of text mining? Can someone give me a easy, simple example (visual)? Amro I assume entropy was mentioned in the context of building decision trees . To illustrate, imagine the task of learning to classify first-names into male/female groups. That is given a list of names each labeled with either m or f , we want to learn a model that fits the data and can be used to

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

左心房为你撑大大i 提交于 2019-11-26 16:59:36
问题 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

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

与世无争的帅哥 提交于 2019-11-26 16:16:19
问题 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++ 回答1: Here is an explanation for how findNonZero()

What is the 'expression problem'?

半腔热情 提交于 2019-11-26 15:19:25
问题 I have a rough idea about what this is but if someone has an explanation of the 'expression problem' that they think is succinct and intuitive I would love to hear it. 回答1: Watch this lecture. The idea is that your program is a combination of a datatype and operations over it. The problem asks for an implementation that allows to add new cases of the type and new operations without the need for recompilation of the old modules and keeping static type safety(no casts or runtime type checks).

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

半腔热情 提交于 2019-11-26 13:06:03
问题 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

What kind of formal languages can modern regex engines parse?

只愿长相守 提交于 2019-11-26 13:03:36
问题 Here on SO people sometimes say something like \"you cannot parse X with regular expressions, because X is not a regular language\". From my understanding however, modern regular expressions engines can match more than just regular languages in Chomsky\'s sense. My questions: given a regular expression engine that supports backreferences lookaround assertions of unlimited width recursion, like (?R) what kind of languages can it parse? Can it parse any context-free language, and if not, what