instruction
stringlengths
0
29.8k
⌀
|statistics|monte-carlo|
> It is the linker's job to link the function declaration to its implementation This is not true. This is the compiler's job. Essentially the declaration (I'm assuming you mean the prototype, as in `return_type function_name (arguments...)`) is part of the language to allow you to tell the compiler what the function...
null
null
(15 marks) Suppose a ray comes from a point (2, 8) and hits at mirror point (6, 6). Assume that perpendicular vector a point (6, 6) is ̅= (0, 3). Find the reflection emitting point from (6, 6). [Assume 2-D coordinate system, you must draw the appropriate diagram of your solution] I'm pretty sure I can figure o...
(15 marks) Suppose a ray comes from a point (2, 8) and hits at mirror point (6, 6). Assume that perpendicular vector a point (6, 6) is ̅= (0, 3). Find the reflection emitting point from (6, 6). [Assume 2-D coordinate system, you must draw the appropriate diagram of your solution] I'm pretty sure I can figure o...
{"Voters":[{"Id":755,"DisplayName":"D.W."}]}
A [random seed](https://en.wikipedia.org/wiki/Random_seed) is a number that is used to initialize a pseudorandom number generator. The resulting numbers that are generated will depend on the seed.
As Arno shows in the other answer, you can easily write a program that halts if and only if at least $k$ out of $n$ given Turing machines halt, by running the $n$ machines in parallel until $k$ of them have halted. As a bonus, if you actually run this program (instead of just asking the oracle about it), it will tell ...
Can you verify this like please bro please tell me the answer to my question [![enter image description here][1]][1] [1]: https://i.stack.imgur.com/rP6Nq.png
A string that contains aabb, does this work?
|finite-automata|
null
When you wonder what a library function does, you should look it up. Get into the habit of reading the language or library's documentation. This can be more or less helpful depending on the quality of the documentation, but when the quality is good, that's your problem solved. In this particular case, the [reference...
The key point here is that $T_A$ and $T_B$ does not know whether any of the TMs will halt. It just simulates all TMs, and it will halt if 2 of them (1 for $T_B$) halt. If none of them halt, then $T_A$ also won't halt, which is why $T_A$ and $T_B$ are not oracle, since they are not guaranteed to halt, unlike the actual ...
IMO the question is about a trick to handle reflections: rather than computing the direction of the incoming ray and deriving the direction of the outgoing ray, you can construct the symmetric of the emission point wrt the mirror. Then the reflected ray is the line from the reflected point through the hitting point. ...
I am currently learning about how the compilation and linking works in C++. I think I kinda get how the compiler works, and that for a file to fully compile you don't need to have function implementations, but only declarations. It is the linker's job to link the function declaration to its implementation. But now I...
How does the linker know where to look for a function implementation in C++?
null
null
null
The formal definition of complexity of an algorithm is the runtime in terms of the length of the input. Meaning, suppose you have a number with size n, to represent the number n you need $log_2(n)$. Thus, the actual time complexities When computing the complexity of an algorithm, it may run in a linear time in terms...
null
The formal definition of complexity of an algorithm is the runtime in terms of the length of the input. Meaning, suppose you have a number with size n, to represent the number n you need $log_2(n)$. Thus, the actual time complexities When computing the complexity of an algorithm, it may run in a linear time in terms...
$P$ is the language class that is decidable in polynomial time by a deterministic Turing machine. $NP$ is a language class that is decidable in polynomial time by non-deterministic Turing machines and can be decidable in exponential time by deterministic Turing machines. So are there any other language classes of...
Are there any other language classes of time complexity between the P language class and the NP language class?
|complexity-theory|time-complexity|p-vs-np|
Not if P = NP. Phrased differently, the provable existence of an intermediate language class would constitute proof that P != NP.
This automaton only accepts strings that START with aabb. You also need to accept strings such as baabb, bababaabbabab, aabaabb, etc.
null
null
The decision version of the minimum feedback arc set problem is as follows: given a directed graph $G=(V,E)$ with no self-loops and an integer $k$, decide whether there is a set $F \subseteq E$ of edges such that $|F| \le k$ and the graph $G - F = (V, E \setminus F)$ is acyclic. This is a well-known NP-Complete pro...
The formal definition of complexity of an algorithm is the runtime in terms of the length of the input. Meaning, suppose you have a number with size n, to represent the number n you need $log_2(n)$. Thus, the actual time complexity is the runtime relative to $log_2(n)$ bits and not n. For instance, when computing th...
null
I need to implement my own red-black tree and I am stuck with deletion. I have found this [book (Introduction to Algorithms)][1] (p.222) and in the following code I can't understand this marked line. [![RB-Delete][2]][2] Firstly, why do I need to do that if `x.p` is already pointed at `y`, because it is in particul...
How to delete node from RB-tree
|algorithms|binary-trees|red-black-trees|
I have a directed graph $G(V,A)$ with arc costs $c_{ij} = \alpha_{ij}1_{x_{ij}>0} +\beta_{ij}x_{ij}$, where $\alpha_{ij}$ and $\beta_{ij}$ are, respectively, a fixed cost and a cost per unit of flow pushed along arc $(i,j)$. I'd like to solve the [minimum-cost flow (MCF) problem][1] in this graph, i.e., given a supply/...
I have a directed graph $G(V,A)$ with arc costs $c_{ij} = \alpha_{ij}1_{x_{ij}>0} +\beta_{ij}x_{ij}$, where $\alpha_{ij}$ and $\beta_{ij}$ are, respectively, a fixed cost and a cost per unit of flow pushed along arc $(i,j)$. I'd like to solve the [minimum-cost flow (MCF) problem][1] in this graph, i.e., given a supply/...
null
Is there a $O(nlogn)$ time algorithm for computing $p(x)=\sum\limits_{i=0}^na_ix^i$ ? I think with the method below I get O(n), but I need O(nlogn) Hint: there's a way to calculate $x^i$ more efficiently. This is exactly what I'm doing right ? x = v total = 0 for coef in coefs: ...
O(nlogn)-time complexity
|time-complexity|polynomials|
Have 5 states S, Sa, Saa, Saab, Saabb. Move to a state Sxxx after you parsed the first characters xxx of aabb, except you stay in the accepting state Saabb no matter what the input once you reached it. S: a->Sa, b->S. Sa: a->Saa, b->S. Saa: a->Saa, b->Saab. Saab: a->Sa, b->Saa...
## Problem ## In the problem, I was given the grammar for a non-deterministic finite state automata (NDFSA). The problem asks you to use this grammar to draw the NDFSA and then asks you to convert the NDFSA into a deterministic finite state automata (DFSA). The grammar is written as such: G2[E]: E ::= ...
Is there any way to tell which states are final states in a finite state automata given only its grammar?
|finite-automata|compilers|nondeterminism|lexical-analysis|
Your solution (when fixed) indeed achieves the complexity $O(n)$ by computing the $x^i$ incrementally. From a numerical standpoint, this is maybe not the best approach because of the accumulation of truncation errors along the multiplies. The power $x^i$ takes $i$ multiplies. It is well-known that you can compute...
null
No, we cannot compute $A(L)$ from $M(L)$ without first building $A(M(L))$, essentially because $A(M(L))$ is obtained from $M(L)$ by forgetting some information; in other words, if you are given $M(L)$, then, you know $A(M(L))$ without having to do any computation.
Your solution (when fixed) indeed achieves the complexity $O(n)$ by computing the $x^i$ incrementally. From a numerical standpoint, this is maybe not the best approach because of the accumulation of truncation errors along the multiplies. The power $x^i$ takes $i-1$ multiplies. It is well-known that you can compu...
Unless a computer has special hardware to generate truly random numbers, it can only generate pseudo-random numbers. Pseudo-random means that the numbers seem random but are in reality generated by a deterministic algorithm. So they will always follow the same sequence of numbers, periodically (though the period can be...
Unless a computer has special hardware to generate truly random numbers, it can only generate pseudo-random numbers. Pseudo-random means that the numbers seem random but are in reality generated by a deterministic algorithm. So they will always follow the same sequence of numbers, periodically (though the period can be...
null
null
null
null
null
I'm assuming that $M$ is a decider and that by "all states" you are excluding the accepting and rejecting state. Given a Turing machine $M$, you can build an equivalent Turing machine $M'$ that behaves like $M$ except that $M'$: - has one additional state $q$ and one additional tape symbol $x$; - whenever $M$ woul...
In graph `G`: a cycle `a` is a **subcycle** of cycle `b` if there exists vertices `c` and `d` such that: - `cd` is an edge of `a` - `f` is the resulting path of `a` without edge `cd` - `e` is a path from `c` to `d` of length `2` or greater and cycle `b` consists of the edges in `e` and `f` For example: In th...
Given a graph `G`, what is the maximum number of "minimum" cycles it could have?
|graphs|
In graph `G`: a cycle $A$ is a **subcycle** of cycle $B$ if there exists vertices $c$ and $d$ such that: - $cd$ is an edge of $A$. - $F$ is the resulting path of $A$ after removing the edge $cd$. - $E$ is a path from $c$ to $d$ of length at least $2$, and the cycle $B$ consists of the edges in $E$ and $F$ For e...
If I understand correctly, you call a cycle "minimum" if it has no chord. Then the number of minimum cycles can be exponential. As an example, start from a graph containing a single cycle $C$ and replace each edge $e = (u,v)$ with two "split" vertices $x_e, y_e$ and the edges $(u, x_e), (x_e,v), (u, y_e), (y_e,v)$....
If I understand correctly, you call a cycle "minimum" if it has no chord. Then the number of minimum cycles can be exponential. As an example, start from a graph containing a single cycle $C$ and replace each edge $e = (u,v)$ with two "split" vertices $x_e, y_e$ and the edges $(u, x_e), (x_e,v), (u, y_e), (y_e,v)$....
If I understand correctly, you call a cycle "minimum" if it has no chord. Then the number of minimum cycles can be exponential. As an example, start from a graph containing a single cycle $C$ and replace each edge $e = (u,v)$ with two "split" vertices $x_e, y_e$ and the edges $(u, x_e), (x_e,v), (u, y_e), (y_e,v)$....
Not exactly what you asked, but if you define $b$ as the maximum length reached, you can minimize $b$ and get something similar to what you desire. Let's say that $X_p$ is a variable that represents the number of cars parked in lane $p$. So, you could add constraints like: $b \geq X_p, \forall p \in P$ If you...
null
null
I want to know if checking whether a a set of 3-literal clause is satisfiable such that every literal in each clause is either all true or all false NP-complete? By 3-literal clause, I mean it can have a clause can have at most 3 literals. I think this problem is NP-complete or co-np complete as it seems like a ...
Is checking whether a a set of 3-literal clause is satisfiable such that every literal in each clause is either all true or all false NP-complete?
|complexity-theory|3-sat|
The problem can be solved in polynomial time. Construct a new formula as follows: - The set of variables, is the set of variables of the original instance plus one variable $x_c$ for each clause $c$. The idea is that all literals in $c$ will be forced to have the same value of $x_c$. - For each clause $(\ell_1, \...
The question is wrong. The "usual demonstration" proves that the deciding machine $D_0$ cannot exist, as that leads to contradiction. Therefore, the adversarial $A_0$ cannot exist either, as it has $D_0$ as a part/subroutine. It is then impossible to construct the discriminator $D_1$, it cannot check for $A_0$ source, ...
The permuted kernel problem is NP-complete problem by simple reduction from partition problem. In fact, it is strongly NP-complete by reduction from 3-partition. The literature points to Garey and Johnson for the reduction from 3-partition. I checked G&J but did not find the reduction. Do you have a reference that cont...
Strong NP-completeness of permuted kernel problem
|complexity-theory|np-complete|
The permuted kernel problem is NP-complete problem by simple reduction from partition problem. In fact, it is strongly NP-complete by reduction from 3-partition. The literature points to Garey and Johnson for the reduction from 3-partition. I checked G&J but did not find the reduction. Do you have a reference that cont...
null
I think that we are calling a *decider* a machine that takes in a natural number $n$ and then prints out either "yes" or "no", where as observers we interpret that as the machine's opinion of whether Turing machine $n$ halts on an empty tape, yes? Consider the decider $D_y$ that always prints "yes," along with the o...
I take it that we are calling a *decider* a machine that takes in a natural number $n$ and then prints out either "yes" or "no", where as observers we interpret that as the decider's opinion of whether Turing machine $n$ halts on an empty tape. Consider the decider $D_y$ that always prints "yes," along with the one $D_...
null
## Problem ## In the problem, I was given the grammar for a non-deterministic finite state automata (NDFSA). There was no other useful context given. The problem asks you to use this grammar to draw the NDFSA and then asks you to convert the NDFSA into a deterministic finite state automata (DFSA). The grammar is wri...
Use $$A = \begin{pmatrix} 1 &\cdots &1 &0 &\cdots &0 &0 &\cdots &0\\ 0 &\cdots &0 &1 &\cdots &1 &0 &\cdots &0\\ 0 &\cdots &0 &0 &\cdots &0 &1 &\cdots &1\\ \end{pmatrix}$$ where each row contains $n/3$ 1's.
null
|complexity-theory|3-sat|schaefers-dichotomy|
null
null
We were given a question in class as follows: You have a "magic oracle" that can decide if a Turing Machine halts. You have three TMs $T_1, T_2, T_3$. Device an algorithm that decides which of the TMs halt and which do not by asking the oracle at most twice. The sketch of the solution given was Construct a new...
null
The problem can be solved in polynomial time. Construct a new formula as follows: - The set of variables of the new formula is the set of variables of the original instance plus one variable $x_c$ for each clause $c$. The idea is that all literals in $c$ will be forced to have the same value of $x_c$. - For each ...
null
The problem that I'm trying to solve is: Given an array of length N, I should be able to find the length of the biggest palindrome in the given array. With palindrome, we refer to a word, phrase, or sequence that reads the same backwards as forwards. For example, if we give as input `"1234321789"` the program should...
Finding the length of the biggest palindrome in the given array
|algorithms|time-complexity|
The problem that I'm trying to solve is: Given an array of length N, I want to find the length of the longest palindrome in the given array. With palindrome, we refer to a word, phrase, or sequence that reads the same backwards as forwards. For example, if we give as input `"1234321789"` the algorithm should retur...
Finding the length of the longest palindrome in the given array
I'm trying to find the time complexity of T(n) = 1600T(n/4) + n! . So far I have thought of changing n! to something usable by the master theorem. Stirling's approximation gives us the equation [![enter image description here][1]][1] [1]: https://i.stack.imgur.com/I8cx9.png I am confused on whether the va...