instruction stringlengths 0 29.8k ⌀ |
|---|
I am reading chapter 32 -String Matching from the book ["Introduction to Algorithms" 3rd edition Cormen et al][1]. The Rabin-Karp Algorithm is not clear despite reading several times. Specifically, when the authors start proposing about some modulo operations for solving some problem, I am unable to understand. To be... |
I am reading chapter 32 -String Matching from the book ["Introduction to Algorithms" 3rd edition Cormen et al][1]. The Rabin-Karp Algorithm is not clear despite reading several times. Specifically, when the authors start proposing about some modulo operations for solving some problem, I am unable to understand. To be... |
null |
I am reading chapter 32 -String Matching from the book ["Introduction to Algorithms" 3rd edition Cormen et al][1]. The Rabin-Karp Algorithm is not clear despite reading several times. Specifically, when the authors start proposing about some modulo operations for solving some problem, I am unable to understand. To be... |
I asked a similar question [here][1] on Rabin Karp Algorithm. My present question is how do we find best q (i.e modulus)? What is the criteria? we need to choose a q , which will be quick to calculate and also must result in lesser number of spurious hits. right?
how do we make sure these things?
[1]: htt... |
How do we find optimum modulus q, in Rabin-Karp Algorithm? |
|algorithms|searching| |
I have a deterministic finite automaton which behaves mostly like a Turing machine, with following difference (relevant to this question):
- The tape is initially finite.
- The automaton can insert and delete cells from the tape.
- Actions are associated with states rather than with transitions (this includes head... |
Minimizing Turing machine-like automaton with no final states |
|turing-machines|automata|finite-automata| |
What exactly is the difference between your machine and a TM? (apart from not having accepting states, which is quite meaningless since you have an output)
It sounds like this is a very powerful model, and its halting problem will be undecidable, let alone minimization.
|
What exactly is the difference between your machine and a TM? (apart from not having accepting states, which is quite meaningless since you have an output)
It sounds like this is a very powerful model, and its halting problem will be undecidable, let alone minimization.
EDIT: Minimizing TMs is undecidable (actual... |
I've been reading a bit about Hierarchical Temporal Memory and Memory Prediction. I found a great paper: HOW THE BRAIN MIGHT WORK: A HIERARCHICAL AND TEMPORAL MODEL FOR LEARNING
AND RECOGNITION.
I was searching google, to see if such a big network has been deployed somewhere, but i found no results. I know that nu... |
Why isn't there a big HTM machine already? |
|artificial-intelligence| |
I am looking to generate a heat map from some data. I have a value and a location (longitude and latitude). I understand generating a colour from the value, however I'm not sure how I would go about generating the matrix to use for this.
I figure it's best to place the location points into buckets essentially (so t... |
Algorithm for generating heat maps |
|algorithms|matrices| |
null |
What does "number of gates" mean in circuit complexity? |
You have to interpolate the missing heat values. There's some mathematics that explains this pretty well (man, it's been a while) but, if I recall correctly, the correct physical way to do this (assuming no heat sources in the area being interpolated) is the following:
1. For each pixel for which there wasn't origin... |
Wikipedia gives great information about the complexity of various [elementary operations](http://en.wikipedia.org/wiki/Computational_complexity_of_mathematical_operations).
Multiplication takes $n^2$ time by the "school-book" algorithm, and thus it is in $\mathsf{FTIME}(n^2)$ and in $\mathsf{FL}$. Better solutions e... |
I was looking at the question [How to convert finite automata to regular expressions?][1] to convert DFA to regex.
The question, I was trying to solve is:
![enter image description here][2]
I have got the following equations:
$Q_0=aQ_0 \cup bQ_1 \cup \epsilon$
$Q_1=aQ_1 \cup bQ_1 \cup \epsilon$
When s... |
DFA to regular expression conversion |
|regular-languages|automata|finite-automata|regular-expressions| |
Given an undirected tree (with no specific root), how to find the longest path, i.e. 2 vertices that are the farthest apart from each other?
Obviously one idea is to check the path lengths between all pairs of vertices (e.g. by doing a DFS from each vertex), but there should be a more efficient solution. Please incl... |
Longest path in undirected tree |
|algorithms|graphs|trees| |
i have a problem regarding the following situation.
I have two arrays of numbers like this:
index/pos 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Array 1(i): 1 2 3 4 7 5 4 3 7 6 5 1 2 3 4 2
Array 2(j): 4 4 8 10 10 7 7 10 10 ... |
Difference between heuristic and approximation algorithm? |
|approximation|heuristics| |
I encountered this problem involving manipulating a context-free language. Let $L$ be a context-free language. Define $L^{\#} = \{ x : x^i \in L$ for every $i=0,1,2,...\}$. Is $L^{\#}$ always context-free?
My guess is that it will preserve context-freeness. Can anyone provide an elementary proof of this? |
Does the following transformation preserve context-freeness? |
|formal-languages|context-free| |
{"OriginalQuestionIds":[1970],"Voters":[{"Id":71,"DisplayName":"Joe"},{"Id":6447,"DisplayName":"vonbrand"},{"Id":1636,"DisplayName":"Luke Mathieson"},{"Id":72,"DisplayName":"JeffE"},{"Id":169,"DisplayName":"uli"}]} |
I'll be using the solution to $Q = \alpha Q + \beta$ given by $Q = \alpha^* \beta$, essentially as you would go solving a system of linear equations by hand:
$$
\begin{align*}
Q_0 &= a Q_0 \cup b Q_1 \cup \epsilon \\
Q_1 &= (a \cup b) Q_1 \cup \epsilon
\end{align*}
$$
From the first equation you have $Q_0 = a^... |
A _heuristic_ is essentially a hunch, i.e., the case you describe ("I noticed it is near", you don't have a _proof_ it is so) is a heuristic. As is solving the [traveling salesman problem][1] by starting at a random vertex and going to the nearest not yet visited each step. It is a _plausible_ idea, that _should not_ g... |
null |
Counter-example: Let $L_1, L_2$ be context-free and containing the empty word, with $L_1 \cap L_2$ being not context-free (CF is not closed under intersection). $L = L_1 \cdot L_2^*$ is also context-free. Then $L^\# = L_1 \cap L_2$, which is not context-free. |
{"Voters":[{"Id":4832,"DisplayName":"Simon S"}]} |
Given an undirected tree (with no specific root), how to find the longest path, i.e. 2 vertices that are the farthest apart from each other? There are no lengths associated with the edges (each edge has length 1 by default).
Obviously one idea is to check the path lengths between all pairs of vertices (e.g. by doing... |
First, lists are a kind of trees. If we represent a list as a [linked list](https://en.wikipedia.org/wiki/Linked_list), it's just a [tree](https://en.wikipedia.org/wiki/Tree_(computer_science)) whose each node has either 1 or 0 descendants.
Parse trees are just an utilization of trees as a data structure. Trees have... |
Counter-example: Let $L_1, L_2$ be context-free with
- $L_1 \cap L_2$ being not context-free (CF is not closed under intersection).
- $\epsilon \not \in L_1$
$L = (L_1 \cdot L_2^*) \cup \epsilon$ is also context-free. Then $L^\# = (L_1 \cap L_2)\cup \epsilon$, which is not context-free. |
{"Voters":[{"Id":4832,"DisplayName":"Simon S"}]} |
Counter-example: Let $L_1, L_2$ be context-free with
- $L_1 \cap L_2$ being not context-free (CF is not closed under intersection).
- $\epsilon \not \in L_1$
- $L_1^\# = \{\} $
$L = (L_1 \cdot L_2^*) \cup \epsilon$ is also context-free. Then $L^\# = (L_1 \cap L_2)\cup \epsilon$, which is not context-f... |
{"Voters":[{"Id":4832,"DisplayName":"Simon S"}]} |
Counter-example: Let $L_1, L_2$ be context-free with
1. $L_1 \cap L_2$ being not context-free (CF is not closed under intersection).
2. $L_1^\# = \{\} $ (which implies $\epsilon \not \in L_1$)
3. $w \in L_1 \setminus L_2 \rightarrow \forall v \in L_2 : w$ is not prefix of $v$
$L = (L_1 \cdot L_2^*) \c... |
You can see this very interesting answer about [Heuristic][1] in Wikipedia:
"
a heuristic is a technique designed for solving a problem **more quickly** when **classic methods** are too slow. The objective of a heuristic is to produce quickly enough a solution that is good enough for solving the problem at hand. ".... |
Counter-example: Let $L_1, L_2$ be context-free with
1. $L_1 \cap L_2$ being not context-free (CF is not closed under intersection)
2. $L_1^\# = \{\} $ (which implies $\epsilon \not \in L_1$)
3. $w \in L_1 \setminus L_2 \rightarrow \forall v \in L_2 : w$ is not prefix of $v$
$L = (L_1 \cdot L_2^*) \cu... |
Counter-example: Let $L_1, L_2$ be context-free with
1. $L_1 \cap L_2$ being not context-free (CF is not closed under intersection)
2. $L_1^\# = \{\} $ (which implies $\epsilon \not \in L_1$)
3. $w \in L_1 \setminus L_2 \rightarrow \forall v \in L_2 : w$ is not prefix of $v$
$L = (L_1 \cdot L_2^*) \cu... |
Counter-example: Let $L_1, L_2$ be context-free with
1. $L_1 \cap L_2$ being not context-free (CF is not closed under intersection)
2. $w \in L_1 \rightarrow \forall n > 1 : w^n \not \in L_1$ (which implies $\epsilon \not \in L_1$)
3. $w \in L_1 \setminus L_2 \rightarrow \forall v \in L_2 : w$ is not pre... |
I think one solution is to do a single DFS (from any node) to determine the longest path. Apologies in advance for the clumsiness of the description - I'm not sure what's the proper notation for these things.
First, some background: at each step of the DFS we're exploring a subtree T, with the current vertex R consi... |
I think one solution is to do a single DFS (from any node) to determine the longest path, in "divide and conquer" fashion. Apologies in advance for the clumsiness of the description - I'm not sure what's the proper notation for these things.
First, some background: at each step of the DFS we're exploring a subtree T... |
I think one solution is to do a single DFS (from any node) to determine the longest path, in "divide and conquer" fashion. Apologies in advance for the clumsiness of the description - I'm not sure what's the proper notation for these things.
First, some background: at each step of the DFS we're exploring a subtree T... |
null |
I would use breath-first search and dynamic programming.
Let $A$ be a matrix where $A[i,j]$ is the distance between $v_i$ and $v_j$.
As we are in a tree, there are no loops and you can just counting the distances by taking the distances to the previous vertex and adding 1 to them.
Let $v_v$ a vertex that has a... |
Counter-example:
$L_1 = \{a^n b^n c^m \mid m,n \ge 1 \}$
$L_2 = \{a^m b^n c^n \mid m,n \ge 1 \}$
$L = (L_1 \cdot L_2^*) \cup \epsilon$ is context-free.
Any nonempty $x \in L^\#$ can have
Then $L^\# = (L_1 \cap L_2)\cup \epsilon$ (which is not context-free), because any nonempty $x \in L^\#$ has a prefix... |
I think one solution is to do a single DFS (from any node) to determine the longest path, in "divide and conquer" fashion. Apologies in advance for the clumsiness of the description - I'm not sure what's the proper notation for these things.
First, some background: at each step of the DFS we're exploring a subtree T... |
From http://rjlipton.wordpress.com/2009/05/27/arithmetic-hierarchy-and-pnp/,
> Define, $M_{[x,c]}$ as the deterministic Turing machine that operates
> as follows on an input $y$. The machine treats $x$ as a deterministic
> program, and simulates $x$ on input $y$. At the same time the machine
> runs a counter that... |
How to relate circuit size to the running time of Turing machine |
Counter-example:
$L_1 = \{a^n b^n c^m \mid m,n \ge 1 \}$
$L_2 = \{a^m b^n c^n \mid m,n \ge 1 \}$
$L = (L_1 \cdot L_2^*) \cup \epsilon$ is context-free.
Any nonempty word $x \in L^\#$ has a prefix $p = a^n b^n c^m \in L_1$. It must be $n = m$, because due to $L_2$, any pair of a $b^+$ and a directly succeedi... |
Counter-example:
$L_1 = \{a^n b^n c^m \mid m,n \ge 1 \}$
$L_2 = \{a^m b^n c^n \mid m,n \ge 1 \}$
$L = (L_1 \cdot L_2^*) \cup \epsilon$ is context-free.
Any nonempty word $x \in L^\#$ has a prefix $p = a^n b^n c^m \in L_1$. It must be $n = m$, because due to $L_2$, any pair of a $b^+$ and a directly succeedi... |
{"Voters":[{"Id":4832,"DisplayName":"Simon S"}]} |
As for your last question, there is no separate theory for approximation algorithms for problems that are solvable in polynomial time. In fact, it might be that $\mathsf{P}=\mathsf{NP}$. Some examples of approximation algorithms for problems in $\mathsf{P}$ include algorithms for numerical linear algebra and computatio... |
I was looking at the question [How to convert finite automata to regular expressions?][1] to convert DFA to regex.
The question, I was trying to solve is:
![enter image description here][2]
I have got the following equations:
$Q_0=aQ_0 \cup bQ_1 \cup \epsilon$
$Q_1=aQ_1 \cup bQ_1 \cup \epsilon$
When s... |
I'll be using the solution to $Q = \alpha Q \cup \beta$ given by $Q = \alpha^* \beta$, essentially as you would go solving a system of linear equations by hand:
$$
\begin{align*}
Q_0 &= a Q_0 \cup b Q_1 \cup \epsilon \\
Q_1 &= (a \cup b) Q_1 \cup \epsilon
\end{align*}
$$
From the first equation you have $Q_0 =... |
null |
Programmers do sometimes write a program that creates infinite loop if some particular input is passed into the program.
But Simply-typed lambda calculus has to stop - so the question is, can anyone show some "useful" program in Turing-complete language (e.g. untyped lambda calculus) that does not go into infinite l... |
A program that cannot be written in (simply-)typed lambda calculus but only in lambda calculus or Turing-complete language |
|complexity-theory|computability|programming-languages|lambda-calculus| |
null |
null |
null |
null |
Take a look at Floyd's algorithm. I would also suggest reading up on how to permute co-ordinates to generate Hamiltonian paths through n-dimensional space. Gray codes mutate one bit at a time and are related to the problem you state. As an aside, I don't understand how you can define a point in n-dimensional space with... |
It's easy: first get the 1st dimension right, then the 2nd dimension, then the 3rd dimension, etc.
For example, if you want to get from $(1,3,0)$ to $(3,4,1)$, you go via the following sequence of points: $(1,3,0), (2,3,0), (3,3,0), (3,4,0), (3,4,1)$. |
I have a n-dimensional grid space with two points on it defined by ordered pairs. I want to find the shortest path between the two points, but I can only increase one number in the ordered pair at a time. **Is there a algorithm for this or at least one I can refer to**? |
Finding the shortest path through a n-dimensional space |
|untagged| |
Wikipedia gives great information about the complexity of various [elementary operations](http://en.wikipedia.org/wiki/Computational_complexity_of_mathematical_operations).
Multiplication takes $n^2$ time by the "school-book" algorithm, and thus it is in $\mathsf{FTIME}(n^2)$ and in $\mathsf{FL}$. Better solutions e... |
The distinction isn't just about being able to write non-terminating programs. There are significant differences even between normalizing lambda calculi. For example, consider [System F](https://en.wikipedia.org/wiki/System_F). It's normalizing, so all its programs are terminating (so it's not Turing complete), but it ... |
Programmers do sometimes write a program that creates infinite loop if some particular input is passed into the program.
But Simply-typed lambda calculus has to stop - so the question is, can anyone show some "useful" program in Turing-complete language (e.g. untyped lambda calculus) that does not go into infinite l... |
Its the best you can do. Because its the minimum distance.
Its like driving [taxicab](http://en.wikipedia.org/wiki/Taxicab_geometry) in n-dimensional space.
$$d(P,Q) = \sum\limits_{i = 1}^{n} | P_i - Q_i|$$
P and Q are points in n-dimensional space and $P_i$ is gives $i^{th}$ co-ordinate of P.
It will t... |
In many discussions of binary heap, normally only decrease-key is listed as supported operation for a min-heap. For example, CLR chapter 6.1 and [this wikipedia page](http://en.wikipedia.org/wiki/Heap_(data_structure)). Why isn't increase key normally listed for min-heap? I imagine it is possible to do that in O(height... |
Increase-key and decrease-key in a binary min-heap |
|algorithms|data-structures|heaps|priority-queues| |
The min-heap property states that for each node, its value is smaller than all the elements in its right and left subtrees.
When you increase a key, this property may be broken for a *parent* of the node you increased. How will you take care of that? |
{"Voters":[{"Id":6890,"DisplayName":"Shaull"}]} |
The algorithm you suggest is simply heapify. And indeed - if you increase the value of an element in a min-heap, and then heapify its subtree, then you will end up with a legal min-heap. |
{"Voters":[{"Id":6890,"DisplayName":"Shaull"}]} |
sorry for my english. that is my question, the non regular languajes has clouser operations ? if the reverse of L is non regular, then L is non regular ? thank you :-) |
has the non-regular languages properties like reverse, union, concatenation, etc? |
|regular-languages| |
Well, if $L$ is regular, then $L^{R}$ is also regular. The contra-positive of this is that if $L^{R}$ is non-regular, then $L$ is non-regular... |
I am writing a functional style interpreter for a non-functional programming language that supports both primitive and object values. Primitives are passed by value while objects are passed by reference. I understand how to deal with primitive values but cannot find any good resources on handling mutable object values.... |
Mutable Object Values in a Functional Interpreter |
|programming-languages| |
Non regular languages are closed under reverse, because $L = (L^R)^R$. Same is true for complement.
Non regular languages are not closed under most other basic operations though. Consider, for example, that $L \cup \overline{L} = \Sigma^\star$. Similarly, if $L = \{1^{x^2} | x > 1\}$ then $\overline{L} \circ \overli... |
null |
I am reading William Stallings Computer Organization & Architecture to understand about control unit & micro-operations.
Stallings explain that interrupt cycle requires 3 time units to complete :
t1 : MBR <- (PC)
t2 : MAR <- Save_Address
PC <- Routine_Address
t3 : Memory <- (MBR)
t1 ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.