instruction
stringlengths
35
29.1k
Let $L_1, L_2,...$ and $L=\cap_{k=1}^{\infty}L_k$ be languages over $\Sigma ^{*}$. Prove /Disprove: if $\forall k\in \mathbb{N} $, $L_k$ is a regular language, then $L$ is a context-free language. I know that statement is false, but couldn't find an example to disprove it. Would appreciate your help:)
Consider the language $A=\{(\phi_1, \phi_2) | \phi_1 \in SAT, \phi_2\in \overline{SAT} \}$. What is the smallest class that $A$ is known to belong to? Apparently, the answer is $\Pi_2$, although I thought it was $NP \cap coNP$, since if we have a non-deterministic machine $M_1$ that decides $SAT$ and another non-deter...
I'm working on a research project where I have to pair up entities together and analyze outcomes. Normally, without constraints on how the entities can be paired, I could easily select one random entity pair, remove it from the pool, then randomly select the next entity pair. That would be like creating a random sample...
What part of the CPU communicates with all the other parts of the processor and makes the processor faster by containing frequently used data or instructions?
I'm asking for problems for which we know there exists a solution for which an equivalent parallel program cannot be written on a Turing machine. Alternatively, have we proven the opposite to be true - that for every problem, there exists at least one parallelizable solution?
I was going through the text Introduction to Algorithms by Cormen et. al. where I came across the following statement: If the keys are known to be random real numbers $k$ independently and uniformly distributed in the range $0 \leq k < 1$ , the hash function $$h(k) = \lfloor km \rfloor$$ satisfies the condition of sim...
I have an assignment to envision and calculate the possible effects the implementation of a general sorting algorithm that is O(n) time and O(1) space ( assuming general case ) would have on computation and society. In order to do that, I am trying to estimate how much computation time computers in server farms spend o...
I was going throught the text Introduction to Algorithm by Cormen et. al. where I came across the two alternative definitions of Universal Class of Hash Function. The versions are as follows: Definition 1: Let $\mathscr{H}$ be a finite collection of hash functions that map a given universe $U$ of keys into the range $...
I have come across the following problem and I would love for your thoughts on an optimal solution or approximate calculations worth trying. The formulation of the problem in the form of graph theory: Given a weighted graph $G=(V, E)$. In addition, we have $C$ colors and $f([C_1, ...C_n])$ the distribution function of ...
I was going through the text Introduction to Algorithms by Cormen et. al. where I came across the following excerpt regarding the said proof and the steps where I felt difficulty are marked with $\dagger$ and $\dagger\dagger$ respectively. Designing a universal class of hash functions $p$ is a prime number large enough...
A non-deterministic finite automaton is considered to be halted when either the whole input string has been consumed or when we reach a state where no available transition (if any) matches the current character being read. If the machine halts when it's in an accepted state and at the same time the whole input has been...
Say you have a neural net that is being trained using back propagation and you are using relu activation. Say the input to a node is a weighted sum of the previous layer with a bias term and say for a particular data point, this weighted sum plus bias is negative. Then relu returns 0. Notice the change in the loss as a...
In Sections 5.1 of The Design of Approximation Algorithms by Williamson and Shmoys, they describe a basic randomized algorithm for MAX SAT and how to derandomize it. The algorithm is just to assign each variable 1 (true) with probability 1/2 and 0 (false) with probability 1/2. In other words, sample uniformly at random...
I read on en.Wikipedia that "Big-endian systems store the most significant byte of a word at the smallest memory address and the least significant byte at the largest. A little-endian system, in contrast, stores the least-significant byte at the smallest address." But I don't know what is "the smallest memory address",...
I am given a graph $G = (V, E)$ with $N$ connected components and $G^\prime = (V^\prime, E^\prime)$, where for each $v \in V$ there is $v_1, v_2 \in V^\prime$ and for each $(u, v) \in E$ there is $(u_1, v_2), (u_2, v_1) \in E^\prime$. I need to prove: $$G^\prime \textrm{ has 2N connected components} \Leftrightarrow G \...
How to prove that every regular subset of $L=\{a^nb^n \mid n\ge0 \}$ is finite? I know that every finite language is regular, and it's not true that every regular language is finite. I also know that $a^n b^n$ is non-regular language. I can find examples of finite regular subsets of $L$, for example $\{\epsilon, ab, aa...
A friend of mine is studying business analytics, currently on the topic for Microsoft DAX, but he is very new to the technological field. He mentioned yesterday, during a conversation, the term "sideways recursion". Does anyone have idea what that means? I know a regular recursion(maybe direct recursion is the more pro...
Linear Time Logic (LTL) is used for system verification. In my case, I am investing some time, to see the feasibility of using LTL this time to enforce a constraint on a stream of data. Enough of generalities, let's take a simple example: The operator UNTIL in the expression u Until v in LTL means, event u until v, it ...
How to simplify this context-free grammar into a similar one with no unit productions and no useless symbols? $$ S \to ABA \\ A \to aAA \mid aBC \mid bB \\ B \to A \mid bB \mid Cb \\ C \to CC \mid cC $$ Can the simplification result in this CFG? $$ S \to ABA \\ A \to aAA \\ A \to Bb \\ B \to b $$
How would you convert the following formal definition of deterministic pushdown automata into non deterministic ? Deterministic PDAs In general terms, a deterministic PDA is one in which there is at most one possible transition from any state based on the current input. Formally, a deterministic PDA is a PDA where: fo...
In the reference below, a 1-sparse recovery algorithm over a vector $a \in R^n$ is defined as follows. My question is why do we need the modulus (i.e. $x \mod p$)? Algorithm: Keep track of $$ \begin{split} w_1 &= \sum a_i \\ w_2 &= \sum i a_i \\ w_3 &= \sum a_i z^i \mod p \end{split} $$ Test if $$ ...
I read the following claim: $PSPACE^{SAT}=PSPACE$ $EXP^{SAT}$ is not necessarily the same as $EXP$ The first claim makes sense; $PSPACE \subseteq PSPACE^{SAT}$ trivially, and for any language $B \in PSPACE^{SAT}$ decided by an oracle machine $M_B$, we can define a non-deterministic machine $M'_B$ that works like $M_B...
How to remove null production and simply the grammar? $$ S \to a \mid Ab \mid aBa \\ A \to b \mid \epsilon \\ B \to b \mid A $$ Can the simplification result in this CFG? $$ S \to a \mid aBa \\ A \to b \\ B \to b $$
I was solving the recurrence using Recursion tree method: $$ T(n) = T(n - a) + T(a) + cn$$ When I started solving I could easily conclude the fact that $T(a)$ would have total cost computation in the form of: $$h*ca$$ But I could not figure out on how to solve the base case. I know that $T(n-a)$ would be at base case w...
According to Wikipedia https://en.wikipedia.org/wiki/RP_(complexity), $P \ne NP$ implies that $RP$ is a strict subset of $NP$. Does anybody have a reference? Furthermore, am I correct that if this indeed the case, then $NP-COMPLETE \cap RP = \emptyset$ since we can use $NP$ completeness to solve all other $NP$ problems...
Given the following language - $L=\left\{\left\langle M_{1}, M_{2}\right\rangle \mid\left\langle M_{1}\right\rangle \notin L\left(M_{2}\right) \vee\left\langle M_{2}\right\rangle \notin L\left(M_{1}\right) \text { and are TM } M_{1}, M_{2}\right\}$ I know it's in CO-RE but why this is not a good acceptor for the above ...
I have to prove that the language $L_2:=${$<M>$|$L(M)=\overline{A_TM}$} is (un-)decidable. In a previous assignment we proved that $L_1:=${$<M>$|$L(M)=A_TM$} is undecidable. I would say that $L_1$ is decidable because we can build a decider S. S="on input w": (rough outlined) breadth first search (a) if no accept stat...
For example, given a cron schedule such as: 0 * 1 7 6 and a time span, like the next year, can you directly compute the number of times the schedule will fire? It can be brute forced pretty trivially but I'd like to use this to sort a list so I'd rather not just brute force it. It's pretty easy to compute the trivial c...
The following is an NP-Complete problem: Suppose you have a collection $\mathcal{C}$ of sets, so that $A_i\in \mathcal{C}$ and $A_i$ is some set--we can suppose the elements of $A_i$ are integers. We want some $k$ integers, say $X \subseteq \bigcup_{A_i\in \mathcal{C}}A_i$ where $X$ has $k$ elements, and subject to t...
We are given a set of $n$ points on the plane $a_i = \{x^a_i, y^a_i\}$ and $b_i = \{x^b_i, y^b_i\}$. Assume that the points b are an affine transform of the points a, we can find a matrix $M$ and vector $t$ such that $\sum_{i=0}^{n-1} ||M a_i + t - b_i ||^2$ is minimized, in fact, we can even do so analytically. Assume...
I want to know if finding solution to a specific number of 2SAT equations sepearted by OR gate (DNF form as below) is in P or NP. The equation has total n variables and each clause is a 2SAT equation in itself in a subset of variables from 1 to n. Example: F = [(x1 || x2 ) && ( !x2 || x3) && (x3 || x4)] || [(x2 || x5) ...
I was going through the text Introduction to Algorithms by Cormen et. al. where I came across the following claim: Universal Hashing uses randomization.For the example of a compiler's symbol table, we find that the programmer's choice of identifiers cannot now cause consistently poor hashing performance. Poor performa...
Malware can enter a computer in various ways, but I would like to know how it is able to simply use 0's and 1's and machine code to take over a computer and how it can stay hidden from antivirus software.
I am familiar with 0/1 knapsack problem. But if the following constraint is imposed... how do I solve the question? If you choose some item 'U' you won't be able to choose another item 'V'. For example Items are given as [Name, Weight, Value] Items are : A 10 20 B 50 80 C 20 30 D 30 70 E 50 50 If you choose B then y...
I came across this problem that I could not figure out... For every language $A$, there is supposed to be a language $B$ such that: $$ A \leq_T B $$ but: $$ B \not \leq_T A $$ If it is $A \leq_TB$ and $B \leq_T A$, this is easy since we can just let $B := \bar{A}$, but for the above I could not think of anything. Any h...
Is this language regular? ${w ∈ (a + b)∗ : |u_{a}|>= 2009 · |u_{b}|}$ for every non empty prefix $u$ of string $w$} I think it's non-regular. I tried concatenation of $L_{prefix} $={${ u : |u_{a}|> 2009 · |u_{b}|}$} and $L_{2}= a^*b^*$. $L_{2}$ is regular. I tried to show that $L_{prefix}$ is non-regular using pumping ...
prove or disprove that any turing machine which accepts language $l=\{ww | w ∈ \{0, 1\}∗ \}$ has time complexity $ω(n^2)$
I'm a Physics/C.S. student and have been struggling with this particular problem for a few days now. So the task is as following: Consider the following languages: $\hspace{20pt} L_1 = \{\langle M \rangle \, | \, L(M) = A_{TM}\} \\ \hspace{20pt} L_2 = \{\langle M \rangle \, | \, L(M) = \overline{A_{TM}}\}$ Are these d...
Input: complete, undirected graph $G=(V,E)$ and cost function $c$ Assume for all nodes $x,y,z \in V$: $c(x,z)\le c(x,y) + 100\cdot c(y,z)$ Find a 200-approximation polynomial time algorithm for the input. I've seen the regular 2-approximation algorithm for a graph that satisfies the triangle inequality. Find the MST ...
Consider the problem of determining whether a Turing machine M on an input w writes the blank symbol at first. Is this decidable ?
How exactly does the control unit in the CPU retrieves data from registers? Does it retrieve bit by bit? For example if I'm adding two numbers, A+B, how does the computation takes place in memory level?
Determine if the following problem is decidable or not : Does the read–write head of a TM with the given input w leave the word w on the tape?
I confused about the description & definition of "key" occuring as terminology for databases and b-trees. In first case dealing with theory of databases a key is defined as a choice for a in certain sense minimal (see below) subset $K \subset A := \{A_1,A_2,...,A_n\}$ of a fixed set of attributes $A_i$ parametrizing a ...
Suppose we have: $$A\text{ }\colon=\{x, y, z\}$$ $$M\text{ }\colon=\text{some DFA using A}$$ $$S\text{ }\colon=xyzxyzxyz$$ Intuitively, one might say $S$ is fed to $M$ on a per-character basis. This means that somehow we have an undisclosed mechanism that can tell where a symbol starts and ends. One might say, simply u...
I am looking for an algorithm to solve the following problem. I am unsure whether to post this in computational science or here, but since this is an algorithm I thought I would try here first. I have a set of species made from a number of components. Let's number each component $0, 1, 2 ... n$. So now each species can...
Do we have to calculate time for declaring statement, in my case int num3 statement. The following question was asked by professor as a post-lecture quiz. I selected t(n)=3, but the correct answer was t(n)=4. What is the time taken by following algorithm on RAM model ? t(n)=3 t(n)=4 t(n)=5 None of the above
I know that BFGS is a general quasi-Newton method, whereas Levenberg-Marquardt (LM) is specifically for non-linear least squares (NLLS). That said, is there a big advantage of using LM instead of BFGS for NLLS problems?
I'm working on optimizing the structure of an optical meta device. I have a randomly generated 2D matrix, where 0,1 represents the presence/absence of a hole. Each structure manipulates light differently, thus giving rise to a unique spectrum. The problem I wish to solve is to maximize the efficiency of this structure....
I'm practicing data and control dependencies, but having trouble detecting them. For this example, I'm assuming this pipeline is fully bypassed (with forwarding). I think the only data dependency is i3 on i2. Is this correct? I also don't know how to detect the control dependency. I know there will be one because of th...
Suppose I have a graph with vertices of three colors - black, gray, and white. I want to compare the connectivity between sets of vertices to make claims like - the black set is more related to the white set than the gray set, and so on. How are such claims measured? Are there standard metrics or methods for that case?...
Can anyone give an example where a language can be rejected by linear bounded automata and accepted by a Turing machine. Is there any proof that a linear bounded automata is less powerful than a Turing machine?
I've seen on Wikipedia; that set covering cannot be approximated in polynomial time to within a factor mentioned above. Unless $NP$ has quasipoly-time algorithms. Now, this must pertain to classical algorithms and does not mention any approximation algorithms that may only work in nature. (eg. Things like Amoebas solvi...
Introduction I have an optimization problem. There are up to 25 nodes. The connectivity between the nodes is far less important than the Cartesian placement of the nodes. Since all nodes can potentially affect each other in the optimization problem it is safe to model this as a complete, undirected graph. In most modes...
The question is as follows: Show that when all elements are distinct, the best-case running time of HEAPSORT is $\Omega(n\lg n)$ https://walkccc.github.io/CLRS/Chap06/6.4/ This website provides a rather complicated analysis to this question, but the obvious answer that occurred to me was far simpler. Hoping if anyone c...
Edit Distance is very well known problem in computer science. Came up with following algorithm after reading through CLRS but it doesn't work. Check the working algorithm below, I couldn't find why first algorithm doesn't work while second one does. public int find (String word1, String word2, int i, int j, int count...
We are given two grayscale images, one of which contains a large, mostly contiguous patch from the other one. The patch can be altered with noise, its levels may be stretched, etc. Here's an example We would like to determine the region of the image which was copied onto the other image. My first instinct was to look...
I am working on a problem defined as the following Given a set of $n$ elements called $R \subseteq \mathbb{N} \times \mathbb{N}$ and numbers $Z,G \in \mathbb{N}$, where $Z$ is a measure of our resources and $G$ is our necessary minimal reward, is there a set $R' \subseteq R$, so that $\sum_{(z,g)\in R'}z \leq Z$ and $\...
Using big- O notation estimate in terms of a simple function of $ n $ the number of bit operations required to compute $3^n$ in binary. I need some help with the above question. The number of bit operations required to multiply two k- bit numbers is $O(k^2)$. In the first step I am multiplying two 2-bit numbers, i...
Consider $L = \{\langle L_1, L_2\rangle\mid L_1, L_2 \in \text{CFL} \text{ and } L_1 \cap L_2 = \emptyset \}$. How to prove that $L \notin R $? $L_1, L_2$ encoded in chomsky-normal-form.
How can I prove the next claim: If a language $L$ meets the pumping lemma for regular languages then $L$ meets the pumping lemma for context-free languages? (Without any pre-condition about the regularity of $L$)
I recently learned about the Arthur-Merlin protocol, and we defined the complexity classes $AM,MA$. We have also seen that there exists a theorem stating that $AMAMAM...AM=AM$, however we have not formally defined $AMAMAMAM...AM$. We did give a brief definition for it as a protocol, but i would like to see a formal def...
A visibility graph $G(P) = (V,E)$ of a set $P = \{p_1, \dots, p_n\}$ of points is defined as follows. Each vertex $u \in V$ corresponds to a point $p_u \in P$. There exists an edge $uv \in E$ if, and only if the line segment $\overline{p_up_v}$ does not contain any other points in $P$. Assume that the coordinates of ...
I learnt that in a order-statistic tree (augmented Red-Black Tree, in which each node $x$ contains an extra field denoting the number of nodes in the sub-tree rooted at $x$) finding the $i$ th order statistics can be done in $O(lg(n))$ time in the worst case. Now in case of an array representing the dynamic set of elem...
As described in the reference, the algorithm (see at the bottom) supposes to output an estimator $\hat T$ for the # of triangles in a given graph $G = (V, E)$, denoted $T$. It is written that "it can easily be shown" that $$ E[\hat T] = T $$ But unfortunately, I'm not seeing it. Trying to analyze $E[\hat T]$, I think a...
I am reading up on algorithms and at the moment looking at the below problem from Jeff Erickson's book Algorithms. I solved (a) by seeing a relationship to the previous problem on computing the number of array inversions. However, I am struggling with problem (b) as I cannot see how to reduce the circle point arrangem...
I'm trying to create a list curation web app. One thing that's important to me is being able to drag-and-drop reorder items in the list easily. At first I thought I could just store the order of each item, but with the reordering requirements, that would mean renumbering everything with a higher order (down the list) t...
I've recently learned about Prolog and Logic programming which I find pretty cool, but the compiler is currently like magic to me and I want to know how they work. After a little bit of research I discovered that logical compilers are based on Warrens Abstract Machine (WAM). I've tried to find some information on WAM, ...
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...
I was going through the Dynamic Programming section of Introduction to Algorithms (2nd Edition) by Cormen et. al. where I came across the following recurrence relations in the context of assembly line scheduling (Note: Assembly line scheduling or dynamic programming is not required to answer to the question though, it ...
I am learning $\lambda \mu$-calculus (self-study). I learned it because it seems very useful for understanding Curry-Howard correspondence (e.g understanding the connection between classical logic and intuitionistic logic) I searched the internet, there is some information about $\lambda \mu$-calculus on Wikipedia, bu...
I can't figure out what the notation $[x \neq k ]$ means. Here's a bit of context: The formula is: $Pr[A_i^k = 1] = \frac{[i\neq k]}{|k-i| + 1} = \begin{cases} \frac{1}{k-i+1} \text{ if } i \lt k \\ 0 \text { if } i = k \\ \frac{1}{i-k+1} \text{ if } i \gt k \end{cases}$ and is part of a chapter where the average ex...
I found a paper titled Multimodal representation: Kneser-Ney Smoothing/Skip-Gram based neural language model. I am curious about how the Kneser-Ney Smoothing technique can be integrated into a feed-forward neural language model with one linear hidden layer and a softmax activation. What is the purpose of the Kneser-Ney...
I'm currently trying to understand an implementation of CRC32 about which I have a question. On this page at section 6, there is the following code: public uint Compute_CRC32_Simple(byte[] bytes) { const uint polynomial = 0x04C11DB7; /* divisor is 32bit */ uint crc = 0; /* CRC value is 32bit */ foreach (by...
As posed in the question; the statement naively seems like it should be self-evident but there are no algorithms that come immediately to mind. Suppose I have some domain $A$ (in my case a subset of $\mathbb{Z}^n$ for some $n$, but I would expect any answer to be independent of that structure), and a domain $B\subset A...
I came across this problem which asks to show the existence of two disjoint Turing-recognizable sets $A$ and $B$ such that no decidable set $C$ can separate them... In this case, a set $C$ is said to separate $A$ and $B$ if $A \subseteq C$ and $B \subseteq \overline{C}$ ... If only $A$ is Turing-recognizable, then we c...
Assume we run Prim’s algorithm when we know all the weights are integers in the range {1, ...W} for W, which is logarithmic in |V|. Can you improve Prim’s running time? When saying 'Improving', it means to at-least: $$O(|E|)$$ My question is - without using priority queue, is it even possible? Currently, we learned th...
As discussed here Johnson's Algorithm can be used to solve the APSP-Problem in $O(V^2\log V + VE)$ in stead of $O(V^3)$ for Floyd-Warshall. However, Johnsons Algorithm does quite a bit of work for the case that some weights are negative. Is there a faster way to compute this given that all weights are positive?
Let $G = (V, E)$ be an undirected graph and $U \subseteq V$ some subset of its vertices. An induced graph $G[U]$ is graph created from $G$ by removing all vertices that are not part of the set $U$. I want to find a polynomial time algorithm that has graph $G = (V, E)$ and integer $k$ as input and returns a maximum set...
In p. 7 of the book "Introduction to Information Retrieval" (by Manning et al), the authors explain how, given a collection of text documents, an inverted index is built by tokenizing, then sorting the (term, docID) pairs, merging multiple occurrences of the same pairs, and the pairs for each term are grouped into a p...
What subfields in computer sciences may one study without learning Object Oriented Programming or is there some kind of degree in Computer Science without the OOP knowledge requirement? Is there a language without OOP? Does one need to know OOP to simulate a CPU? I wanted to earn a CS degree without ever learning OOP. ...
I'm trying to figure out whether infinite language change the answer. Show that the following language is decidable: $$L=\{\langle A,B \rangle : \text{$A,B$ are DFAs, $L(B)$ is finite, and $L(A)/ L(B)=L(0^*1^*)$}\}.$$ (I am talking about right division.) We know how to check whether the language of a DFA is finite, a...
I went through the Master Theorum extension for floors and ceiling section 4.6.2 in the book Introduction to Algorithms It had the following statement: Using the inequality $\lceil x \rceil \le x+1$ But I haven't seen the inequality anywhere and could not understand the verifiability of inequality. Instead the Chapte...
What are some applications where irreducible control flow is required*? I'm particularly interested in programming language features that will be tricky to efficiently compile if the compile target does not permit irreducible control flow. For example, a programming language offering GOTO will generate irreducible cont...
Assume in the applied pi-calculus we have the following process: $$(\nu n)\overline{c} \langle n \rangle.0 | (\nu n) (c(y).(\text{if n=y then P else Q}))$$ where $P$ and $Q$ are further processes. I know that the following reduction semantic holds for the applied $\pi$-calculus (from wikipedia): $$\overline{x}\langle z...
I was looking online, on sipser book, and on lecture notes and I can't find a proof to closure of context free languages to homomorphism that using PDA instead of CFG. I'm not looking for a full and formal proof, I just want to understand the general idea.
A Dyck path is a finite list of $1$'s and $-1$'s whose partial sums are nonnegative and whose total sum is $0$. For example, [1, 1, -1, -1] is a Dyck path. Rather than use $1$ and $-1$, it is common to use "U" and "D" for $1$ and $-1$, respectively, so we might write UUDD instead. (These might be more familiar as Dyck ...
The simple (naive?) answer would be O(n) where n is the length of the shorter string. Because in the worst case you must compare every pair of characters. So far so good. I think we can all agree that checking equality of two equal length strings requires O(n) runtime. However many (most?) languages (I'm using Python 3...
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...
Are there competitions for integer programming like there are for SAT and MAXSAT?
I'm working on the problem: Count smaller elements on right side using Set in C++ STL The solution is to add each element to the set and then to count the elements on the left, the distance function is called. This is the algo: 1. Traverse the array element from i=len-1 to 0 and insert every element in a set. 2. Find t...
First Look at the definition of SUBEXP from Complexity Zoo: SUBEXP: (Deterministic Subexponential-Time) The intersection of DTIME($2^{n^\epsilon}$) over all $\epsilon$>0. (Note that the algorithm used may vary with $\epsilon$.) or it can be written as: SUBEXP = $\bigcap_{\epsilon>0}$DTIME$(2^{n^\epsilon})$. So, I bri...
Please excuse or improve the poor title of this question. My question is rather undirected, but I guess I am trying to find out if I might be missing a keyword for my problem. So there is plenty of work on sorting algorithms. Sorting is usually understood as creating a / the one correct total order given a set of eleme...
$S \to aAA$ $A \to aS \mid bS \mid a$ Trivial thing: starting and ending with a Atleast 3 a's are definitely present (These are very layman observations...but seriously I am unable to figure out what exactly this language is all about. ...) My attempt: What I am able to generate 1)aaa 2)aAA a bS A a ba AA A a ba *** Th...
Consider the following python code X = [None] X[0] = X This has many fun properties such as X[0] == X and X[0][0][0][0][0][0][0][0] == X I understand how this works from a practical standpoint, as it's all just the same pointer. Now, when flattening a list, we tend to convert things from [[1, 2, 3], [[4, 5], [6, 7]]...
I have some difficulties with understanding the space complexity of the following algorithm. I've solved this problem subsets on leetcode. I understand why solutions' space complexity would be O(N * 2^N), where N - the length of the initial vector. In all those cases all the subsets (vectors) are passed by value, so we...
Consider these equivalent functions in C and Python 3. Most devs would immediately claim both are $O(1)$. def is_equal(a: int, b: int) -> bool: return a == b int is_equal(int a, int b) { return a == b; } But consider what is happening under the surface. Integers are just binary strings and, to determine equality,...
Say you have an array of integers like [1, 2, 3, 4, 5, 6], the problem is to find the smallest way to break up the array into sub-arrays where each sub-array satisfies the following requirement: sub-array.first_integer and sub-array.last_integer must have a common divisor that is not 1. So for [7, 2, 3, 4, 5, 6] the ...
Are there variations of the classic graph coloring problem that the number of neighbors in the same color is limited but not zero (in the original problem the limit is zero)? Problem: Given a graph $G$ and two integers $c$ and $p$, is it possible to color the vertices of $G$ with $c$ colors such that for every vertex $...
This is an exam question. For E = {a,b}. let us consider the regular language $L= \{x|x = a^{2+3k} or x=b^{10+12k}, k >= 0\}$ Which one of the following can be a pumping length (the constant guaranteed by the pumping lemma) for L? A)3 B)9 C)5 D)24 Ans is 24. As per me pumping length is the length which gets actually re...
Continuing from this question: the buckets of water problem. (All the definitions can be found there, so I will not repeat them). As seen there by Yuval's answer, the problem is NP-Hard. I was attempting to prove its NP-completeness, and while doing so - I was suddenly not sure whether or not it belongs to NP. Because ...