computer-science

Recursive Sets vs Recursive Functions

偶尔善良 提交于 2019-12-06 09:49:20
问题 What s the difference between a recursive set and recursive function? 回答1: Recursive functions and recursive sets are terms used in computability theory. Wikipedia defines them as follows: A set of natural numbers is said to be a computable set (also called a decidable, recursive, or Turing computable set) if there is a Turing machine that, given a number n, halts with output 1 if n is in the set and halts with output 0 if n is not in the set. A function f from the natural numbers to

How exactly does dp parameter in cv::HoughCircles work?

我们两清 提交于 2019-12-06 08:13:36
I read similar question in Stack Overflow. I tried, but I still can not understand how it works. I read OpenCV document cv::HoughCircles , here are some explanation about dp parameter: Inverse ratio of the accumulator resolution to the image resolution. For example, if dp=1 , the accumulator has the same resolution as the input image. If dp=2 , the accumulator has half as big width and height. Here are my question. For example, if dp = 1, the size of accumulator is same as image, there is a consistent one-to-one match between pixels in image and positions in accumulator, but if dp = 2, how to

division and multiplication by power of 2

99封情书 提交于 2019-12-06 08:04:46
I read in a paper that division and multiplication of a number by a power of 2 is a trivial process. I have searched a lot of internet for the explanation but doesn't get it. Can any one explain in easy words what does this actually meant to say. Vlad It is trivial from the bit operations perspective. Multiplying by 2 is equivalent to a shift left by 1 bit, division is a right shift. similarly it is the same trivial to multiply and divide by any power of 2. int a = 123; // or in binary format: a = 0b01111011; assert (a * 2) == (a << 1); // 2 = 2^1, (a << 1) = 11110110 assert (a / 2) == (a >> 1

Why is a monitor implemented in terms of semaphores this way?

♀尐吖头ヾ 提交于 2019-12-06 07:26:39
问题 I have trouble understanding the implementation of a monitor in terms of semaphores from Operating System Concepts 5.8.3 Implementing a Monitor Using Semaphores We now consider a possible implementation of the monitor mechanism using semaphores. For each monitor, a semaphore mutex (initialized to 1) is provided. A process must execute wait(mutex) before entering the monitor and must execute signal(mutex) after leaving the monitor. Since a signaling process must wait until the resumed process

How do you define an anonymous function in lambda calculus terms (or how can I say some language supports anonymous functions)?

为君一笑 提交于 2019-12-06 04:03:02
问题 Does java support in current version of 6 lambda expressions or "anonymous functions"? Is there something I can't do in java that I couldn't do with a programming language supporting lambda expressions? I understand that java is turing complete so you can do "anything" in it. Why couldn't anonymous inner class wrapped functions represent functions as defined in lambda calculus? What actually is an anonymous function and how you can say that some language supports anonymous functions? 回答1: As

Real-world use of binding objects in ruby

人盡茶涼 提交于 2019-12-06 03:27:37
问题 Last night, I was thinking about what i think are advanced ruby language features, namely Continuations (callcc) and Binding objects. I mean advanced because I have a statically-typed oo langages background (C#, Java, C++), I discovered ruby very recently, so these language features are not very familiar to me. I'm wondering what could be real-world use of these langages features. In my experience, everything could be done with statically typed oo langages, but I agree not very smartly

Why are loops executed one more time than the loop body?

会有一股神秘感。 提交于 2019-12-06 02:15:55
A quote from an Algorithms textbook: "When a for or while loop exits in the usual way (i.e., due to the test in the loop header), the test is executed one time more than the loop body." So, for example, a for loop that begins with for j=1 to 3 will be executed not 3 times, but 4 times! Question: Why would such a loop be executed 4 times and not 3 times? By my reasoning: When j = 1, the loop is executed. When j = 2, the loop is executed. When j = 3, the loop is executed. When j = 4, the loop is NOT executed. I count 3, not 4. bnm I think you are confused about what the statement in the book

Is it possible to have regexp that matches all valid regular expressions?

寵の児 提交于 2019-12-06 02:07:52
问题 Is it possible to detect if a given string is valid regular expression, using just regular expressions? Say I have some strings, that may or may not be a valid regular expressions. I'd like to have a regular expression matches those string that correspond to valid regular expression. Is that possible? Or do I have use some higher level grammar (i.e. context free language) to detect this? Does it affect if I am using some extended version of regexps like Perl regexps? If that is possible, what

Finding the transpose of a very, very large matrix

拟墨画扇 提交于 2019-12-05 22:02:35
I have this huge 2 dimensional array of data. It is stored in row order: A(1,1) A(1,2) A(1,3) ..... A(n-2,n) A(n-1,n) A(n,n) I want to rearrange it into column order A(1,1) A(2,1) A(3,1) ..... A(n,n-2) A(n,n-1) A(n,n) The data set is rather large - more than will fit on the RAM on a computer. (n is about 10,000, but each data item takes about 1K of space.) Does anyone know slick or efficient algorithms to do this? Create n empty files (reserve enough space for n elements, if you can). Iterate through your original matrix. Append element (i,j) to file j . Once you are done with that, append the

Modification to “Implementing an N process barrier using semaphores”

南笙酒味 提交于 2019-12-05 20:34:32
Recently I see this problem which is pretty similar to First reader/writer problem. Implementing an N process barrier using semaphores I am trying to modify it to made sure that it can be reuse and work correctly. n = the number of threads count = 0 mutex = Semaphore(1) barrier = Semaphore(0) mutex.wait() count = count + 1 if (count == n){ barrier.signal()} mutex.signal() barrier.wait() mutex.wait() count=count-1 barrier.signal() if(count==0){ barrier.wait()} mutex.signal() Is this correct? I'm wondering if there exist some mistakes I didn't detect. Your pseudocode correctly returns barrier