instruction
stringlengths
0
29.8k
⌀
You are missing one thing, namely that the optimal algorithm and worst instance are not simply functions of the instance size. Also, I am not sure that minimising/maximising algorithm and instance independently of each other is doing the right thing. The complexity of a problem is the *complexity of an optimal algor...
You can modify any graph $G$ so that Dijkstra's finds the solution with the minimal number of edges thusly: Multiply every edge weight with a number $a$, then add $1$ to the weight to penalize each additional edge in the solution, i.e. $w'(u,v)=a*w(u,v)+1$ This does not work for all values of $a$; $a$ needs t...
Dijkstra to favor solution with smallest number of edges
|algorithms|shortest-path|
I am recently studying about Compilers designing. I came to know about two types of grammar one is LL grammar and other is LR grammar. We also know the facts that every LL grammar is LR that is LL grammar is a proper subset of LR grammar. First one is used in top-down parsing and the second one is used in bottom-up...
Is there any way to distinguish between LL(k) and LR(k) grammar?
|compilers|language-design|
Why are decision problems commonly used in complexity theory?
I need to create a bloom filter of 208 million URLs. What would be a good choice of bit vector size and number of hash functions? I tried a bit vector of size 1 GB and 4 hash functions, but it resulted in too many false positives while reading. I have a huge web corpus containing web content of billions of URLs. I n...
|data-structures|big-data|
null
There are several equivalent PDA models: 1. In one model, "By accepting state", the PDA accepts if at the end of processing the input, the automaton is in an accepting state. 1. In another model, "By empty stack", the PDA accepts if at the end of processing the input, the stack is empty (regardless of the state t...
Basically, a `module` runs at the same memory space than the kernel and a `server` runs in a different one. Although a `module` can surely be added/removed on-the-fly (linux kernel does that), any misbehavior caused by it may affect the entire system, whether in the micro-kernel architecture, only the `server` gets ...
Dijkstra to favor solution with smallest number of edges if several paths have same weight
|formal-grammars|compilers|parsing|
|algorithms|graphs|shortest-path|
$LL(k)$ and $LR(k)$ grammars are nice not just because they can be parsed efficiently, but also because we can check if a grammar is $LL(k)$ or $LR(k)$, and because we can generate tables for them (parse tables are used to parse input strings). Note that for these two classes, having the parse table immediately allows ...
A 'top down parser' is usually understood to be a hand-written $LL(1)$ parser, or $LL(k)$ for some low $k$, which would explain the use of this terminology. These two concepts are therefore essentially the same. I'm unsure what you mean exactly by 'common prefixes' - I guess you are talking about common lookaheads. ...
null
Your grammar indeed is ambiguous as it currently is, but not because the follow sets of two nonterminals have common elements. The ambiguity I see is that both re2 -> re1 -> expr -> term -> factor -> num -> ε and re2 -> re1 -> expr -> term -> factor -> id -> ε derive the empty word. If you require that num and id are b...
I am trying to understand different interactive proof systems. Is there a typical problem for the complexity class MA (like graph-nonisomorphism is for AM)? Is there a problem in MA but not known to be in NP or BPP? Is there a reason that most books discuss AM in detail while merely glossing over MA, which seems to ...
"Essential" problem for MA
|complexity-theory|
null
|complexity-theory|interactive-proof-systems|
We have to check only that a grammar is LL or not because every LL grammar is LR that is LL is proper subset of LR. So if a grammar is LL then it must be LR but every LR is not LL. A grammar G is in LL iff whenever A->C|D , the following condition should hold: 1. First(C) and First(D) are disjoint sets. 2. If e...
This is part of a larger problem, which I believe I have reduced to this. Given a tree $T$ having positive edge weights, and $k$ leaves (nodes which have exactly one connected node), I need to delete some edges in the tree so that no two leaves in the original tree are connected (by a path) in the newly formed forest (...
Separate all leaves of a weighted tree with minimum weight cuts
|algorithms|graphs|trees|
null
You are missing one thing, namely that the optimal algorithm and worst instance are not simply functions of the instance size. Also, I am not sure that minimising/maximising algorithm and instance independently of each other is doing the right thing. The complexity of a problem is the *complexity of an optimal algor...
Foo and Bar is playing a **game of strategy**. At the start of the game, there are **N apples**, placed in a row (in straight line). The apples are numbered from 1 to N. Each apple has a particular price value. The price of ith apple is **pi** for i=1 to N. In this game, the players Foo and bar mak...
Foo and Bar Game of Strategy
|algorithms|game-theory|
null
Automatic parallelization in the most general terms is extracting a dependency graph from the execution sequence of the program and executing distinct paths in this graph in parallel with synchronization introduced at the nodes of the graph where the paths merge. Our ability to extract the dependency information var...
Automatic parallelization in the most general terms is extracting a dependency graph from the execution sequence of the program and executing distinct paths in this graph in parallel with synchronization introduced at the nodes of the graph where the paths merge. Our ability to extract the dependency information var...
They probably meant you to solve it using dynamic programming. Since I'm guessing this is an exercise, I won't say anything more on this front. Also, your program is incorrect: it doesn't consider the actions of Bar. The game is not really a *game of strategy*, since there are no choices involved, only chance. In or...
there are probably many different ways to answer this question however one key element is historical precedent. the disproof of the existence of an algorithm for the [halting problem](http://en.wikipedia.org/wiki/Halting_problem) in 1936 by Turing uses the halting problem as a decision problem. this was in turn based o...
there are probably many different ways to answer this question however one key element is historical precedent. the disproof of the existence of an algorithm for the [halting problem](http://en.wikipedia.org/wiki/Halting_problem) in 1936 by Turing uses the halting problem as a decision problem. this was in turn based o...
there are probably many different ways to answer this question however one key element is historical precedent. the disproof of the existence of an algorithm for the [halting problem](http://en.wikipedia.org/wiki/Halting_problem) in 1936 by Turing uses the halting problem as a decision problem. this was in turn based o...
Apologies in advance for my formatting. In my Computing Theory course, a lot of our problems involve using induction on the length of the input string to prove statements about finite automata. I understand mathematical induction, however when strings come into play I get real tripped up. I'd really appreciate it ...
How do I write a proof using induction on the length of the input string?
|finite-automata|proof-techniques|
In my Computing Theory course, a lot of our problems involve using induction on the length of the input string to prove statements about finite automata. I understand mathematical induction, however when strings come into play I get real tripped up. I'd really appreciate it if someone would go through the process of ...
|finite-automata|proof-techniques|induction|
Representing numeric values using [positional notation][1] is one of the milestones in the history of arithmetic. Babylons used a base 60 system, Maya a base 20 system; base 10 system became "the standard" used by modern civilizations; digital computers use the [Binary numeral system][2], .... But if we look at natu...
Numeral systems other than unary used in nature or in animal and human behaviours
|algorithms|reference-request|soft-question|
Representing numeric values using [positional notation][1] is one of the milestones in the history of arithmetic. Babylons used a base 60 system, Maya a base 20 system; base 10 system became "the standard" used by modern civilizations; digital computers use the [Binary numeral system][2], .... But if we look at natu...
Representing numeric values using [positional notation][1] is one of the milestones in the history of arithmetic. Babylons used a base 60 system, Maya a base 20 system; base 10 system became "the standard" used by modern civilizations; digital computers use the [Binary numeral system][2], .... But if we look at natu...
Foo and Bar are playing a game of strategy. At the start of the game, there are $N$ apples, placed in a row (in straight line). The apples are numbered from $1$ to $N$. Each apple has a particular price value. The price of $i$th apple is $p_i$. In this game, the players Foo and bar make an alternative move. In...
Expected gain of a game of chance with differently-priced tokens
In my Computing Theory course, a lot of our problems involve using induction on the length of the input string to prove statements about finite automata. I understand mathematical induction, however when strings come into play I get real tripped up. I'd really appreciate it if someone would go through the process of ...
In my Computing Theory course, a lot of our problems involve using induction on the length of the input string to prove statements about finite automata. I understand mathematical induction, however when strings come into play I get real tripped up. I'd really appreciate it if someone would go through the process of ...
<sup>As it is unclear where your problem lies, I'll start at the very beginning.</sup> Mathematical induction works like the game of [Chinese whispers](https://en.wikipedia.org/wiki/Chinese_whispers) (in the ideal case): you start somewhere and show that your every next step does not break anything, assuming nothing...
They probably meant you to solve it using dynamic programming. Since I'm guessing this is an exercise, I won't say anything more on this front. Also, your program is incorrect: it doesn't consider the actions of Bar. The game is not really a *game of strategy*, since there are no choices involved, only chance. In or...
Do you know any algorithm that calculates the factorial after modulus efficiently? For example, I want to program: for(i=0; i<5; i++) sum += factorial(p-i) % p; But, `p` is a big number (prime) for applying factorial directly $(p \leq 10^ 8)$. In Python, this task is really easy, but i really wan...
*(This answer was initially posted by the asker [d555](http://cs.stackexchange.com/users/1152/d555) inside the question.)* I remember [Wilson's theorem](https://en.wikipedia.org/wiki/Wilson%27s_theorem), and I noticed little things: In the above program, it is better if I write: $$\begin{align} (p-1)! \equiv -1...
null
null
null
You can modify any graph $G$ so that Dijkstra's finds the solution with the minimal number of edges thusly: Multiply every edge weight with a number $a$, then add $1$ to the weight to penalize each additional edge in the solution, i.e. $w'(u,v)=a*w(u,v)+1$ This does not work for all values of $a$; $a$ needs t...
From the point of view of filling-out the machine model, the three criteria of Turing Completeness appear useful. * Sequence * Selection * Iteration or Recursion It's clearly #3 that's missing at present, the fanciful "linkage" mentioned above.
Let's say I have a graph $|G|$ with $|E|=O(V^2)$ edges. I want to run BFS on $G$ which has a running time of $O(V+E)$. It feels natural to write that the running time on this graph would be $O(O(V^2)+V)$ and then simplify to $O(V^2)$. Are there any pitfalls to using such a "remove-the-nested-O" shortcut (not just...
Nested O-notation
|complexity|big-o|
I understand that using DFS "as is" will not find a shortest path in an unweighted graph. But why is tweaking DFS to allow it to find shortest paths in unweighted graphs such a hopeless prospect? All texts on the subject simply state that it cannot be done. I'm unconvinced (without having tried it myself). Do y...
Why can't DFS be used to find shortest paths in unweighted graphs?
|algorithms|shortest-path|
null
/* Bubble sort for integers */ #define SWAP(a,b) { int t; t=a; a=b; b=t; } void bubble( int a[], int n ) /* Pre-condition: a contains n items to be sorted */ { int i, j; /* Make n passes through the array */ for(i=0;i<n;i++) { ...
how to find the time complexity of this algorithm?
|algorithm-analysis|
|algorithms|algorithm-analysis|sorting|
There is at least one example where a string of symbols from an alphabet is also used: proteins. Proteins consist of chains of 20 different amino acids (usually, in some cases, it's 21 or 22) and the sequence of amino acids determines what given protein does. This example is closely related to the DNA example you...
The first iteration will do will do $n$ comparisons, the next $n-1$, the second $n-2$ and so on. In total $n$ iterations are done. Hence, you need to find the sum of $n +(n-1)+(n-2) + ... + 1$ which is $(n^2+n)/2$ which still is $O(n^2)$. So the optimization does not improve the asymptotic running time.
null
The first iteration will do will do $n-1$ comparisons, the next $n-2$, the second $n-3$ and so on. In total $n-1$ iterations are done. Hence, you need to find the sum of $(n-1)+(n-2) + ... + 1$ which is $((n-1)^2+n-1)/2$ which still is $O(n^2)$. So the optimization does not improve the asymptotic running time. No...
I have a formula $ \neg((q \implies \neg q) \vee p \vee (\neg q \implies (r \wedge p))) $. As it contains 3 subformulas between the $\vee$'s, how can i put it into a parse tree, as a parse tree contains 2 branches from each node.
How to make a parse tree for the following propositional logic formula?
|formal-languages|logic|binary-trees|
|terminology|asymptotics|landau-notation|
|algorithms|graphs|shortest-path|
/* Bubble sort for integers */ #define SWAP(a,b) { int t; t=a; a=b; b=t; } void bubble( int a[], int n ) /* Pre-condition: a contains n items to be sorted */ { int i, j; /* Make n passes through the array */ for(i=0;i<n-1;i++) ...
Complexity of optimized bubblesort
null
Let me start of with a recommendation: treat Landau notation just as you (should) treat rounding: round rarely, round late. If you know something more precise than $O(.)$, use it until you are done with all calculations, and Landauify at the end. --- As for the question, let's dig through this abuse of notation¹....
Nested Big O-notation
null
null
What is the runtime complexity of the following implementation of Bubblesort (for integers)? #define SWAP(a,b) { int t; t=a; a=b; b=t; } void bubble( int a[], int n ) /* Pre-condition: a contains n items to be sorted */ { int i, j; /* Make n passes throug...
|algorithms|algorithm-analysis|runtime-analysis|sorting|
The Aufbau principle, which controls the electron configuration of atoms, is an example of a "positional" notation. Electrons (more or less) fill shells in some fixed order, and the outer shell determines the chemical properties of the atom.
As it is, your formula is ambiguous; it is not clear which pair of parentheses to insert in order to get a binary tree. Both $\qquad \displaystyle \varphi_1 \lor (\varphi_2 \lor \varphi_3)$ and $\qquad \displaystyle (\varphi_1 \lor \varphi_2) \lor \varphi_3$ are feasible. Luckily for you, $\lor$ is associat...
|formal-languages|logic|binary-trees|parsing|
Let $A$ be an adjacency matrix of a directed graph. What's the meaning of the $(i,j)-$entry of the matrix $((A^T)^{7} \cdot (A^{7}))$ ? My initial interpretation is that $(i,j)$ of this matrix is zero whenever nodes $i$ and $j$ have no 7-length in-coming paths from a common source. Is that right? Any attention is a...
Meaning of the adjacency matrix product