I have a language consisting of all Turing machines that only accept words "σ" with |σ| ≤ 200 and I need to determine if it is decidable, but it doesn’t look like any problem I have solved before. Any ideas?

# Tag: length

## Encoding a arbitrary stack trace into a fixed length value

**Background**

I would like to store the nodes of a Calling Context Tree using in a key value store. I need to be able to directly access a node by it’s method name and complete stack trace. In addition in need to access all nodes of a method by only it’s name (the key value store supports a loading based on prefix).

**Problem**

The first idea is to use the method name + an encoded stack trace as key, e.g. the concatenated string representations. Unfortunately this can get quite large and I cannot use keys of arbitrary length. So the second idea was to encode the stack trace in a deterministic and reversible way. So my next idea was to encode the stack trace in a 64 bit integer, by adding the 32 bit hash representations of the methods in the stack. Unfortunately this is not collision free as the traces A -> B -> C and B -> A -> C compute to the same values even though the traces are different. So my current idea is to encode the traces by:

`encodeStacktrace(stack_trace) 1. 64bit current = 0 2. For every method m in stack_trace 3. current = rotateLeft(current) + hash(m) 4. return current `

They key is then method name concatenated with the encoded stack trace value.

**Question**

Is this implementation collision safe? I think not 100% however I don’t know how to compute the probability under the assumption that the method hash computation is a perfect hashing algorithm.

If it is not safe, are there other implementations/directions I can look into?

## Number of words of length n for special language

Let $ \Sigma$ be an alphabet and let $ L$ be a language over it with the following properties:

- if $ w\in L$ then there exists $ v\in \Sigma^*$ such that $ wv \in L$ and for every $ s\in \Sigma$ the word $ wvs$ does not lie in $ L$
- $ wv\in L$ then $ vw \in L$
- It is prefix-closed, i.e. prefix of any word is still in the language.

Note that by the definition, it is not cyclic language. I’m trying to compute its growth function, by that I mean $ \gamma_n:= |\{w\in L \mid |w| = n\}|$ . I know about my specific case that it is not regular and my hypothesis is that function $ \Gamma(x) = \sum_{n=1}^\infty \gamma_nx^n$ is not rational. However, I couldn’t find any information about these functions for non-regular languages. Maybe, there’s a formula that connects entropy of language, i.e. $ e(L):= \limsup\limits_{n\to\infty} \frac{\log\gamma_n}{n}$ and the $ \Gamma$ function. Or for such a language there’s a way to describe its growth throughout the growth of the language $ \operatorname{End}(L) = \{ w\in L \mid \forall s\in \Sigma \,ws \text{ is not in } L \}$ .

## Find number of ways to create sequence $A$ of length $n$ satisfying $m$ conditions

Find number of ways to create sequence $ A$ of length $ n$ satisfying $ m$ conditions. This sequence $ A$ should consist of only non negative numbers. Each condition is described by three integers $ i,j,k$ signifying $ max$ ($ A_{i}$ ,$ A_{j}$ )=$ k$ .

It is guaranteed that each index of the sequence will be there in at least one condition i.e. there will be finite number of such sequences.

The maximum value of $ n$ will not exceed $ 18$ and maximum value of $ k$ will not exceed $ 2*10^4$ .

I tried it using dynamic programming but the time complexity came out to be exponential. Can you suggest me any better approach which will reduce the time complexity?

## Find number of ways to create sequence $A$ of length $n$ satisfying $m$ conditions

Find number of ways to create sequence $ A$ of length $ n$ satisfying $ m$ conditions. This sequence $ A$ should consist of only non negative numbers. Each condition is described by three integers $ i,j,k$ signifying $ max$ ($ A_{i}$ ,$ A_{j}$ )=$ k$ .

It is guaranteed that each index of the sequence will be there in at least one condition i.e. there will be finite number of such sequences.

The maximum value of $ n$ will not exceed $ 18$ and maximum value of $ k$ will not exceed $ 10^6$ .

I tried it using dynamic programming but the time complexity came out to be exponential. Can you suggest me any better approach which will reduce the time complexity?

## What is the time complexity of sorting n words length wise and then alphabetically? Should we consider the length of the strings in the complexity?

Let’s assume I have a list of some words found in the English dictionary: ["hat", "assume", "prepare", "cat", "ball", "brave", "help" …. ]

I want to sort these words (which are n in number) in a way, such that they are ordered based on their length, but if 2 words have the same length, they are ordered alphabetically.

What is the time complexity of this sorting operation?

Would it be fair to say that the complexity is just O(nlogn) and not take into consideration the length of the strings? If the largest length is `S`

, can the complexity also involve a factor of S?

## Minimum pumping length of (01)*

Michael Sipser offers the definition:

*The pumping lemma says that every regular language has a pumping length p, such that every string in the language can be pumped if it has length p or more. If p is a pumping length for language A, so is any length p′ ≥ p. The minimum pumping length for A is the smallest p that is a pumping length for A.*

Now, (01)* in set notation is {€, 01,0101,010101….} Taking minimum pumping length = 1, according to the definition, we have the statement if a string in the language has length 1 or more, it can be pumped.

This statement is true for all elements of the above mentioned set, so can the minimum pumping length be 1?

p.s. the minimum pumping length for (01)* has been asked here before but it doesn’t answer my doubt that since the condition holds for minimum pumping length = 1, why is it not the answer?

## Finding paths of length $n$ on a directed graph

Suppose I have the following directed graph

`g = Graph[{DirectedEdge[v1, v1, a], DirectedEdge[v1, v1, OverBar[a]], DirectedEdge[v1, v2, b], DirectedEdge[v2, v2, c], DirectedEdge[v1, v3, OverBar[b]], DirectedEdge[v3, v3, OverBar[c]]}, VertexLabels -> "Name", EdgeLabels -> "Index"] `

First of all, I would prefer to label the edges with the tag of the directed edge, but I’m not sure how to do this.

The main question is, can Mathematica give me all possible paths of length $ n$ on this graph starting from, say, $ v1$ ?

## Construct a dfa and nfa for a set of strings on{0,1} : the left most symbol differs from the right most one and odd length string

Construct dfa and nfa for a set of string 0,1 such that left most and right most element are different and odd length string Can you plss draw it

## Finding simple path on grid graphs of length $l$

Let $ G$ be a grid graph and we are given two vertices $ s$ and $ t$ and $ l$ , the goal is to check if there exists a path from $ s$ to $ t$ simple path of length $ l$ ?

Brute force algorithm will give $ n^l$ time algorithm as I will simply enumerate all the paths of length $ l$ . Are there faster algorithms for this problem?

My observation is grid graphs are bipartite graphs so all paths will be either of odd length or even length but I don’t know how to use this fact. Note that in grid graphs the degree is bounded by four so from any vertice to any other vertex, number of paths of length $ l$ are bounded by $ 4^l$ . I am looking for an algorithm faster than $ 4^l$ .