instruction
stringlengths
0
29.8k
⌀
You seem to be overloading the term 'blocking'. Any context switch you make to the kernel, you have to wait for it to switch back to the usermode before your application can continue. This is not what is usually called 'blocking'. In the current kernel design, blocking calls are calls where the kernel returns on...
Is it not necessary to encode both the uppercase and lowercase letter while encoding a message? From an old computer science course exam, the problem was to encode `Matt_ate_the_mat` starting with an empty list. Using the author's solution methodology of not taking into account "M" versus "m" one arrives at $C(1)...
Distinguishing between uppercase and lowercase letters in the "move to front" method
|combinatorics|data-compression|
One point that's important in our multicore world: BFS is much more easy to parallelize. This is intuitively reasonable (send off threads for each child) and can be proven to be so as well. So if you have a scenario where you can make use of parallelism, then BFS is the way to go.
(I made this a community wiki. Please feel free to edit.) If * $b$ is the branching factor * $d$ is the depth where the solution is * $h$ is the height of the tree (so, $d\le h$) Then * DFS takes $O(b^h)$ time and $O(h)$ space * BFS takes $O(b^d)$ time and $O(b^d)$ space * IDFS takes $O(b^d)$ time...
null
Is it not necessary to encode both the uppercase and lowercase letter while encoding a message with the [move-to-front transform](http://en.wikipedia.org/wiki/Move-to-front_transform)? From an old computer science course exam, the problem was to encode `Matt_ate_the_mat` starting with an empty list. Using the author...
Distinguishing between uppercase and lowercase letters in the "move-to-front" method
Here is the standard pseudocode for breadth first search: { seen(x) is false for all x at this point } push(q, x0) seen(x0) := true while (!q.empty()) x := pop(q) visit(x) for each y reachable from x by one edge if not seen(y) push(q, y) seen(y) ...
Do you get DFS if you change the stack to a queue in a BFS implementation?
|graphs|
Do you get DFS if you change the queue to a stack in a BFS implementation?
I was reading [an article](http://www.eecg.toronto.edu/~livio/papers/flexsc-osdi10.pdf) that describes the switch between user-space and kernel-space that happens upon a system call. The article says > An application expects the completion of the system call before resuming user-mode execution. Now, until now I ...
|algorithms|graphs|
Here is the standard pseudocode for breadth first search: { seen(x) is false for all x at this point } push(q, x0) seen(x0) := true while (!empty(q)) x := pop(q) visit(x) for each y reachable from x by one edge if not seen(y) push(q, y) seen(y) :...
Disclaimer: I am wildly guessing here; I have not read any genre research. You could look at how many connections to nodes share relatively to the number of conncetions a node has. This is a very naive (as local) idea, but here goes. Every node $N$ (person or some other concept) has a set of connections $C_N$. No...
It seems to be a simple case of [Blum's Speedup Theorem](http://en.wikipedia.org/wiki/Blum's_speedup_theorem): >Given a Blum complexity measure $(\varphi, \Phi)$ and a total computable function $f$ with two parameters, then there exists a total computable predicate $g$ (a Boolean valued computable function) so that ...
Note: This is a seeding question and might have appeared on StackOverflow before. (Feel free to close if you think it is inappropriate). You are given an array of $2n$ elements $$a_1, a_2, \dots, a_n, b_1, b_2, \dots b_n$$ The task is to interleave the array, using an in-place algorithm such that the resultin...
In-place algorithm for interleaving an array
|algorithms|in-place|
Here is the standard pseudocode for breadth first search: { seen(x) is false for all x at this point } push(q, x0) seen(x0) := true while (!empty(q)) x := pop(q) visit(x) for each y reachable from x by one edge if not seen(y) push(q, y) seen(y) :...
As stated in the comments of the original question, This "handle" means the left-most variable in left-most derivation according to the definition which is 'B' in this case. It means from which variable you should start simplifying a sentence of the grammar.
Deriving the regular expression for C-style /**/ comments
null
Suppose the datatype for a BST is defined as follows (in SML) datatype 'a bst_Tree = Empty | Node of (int * 'a) * 'a bst_Tree * 'a bst_Tree; So there are two cases one in which the BST is `Empty` or it can have a (key,value) as well as two children. Now, for the case of an AVL where the condi...
What is the height of an empty BST when using it in context for balancing?
|algorithms|
Any constant works as the height of `Empty`, because only the *difference* of heights is important for balancing. So, why not choose 0?
Suppose the datatype for a BST is defined as follows (in SML) datatype 'a bst_Tree = Empty | Node of (int * 'a) * 'a bst_Tree * 'a bst_Tree; So there are two cases one in which the BST is `Empty` or it can have a (key,value) as well as two children. Now, for the case of an AVL where the condi...
Suppose the datatype for a BST is defined as follows (in SML) datatype 'a bst_Tree = Empty | Node of (int * 'a) * 'a bst_Tree * 'a bst_Tree; So there are two cases one in which the BST is `Empty` or it can have a (key,value) as well as two children. Now, for the case of an AVL where the condi...
No, this is not the same as a DFS. Consider the graph ![enter image description here][1] If you push the nodes in right to left order, the algorithm gives you a traversal: $A, B , E, C , D$ while a DFS would expect it to be $A,B,E,D,C$ The problem occurs because you mark it as seen at the time of...
If you want to be sure that you're parsing C comments, you need to confront your model with the C specification. [C99](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf) §6.4.9 defines the syntax of comments as follows: > 1\. Except within a character constant, a string literal, or a comment, the characters ...
I'm learning programming in ML (OCaml), and earlier I asked about [ML functions of type `'a -> 'b`](http://cs.stackexchange.com/questions/302/ml-function-of-type-a-b). Now I've been experimenting a bit with functions of type `'a list -> 'b list`. There are some obvious simple examples: let rec loop l = loop l ...
ML functions from polymorphic lists to polymorphic lists
|programming-languages|typing|
Intuitively, "balanced trees" should be trees where left and right sub-trees at each node must have "approximately the same" number of nodes. Of course, when we talk about Red-Black trees being balanced, we actually mean that they are _height_ balanced and in that sense, they are balanced. I have seen a few arti...
Not all Red-Black trees are balanced?
|binary-trees|
I'll assume you talk about the 'handle' as often defined in the context of LR-parsing. I'm not entirely sure if the definition you use is the proper definition: $A$ and $B$ seem to stand for nonterminals, but $B$ should really stand for some string of terminals and nonterminals (as the right hand side of a production o...
From the [wikipedia article that you cited][1]: > The Toffoli gate is universal; this means that for any boolean > function f(x1, x2, ..., xm), there is a circuit consisting of Toffoli > gates which takes x1, x2, ..., xm and some extra bits set to 0 or 1 > and outputs x1, x2, ..., xm, f(x1, x2, ..., xm), and some...
Let's get back to simpler objects: you cannot build an proper object of type <code>'a</code> because then it would mean this object <code>x</code> can be used wherever <code>'a</code> would fit. And that means everywhere: as an integer, an array, even a function. For example that would mean you can do things like <cod...
From the [wikipedia article that you cited][1]: > The Toffoli gate is universal; this means that for any boolean > function f(x1, x2, ..., xm), there is a circuit consisting of Toffoli > gates which takes x1, x2, ..., xm and some extra bits set to 0 or 1 > and outputs x1, x2, ..., xm, f(x1, x2, ..., xm), and some...
From the [wikipedia article that you cited][1]: > The Toffoli gate is universal; this means that for any boolean > function f(x1, x2, ..., xm), there is a circuit consisting of Toffoli > gates which takes x1, x2, ..., xm and some extra bits set to 0 or 1 > and outputs x1, x2, ..., xm, f(x1, x2, ..., xm), and some...
From the [wikipedia article that you cited][1]: > The Toffoli gate is universal; this means that for any boolean > function f(x1, x2, ..., xm), there is a circuit consisting of Toffoli > gates which takes x1, x2, ..., xm and some extra bits set to 0 or 1 > and outputs x1, x2, ..., xm, f(x1, x2, ..., xm), and some...
From the [wikipedia article that you cited][1]: > The Toffoli gate is universal; this means that for any boolean > function f(x1, x2, ..., xm), there is a circuit consisting of Toffoli > gates which takes x1, x2, ..., xm and some extra bits set to 0 or 1 > and outputs x1, x2, ..., xm, f(x1, x2, ..., xm), and some...
|algorithms|in-place|arrays|
Toffoli is universal for classical computation (as shown by @Victor). However, Toffoli is NOT universal for quantum computation (unless we have something crazy like $P = BQP$). To be universal for quantum computation (under the usual definition), the group generated by your gates has to be dense in the unitaries. I...
The **height** of a rooted tree is defined as the **length of the longest simple leaf-to-root path** In the case of a 2 node tree, then clearly this length is 1. In the case of a 1 node tree (a tree with just the root) then the length has to be 0. (There are 0 edges on the path from the leaf to the root.) ...
The **height** of a rooted tree is defined as the **length of the longest simple leaf-to-root path** In the case of a 2 node tree, then clearly this length is 1. In the case of a 1 node tree (a tree with just the root) then the length has to be 0. (There are 0 edges on the path from the leaf to the root.) ...
Though for us, human beings, `m` and `M` are the same, for a computer these are two distinct symbols that have no relation whatsoever. The answer actually depends on the application: * If your application is not case-sensitive, this separation does not matter, and the encoding is correct. * If the application...
|algorithms|data-structures|
Intuitively, "balanced trees" should be trees where left and right sub-trees at each node must have "approximately the same" number of nodes. Of course, when we talk about red-black trees being balanced, we actually mean that they are _height_ balanced and in that sense, they are balanced. I have seen a few arti...
null
|data-structures|binary-trees|
I sometimes find out that people that doesn't do well in theory, just have the basics wrong (on the first 1-3 lectures, they thought the material is very easy, so they didn't pay too much attention, but then, at lecture 5-7 things speed up and it's too late to recap). As @fbernardo said, it might be a good idea to s...
From the [wikipedia article that you cited][1]: > The Toffoli gate is universal; this means that for any boolean > function f(x1, x2, ..., xm), there is a circuit consisting of Toffoli > gates which takes x1, x2, ..., xm and some extra bits set to 0 or 1 > and outputs x1, x2, ..., xm, f(x1, x2, ..., xm), and some...
null
Intuitively, "balanced trees" should be trees where left and right sub-trees at each node must have "approximately the same" number of nodes. Of course, when we talk about red-black trees being balanced, we actually mean that they are _height_ balanced and in that sense, they are balanced. I have seen a few arti...
From the [wikipedia article that you cited][1]: > The Toffoli gate is universal; this means that for any boolean > function f(x1, x2, ..., xm), there is a circuit consisting of Toffoli > gates which takes x1, x2, ..., xm and some extra bits set to 0 or 1 > and outputs x1, x2, ..., xm, f(x1, x2, ..., xm), and some...
From the [wikipedia article that you cited][1]: > The Toffoli gate is universal; this means that for any boolean > function f(x1, x2, ..., xm), there is a circuit consisting of Toffoli > gates which takes x1, x2, ..., xm and some extra bits set to 0 or 1 > and outputs x1, x2, ..., xm, f(x1, x2, ..., xm), and some...
Though for us, human beings, `m` and `M` are the same, for a computer these are two distinct symbols that have no relation whatsoever. The answer actually depends on the application: * If your application is not case-sensitive, this separation does not matter, and the encoding is correct. * If the application...
I was reading an article that described the switch between user-space and kernel-space that happens upon a system call. The article said > An application expects the completion of the system call before resuming user-mode execution. Now, until now I was assuming that some system calls are `blocking`, where as ot...
To answer part of your question. The formalism described by [Morrisett and Harper][1] covers big- and small-step semantics of higher-order polymorphic languages containing closures. There are papers before these providing the kinds of semantics you are looking for. Look, for example, at [the SECD machine][2]. Adding mu...
To encrypt a message $m_1$ with a one-time-pad key $k$ you do $Enc(m_1,k) = m_1 \oplus k$. If you use the same $k$ to encrypt a different message $m_2$ you get $Enc(m_2,k) = m_2 \oplus k$, and if you perform Xor of the two ciphertext you get $$( m_1 \oplus k) \oplus ( m_2 \oplus k) = m_1 \oplus m_2$$ so, OK, ...
Why encrypting with the same one-time-pad is not good?
|crypto|encryption|otp|information|
De Morgan's Law is often introduced in an introductory mathematics for computer science course, and I often see it as a way to turn statements from AND to OR by negating terms, is there a more intuitive explanation for why this works rather than just remembering why it works because of truth table works out? To me this...
What is an intuative way to explain De Morgan's Law, and why does De Morgan's law work?
|logic|discrete-mathematics|
If you like to visualize it, use the venn diagrams. See [this][1], for instance. I find it more simple just to memorize the basic 2 laws: everytime you "break" a negation line, you rplace the AND to OR (or vice versa). Adding two negation lines change nothing (but this gives you more "lines" to break). It just work...
Why is encrypting with the same one-time-pad not good?
What is an intuative way to explain and understand the De Morgan's Law?
|crypto|encryption|otp|information-theory|
Most of today's encryption, such as the RSA, relies on the integer factorization, which is not believed to be a NP-hard problem. I wonder, why has there not been an encryption algorithm which is based on an known NP-hard problem. It sounds (at least in theory) like it would make a better encryption algorithm than a one...
Why hasn't there been an encryption algorithm that uses the known NP-Hard problems?
|complexity-theory|crypto|encryption|
Insert real-world predicates and read aloud, for instance: > It can not be both winter *and* summer (at any point in time). and > (At any point in time) It is *not* winter *or* it is *not* summer. Clearly, the two statements are equivalent.
Most of today's encryption, such as the RSA, relies on the integer factorization, which is not believed to be a NP-hard problem, but it belongs to BQP, which makes it vulnerable to quantum computers. I wonder, why has there not been an encryption algorithm which is based on an known NP-hard problem. It sounds (at least...
discussions about the One-Time-Pad (OTP) encryption method
null
Why hasn't there been an encryption algorithm that is based on the known NP-Hard problems?
De Morgan's Law is often introduced in an introductory mathematics for computer science course, and I often see it as a way to turn statements from AND to OR by negating terms. Is there a more intuitive explanation for why this works rather than just remembering truth tables? To me this is like using black magic, wh...
What is an intuitive way to explain and understand De Morgan's Law?
null
|complexity-theory|np-hard|crypto|encryption|
You need to check that your friend, Bob, has your correct phone number, but you cannot ask him directly. You must write the question on a card which and give it to Eve who will take the card to Bob and return the answer to you. What must you write on the card, besides the question, to ensure Bob can encode the message ...
How to verify number with Bob without Eve knowing?
|algorithms|crypto|
Looks like a classic application of [Public Key Cryptosystem][1]. You send your public key along, BoB encrypts your phone number from his contacts list and sends it back to you. [1]: http://en.wikipedia.org/wiki/Public-key_cryptography
There have been. One such example is http://en.wikipedia.org/wiki/McEliece_cryptosystem which is based on hardness of decoding a linear code. A second example is: http://en.wikipedia.org/wiki/NTRUEncrypt which is based on the shortest vector problem which I believe is known to be NP-Hard. Another is http://en...
Looks like a classic application of [Public Key Cryptosystem][1] like [RSA][2]. You send your public key along, BoB encrypts your phone number from his contacts list and sends it back to you. [1]: http://en.wikipedia.org/wiki/Public-key_cryptography [2]: http://en.wikipedia.org/wiki/RSA_%28algorithm%29
There have been. One such example is http://en.wikipedia.org/wiki/McEliece_cryptosystem which is based on hardness of decoding a linear code. A second example is: http://en.wikipedia.org/wiki/NTRUEncrypt which is based on the shortest vector problem which I believe is known to be NP-Hard. Another is http://en...
It's insecure precisely due to the reason you mention - there is some information leakage. Basically, if you have any assumptions about plaintexts (english text, files with known structure, etc), it leads to an easy statistical analysis. Probably using it **twice** doesn't change the practicality of the attack signi...
You need to check that your friend, Bob, has your correct phone number, but you cannot ask him directly. You must write the question on a card which and give it to Eve who will take the card to Bob and return the answer to you. What must you write on the card, besides the question, to ensure Bob can encode the message ...
Intuitively, "balanced trees" should be trees where left and right sub-trees at each node must have "approximately the same" number of nodes. Of course, when we talk about red-black trees*(see definition at the end) being balanced, we actually mean that they are _height_ balanced and in that sense, they are balanced...