Problem Detail: Let $qquad L = {a^n mid exists_{p geq n} p,, p+2 text{ are prime}}.$ Is $L$ regular? This question looked suspicious at the first glance and I’ve realized that it is connected with the twin prime conjecture. My problem Read More …
Blog
[Solved]: Are there languages generated by linear grammar which aren’t regular?
Problem Detail: Are there languages generated by linear grammer which aren’t regular? Asked By : Iancovici Answered By : Shaull Of course. Look at the first example on Wikipedia: $qquad S to aSb mid varepsilon$ is linear and generates ${a^nb^n mid n in Read More …
[Solved]: Proving that the language of TMs with finite left head moves is undecidable
Problem Detail: I’m trying to prove that the following language is undecidable:$$ { langle M, w rangle ~|~ M text{ is a TM where its head moves left a finite number of times on } w } $$ But I’m having Read More …
[Solved]: Travelling with the most efficient path
Problem Detail: A friend of mine actually asked me a very interesting computer science related question, and I have been stuck on it for a long time. The problem is: you have to travel $1000$ km. The only gas station is Read More …
[Solved]: Fast implementation of basic addition algorithm
Problem Detail: Write code for a modified version of the Grade School addition algorithm that adds the integer one to an m-digit integer. Thus, this modified algorithm does not even need a second number being added. Design the algorithm to Read More …
[Solved]: Show that a regular language L contains only palindromes if and only if all words of length at most 3n are palindromes
Problem Detail: This is an extension of a previous question asked by a different user earlier: Let $x, u, v, w, y, x’, u’, v’, w’, y’$ be words satisfying $y’x’ = xy$. $y’u’x’ = xuy$. $y’v’x’ = xvy$. $y’w’x’ = Read More …
[Solved]: What is the time complexity of this atrocious algorithm?
Problem Detail: This grew out of a discussion of deliberately bad algorithms; credit to benneh on the xkcd forums for the pseudocode algorithm, which I’ve translated to Python so you can actually run it: def sort(list): if len(list) < 2: return Read More …
[Solved]: In the Gas-Up problem, how is the amount of gas the same up to a cyclic shift regardless of starting city?
Problem Detail: I’m working through Elements of Programming Interviews as practice for finding a job. I’ve spent a ridiculous amount of time on Problem 18.7. In the gas-up problem, $n$ cities are arranged on a circular road. You need to visit Read More …
[Solved]: Counting subarrays that satisfy either of two conditions
Problem Detail: We have an array of integers $a[]$, with each $|a[i]| leq 10^{6}$, $size(a)leq10^{5}$, and $a[i]-a[i-1]leq100$. Then we define the term range as a subarray $[x,y]$ of the array $a[]$, $x lt y$. We need to find total number of Read More …
[Solved]: Finding farthest item in an array with duplicates
Problem Detail: I have an array $A[]$ of size $L$, which contains numbers in the range $1 ldots N$. Here $L>N$, so the array will contain repetitions. If $x,y$ are two numbers that are both present in the array, define the Read More …