instruction
stringlengths
0
29.8k
⌀
You are almost there. "If yes then an index $i$ that satisfies $a[i]<a[i+1]$, will surely appear on the right side"; so continue searching on the right side. If no, continue searching on the left side. ------ The idea is to find two elements, the left of which is smaller than the right of which such that their p...
I need to write a function that gets an array of numbers $a$ as an input and returns an index $i$ such that $a[i]<a[i+1]$ if it exists, if such $i$ doesn't exist return $-1$. (return any index $i$ if there are multiple). <br> We know that: in $a$ there are at least $2$ elements, $a$ may or may not be sorted and the fi...
How can I apply binary search to find two adjacent increasing elements in an unsorted array?
In Arora and Barak's textbook, in chapter 18, p.366-367, they prove the following theorem: > Theorem 18.7 if $(L,D)$ is reduced to $(L',D')$ and $(L',D') \in disP$, then $(L,D) \in disP$ The proof goes by just following the definition of average-case reduction and disP. I.e., suppose there is an efficient algorit...
A minor issue on the proof of "if (L',D') is easy, then so is (L,D)" in Average-case Complexity!
|complexity-theory|average-case|
null
The length of the shortest program to produce a given string is known as the [Kolmogorov complexity](https://en.wikipedia.org/wiki/Kolmogorov_complexity) of that given string. (Of course, some details are needed to give a formal definition, but this is the idea.) A proof of undecidability goes roughly as follows: - Th...
You are almost there. "If yes then an index $i$ that satisfies $a[i]<a[i+1]$, will surely appear on the right side"; so continue searching on the right side. If no, continue searching on the left side. ------ The idea is to find two elements, the left of which is smaller than the right of which such that their p...
**Lemma:** For any $i<j$, if $A[i]<A[j]$, there are certainly two neighboring elements in $A[i..j]$ such that $A[k]<A[k+1]$. Otherwise, the subarray would be non-increasing and this contradicts $A[i]<A[j]$. **Algorithm:** The dichotomy is based on the following rule: - take $k$ to be the midpoint of $i$ and...
You are almost there. "If yes then an index $i$ that satisfies $a[i]<a[i+1]$, will surely appear on the right side"; so continue searching on the right side. If no, continue searching on the left side. ------ The idea is to find two elements, the left of which is smaller than the right of which such that their p...
null
in my Complexity class I have to present the 1/2 **MaxSat approximation algorithm** that appears in the Vazirani, Vijay V - Approximation algorithms-Spring (2011) [Image attached]. The problem is that it is not clear to me where and how the **weights** are assigned. The example talks about considering the weights as a...
Could someone give me an example of MaxSat's approximable 1/2 algorithm?
|maxsat|
You are almost there. "If yes then an index $i$ that satisfies $a[i]<a[i+1]$, will surely appear on the right side"; so continue searching on the right side. If no, continue searching on the left side. #### Binary Search The idea is to find two elements, the left of which is smaller than the right of which such ...
I saw this question on the internet and found many solutions actually but none of them really persuade me that much. ***Question:*** Given language $L$ which is accepted by a Turing machine $M$, provide a 2-PDA that describes $L$. End of the question. ***Note:*** A Turing machine is given by $M=\{Q,\Sigma,\Gamma...
Build a 2-PDA for language accepted by Turing Machine
|turing-machines|pushdown-automata|computation-models|
null
I'll answer using the words instanceof (instead of inhabitant) and Class (instead of Type) since these are the terms in UML. It seems to me that you are thinking about classes anb subclasses like sets of individuals and subsets of individuals. However, I would suggest, following [1], interpreting a class as a set of...
Some time ago I had in one of the big tech interviews the following question that I still don't know how to approach it. You have a chains of reservations from AirBnb: reservations:[ {user = 1, res_id = 1001, checkin = 100, checkout = 101}, {user = 2, res_id = 1002, checkin = 104, checkout =...
|algorithms|data-structures|path|
null
An alternative way of deciding within a nondeterministic complexity class is to present a verifier-prover pair. To recall, let $\mathsf{L}$ be a language, and let $\mathsf{w}$ be a word. To decide whether $\mathsf{w} \in \mathsf{L}$: * The prover, a magical machine, will immediately find a proof that $\mathsf{w} \i...
Whose fault is that $\mathsf{\text{NOT-HALT}}$ is not in $\mathsf{RE}$?
|computability|undecidability|nondeterminism|
|computability|undecidability|halting-problem|nondeterminism|
Are Unit Tests Required if you have a good End to End Test? If you find problems, couldn't you always just update the end to end test to make it more robust?
Are Unit Tests Required if you have a good End to End Test?
|software-testing|
null
I'm looking at a problem similar to an assignment problem. There are both agents and tasks. Each agent has a list of tasks they are able to do, and cannot do any task not within that list (note that agents do not have a preference for what task they do, only a list of tasks they are able to do). A task can be assign...
Variation of Assignment Problem to maximize amount of agents working
|algorithms|graphs|
I'm looking at a problem similar to an assignment problem. There are both agents and tasks. Each agent has a list of tasks they are able to do, and cannot do any task not within that list (note that agents do not have a preference for what task they do, only a list of tasks they are able to do). A task can be assign...
If $A$ and $B$ are languages, let $A\bowtie B$ denote the set of strings made by concatenating any word from $A$ and any word from $B$ of equal length. $$A\bowtie B \equiv \{ ab : a\in A,\;b\in B, |a|=|b|\}.$$ You can prove using regular grammars that if $A$ and $B$ are regular, then $A\bowtie B$ is context free....
Context-free languages can't count and compose?
|context-free|
It's the prover's fault: there is no way to decide whether an arbitrary TM will halt or run forever, and so there is no certificate that can correctly establish that an arbitrary TM will halt. If $L$ is not recursively enumerable, then no machine can simultaneously: 1. Halt on every input $\langle w, c\rangle$ (a w...
If $A$ and $B$ are languages, let $A\bowtie B$ denote the set of strings made by concatenating any word from $A$ and any word from $B$ of equal length. $$A\bowtie B \equiv \{ ab : a\in A,\;b\in B, |a|=|b|\}.$$ You can prove using regular grammars that if $A$ and $B$ are regular, then $A\bowtie B$ is context free....
It's the prover's fault: there is no way to decide whether an arbitrary TM will halt or run forever, and so there is no certificate to prove that an arbitrary TM will run forever. If $L$ is not recursively enumerable, then no machine can simultaneously: 1. Halt on every input $\langle w, c\rangle$ (a word and a pro...
I'm looking at a problem similar to an assignment problem. There are both agents and tasks. Each agent has a list of tasks they are able to do, and cannot do any task not within that list (note that agents do not have a preference for what task they do, only a list of tasks they are able to do). A task can be assign...
If the non-blank region of the Turing tape looks like $$ \begin{bmatrix}a_1&a_2& \ldots& a_n& \check{x} &b_1&\ldots& b_m\end{bmatrix}$$ where $\check{x}$ denotes the current position, then the two stacks should look roughly like $$\begin{bmatrix}a_n\\a_{n-1}\\a_{n-2}\\\vdots \\ a_1\end{bmatrix} \begin{bmatrix}x\\b_...
null
I'm looking at a problem similar to an assignment problem. There are both agents and tasks. Each agent has a list of tasks they are able to do, and cannot do any task not within that list (note that agents do not have a preference for what task they do, only a list of tasks they are able to do). A task can be assign...
Conjecture: a half of a context-free language must be a regular language
|regular-languages|context-free|open-problem|
No, this conjecture is not true. Consider $A=\{a^nb^n \mid n\ge0 \}$ and $B=\{b^{2n}\mid n\ge0\}$. We have $\{|a| : a\in A\}=\{|b| : b\in B\}=\{2n\mid n\ge0\}$ and $A\bowtie B \equiv \{ a^nb^{3n}\mid n\ge0\}$. While $A\bowtie B$ is context-free, $A$ is not.
No, this conjecture is not true. Consider $A=\{a^nb^n \mid n\ge0 \}$ and $B=\{b^{2n}\mid n\ge0\}$. We have $\{|a| : a\in A\}=\{|b| : b\in B\}=\{2n\mid n\ge0\}$ and $A\bowtie B \equiv \{ a^nb^{3n}\mid n\ge0\}$. While $A\bowtie B$ is context-free, $A$ is not regular.
null
It's the prover's fault: there is no way to decide whether an arbitrary TM will halt or run forever, and so there is no certificate to prove that an arbitrary TM will run forever. If $L$ is not recursively enumerable, then no machine can simultaneously: 1. Halt on every input $\langle w, c\rangle$ (a word and a pro...
null
null
I was watching this video https://www.youtube.com/watch?v=U1JYwHcFfso&list=PLUl4u3cNGP63EdVPNLG3ToM6LaEUuStEY&index=10 about binary trees and at minute 41:22 the teacher states that 2*N[h-2] = 2^(h/2) {where N stands for the number of nodes in a subtree of height h-2}. Can someone explain me in more detail why this rec...
Why a recurrence of 2*N[h-2] is equal to 2^(h/2)?
|recursion|binary-trees|subtree|
I was watching video [*7. Binary Trees, Part 2: AVL*](https://youtu.be/whjt_N9uYFI?t=3859), where professor Erik Demaine stated that $$2N_{h-2} = 2^{h/2\text{ (or maybe with floor or something... maybe it's ceiling)}}$$ where $N$ stands for the number of nodes in a subtree of height $h-2$. Can someone explain me in mor...
Why is a recurrence of $2N_{h-2}$ equal to $2^{h/2}$?
Is there a communication protocol that ensures that both parties can read the other one's message at the same time (or at the very least, only after sending their own message, thus no party can read a message and then send their own).
Communication protocol so that messages are read "synchronously"
|communication-protocols|
null
null
In the operating systems that make use of the execution-time address binding who is responsible for the creation of logical addresses?
Execution-time address binding, logical addresses creation
|operating-systems|
In the lecture it was shown that $N_h \leq 2N_{h-2}$. You can obtain the bound of $2^{h/2} $ for this recurrence by continued expansion of the r.h.s., also called unrolling the recurrence. E.g. : $N_h \leq 2 * (2N_{h-4}) \leq 2*(2*(2N_{h-6})) \leq 2(2(2(...(2N_0)...)))$. This expansion will continue until you rea...
In the lecture it was shown that $N_h \leq 2N_{h-2}$. You can obtain the bound of $2^{h/2} $ for this recurrence by continued expansion of the r.h.s., also called unrolling the recurrence. E.g. : $N_h \leq 2N_{h-2} \leq 2 * (2N_{h-4}) \leq 2*(2*(2N_{h-6})) \leq 2(2(2(...(2N_0)...)))$. This expansion will continue...
With C# I can convert an array of bytes to a decimal value: //F4 6C 56 7D AE C6 4B 40 var bytes = new byte[] { 244, 108, 86, 125, 174, 198, 75, 64 }; var value = BitConverter.ToDouble(bytes, 0); //=55.5522 I would like to know how this works and be able to express it by hand on paper.
How to mathematically convert an array of bytes to a decimal value
|logic|
**Lemma:** For any $i<j$, if $A[i]<A[j]$, there are certainly two neighboring elements in $A[i..j]$ such that $A[k]<A[k+1]$. Otherwise, the subarray would be non-increasing and this contradicts $A[i]<A[j]$. **Algorithm:** The dichotomy is based on the following rule: - take $k$ to be the midpoint of $i$ and...
A random language is neither recognizable nor co-recognizable almost surely. Every language which is complete for $\Sigma_k$ or $\Pi_k$, for any $k \geq 2$ (these are classes in the [arithmetical hierarchy](https://en.wikipedia.org/wiki/Arithmetical_hierarchy)), is neither recognizable nor co-recognizable. Some exam...
In the operating systems that make use of the execution-time address binding who is responsible for the creation of logical addresses? EDIT I'm thinking that the logical addresses are generated by the compiler and are included in the relocatable code
This isn't really a CS question, more of a Software Engineering question. Still: If you find an error in an end-to-end test, and you can then replicate it in a simpler unit test, then you definitely should create that unit test. Unit tests have the big advantage of pinpointing _where_ in your code a problem exists. ...
No, this conjecture is not true. Consider $A=\{0^n1^n \mid n\ge0 \}$ and $B=\{1^{2n}\mid n\ge0\}$. We have $\{|a| : a\in A\}=\{|b| : b\in B\}=\{2n\mid n\ge0\}$ and $A\bowtie B \equiv \{ 0^n1^{3n}\mid n\ge0\}$. While $A\bowtie B$ is context-free, $A$ is not regular. <!-- As noted by Pseudonym, this example s...
According to [Wikipedia][1], a closed-form formula for the number of unlabelled trees is not known, so a numbering in the form of a bijection between the set of unlabelled trees on $n$ vertices and $\{1,\ldots,T_n\}$ (for an appropriate $T_n$) is probably hopeless. [Tree isomorphism is in P][2], so if you want an "effe...
null
null
Admissible path-systems are, indeed, P-complete under many-one logspace reductions. On the paper [1] we can see that Cook, given a Turing Machine $M$ that runs in $T(n)$ and some input $w$, builds a path-system problem that is admissible iff $M$ accepts $w$. Hence, the reduction is many-one. The reduction is logs...
No, this conjecture is not true. Consider $A=\{0^n1^n \mid n\geqslant0 \}$ and $B=\{1^{2n}\mid n\geqslant0\}$. We have $\{|a| : a\in A\}=\{|b| : b\in B\}=\{2n\mid n\geqslant0\}$ and $A\bowtie B = \{ 0^n1^{3n}\mid n\geqslant0\}$. While $A\bowtie B$ is context-free, $A$ is not regular. <!-- As noted by Pseudo...
null
[Exchange sort](https://en.wikipedia.org/wiki/Sorting_algorithm#Exchange_sort) is similar to selection sort, just swaps "overly eagerly" instead of finding the minimum and doing only one swap. And the swaps affect how often the `if ...` is true. For example for 8000 random numbers, in exchange sort it's true ~270 times...
Number of trues in Selection sort vs Exchange sort
|algorithms|sorting|python|
I think this question was answered in ["The Trouble with Locks"](https://www.drdobbs.com/cpp/the-trouble-with-locks/184401930?pgno=2) (Dr. Dobb's Journal, 1 March 2005), which article indicates that his "I'll have more to say about that soon" was more about the problems of lock-based programming than about a specific...
null
I am trying to understand how $\Theta(n), O(n), \text{ and } \Omega(n)$ relate to each other as sets and want to make sure I'm on the right track. I get that $Θ(n) \subseteq O(n)$ since $Θ(n)$ is stronger and all of its elements are also in $O(n)$. Then $Θ(n) ⊆ Ω(n)$ is true too, yes? But $O(n) \subseteq Ω...
$Θ, O$ and $Ω$, and how they relate to each other as subsets
|algorithm-analysis|asymptotics|runtime-analysis|discrete-mathematics|big-o-notation|
null
I am trying to understand how $\Theta(n)$, $O(n)$, and $\Omega(n)$ relate to each other as sets and want to make sure I'm on the right track. I get that $Θ(n) \subseteq O(n)$ since $Θ(n)$ is stronger and all of its elements are also in $O(n)$. Then $Θ(n) ⊆ Ω(n)$ is true too, yes? But $O(n) \subseteq Ω(n)$ isn...
Θ, O and Ω, and how they relate to each other as subsets
**I am stuck on what to do.** I am trying to create a simple implementation of the **[Flajolet–Martin algorithm][1]** using Python. The stream will be the contents of a text file and you will produce an approximation of the number of unique words in the file as given by the algorithm. You will need to process the ...
Implementing Flajolet–Martin algorithmin Python
|algorithms|hash|python|hashing|streaming-algorithm|
null
Implementing Flajolet–Martin algorithm in Python
I am blocked with this question for a long time. $L = \{w\# w ' |$ where $w < w'$ lexicographically, and $w,w'\in \{0,1\}^* \}$ I am trying to find 1. A Deterministic Turing Machine for L. 2. A Non-Deterministic Turing Machine for L. **Example** - $01\#111 \in L$ since $ w=01$ and $w=111$ and $01 ...