instruction stringlengths 0 29.8k ⌀ |
|---|
null |
I was looking into complexity theory and disappointed by the fact that a problem as simple as sorting an array isn't in the class $P$. This is because the class is defined only for decision problems (ones that have a binary answer). I know that any optimization problem can be turned into a decision problem by imposing ... |
Construct an objective function that favors the sorted permutation |
|np|arrays|permutations| |
**Preorder traversal:**
This traversals always yield unique binary trees. For a proof, please check [why recording non-existent children in the pre-order traversal will differentiate different binary trees?](https://cs.stackexchange.com/questions/144593/why-recording-non-existent-children-in-the-pre-order-traversal-... |
Assume we have a tree and we want to serialize it.
**Example:**
Tree
1
/ \
3 2
/ \ / \ ... |
|trees|binary-trees|strings|hashing|tree-traversal| |
null |
|trees|binary-trees|tree-traversal| |
I don't understand why you seem to want that computing the best value of the objective function must require sorting the array. In optimization problems (look for example at the class $\mathsf{NPO}$), the problem is that of computing an optimal solution (and not just the optimal value of the objective function).
Tha... |
{"Voters":[{"Id":6759,"DisplayName":"Steven"}]} |
{"Voters":[{"Id":6759,"DisplayName":"Steven"}]} |
null |
Here is a definition of $\mathrm{NP}^B$. A language $L$ belongs to this class if there exists a polynomial $p$ and a polytime oracle function $f$ (that is, a polytime function which has access to an oracle) such that
$$
x \in L \iff \text{there exists $y$ of size at most $p(|x|)$ such that } f^B(x,y),
$$
where the ... |
null |
Suppose that a Turing machine runs in time at most $T(n)$ on inputs of length $n$, where $T(n) = o(n)$. Therefore $\lim_{n\to\infty} T(n)/n = 0$, and so we can find $N$ such that $T(n) < n$ for $n \geq N$.
Let $x$ be an input of size at least $N$, and let $y$ be the first $N$ symbols of $x$. If we run the Turing mac... |
I encountered many articles on max-flow problem that do not go beyond simple graphs in which two nodes are either connected with a single directed edge OR two nodes are connected with a single undirected edge, therefore making the capacity symmetric.
When two nodes are connected with more than one edge, they use "tr... |
Network flow on multigraph easier than I thought? |
|algorithms|graphs|network-flow| |
null |
{"Voters":[{"Id":755,"DisplayName":"D.W."}],"SiteSpecificCloseReasonIds":[]} |
If we find a problem we know for sure is in NP but not in NP-complete or P, we'll have proved P!=NP. One approach then is to identify problems in NP (but not P) we haven't been able to show to be NP-complete so far and try to prove they aren't in that set. Any examples of such problems? Preferably one problem per answe... |
Examples of problems in NP but not in P which we haven't proved NP complete |
|complexity-theory|np-complete|np| |
The language constructed in the proof of [Ladner's Theorem](https://web.cs.ucdavis.edu/~rogaway/classes/220/winter06/ladner-theorem.pdf).
See also the [Wikipedia page](https://en.wikipedia.org/wiki/NP-intermediate) on the NP-intermediate class, which contains a list of problems that might be in NP-intermediate. |
Let's say number of elements are a power of 4. Now if we break the array in parts of 1/4 and 3/4, how do we calculate the time complexity in this case? |
In merge sort, what will be the time complexity if in each recursion, we break the array in two parts of size 1/4 and 3/4 respectively? |
|algorithms|time-complexity|recurrence-relation|divide-and-conquer|mergesort| |
null |
[R C Lacher's definition][1]:
> A binary tree is complete iff the only vertices with less than two children are in the bottom two layers.
[Paul E. Black's definition][2]:
> A binary tree in which every level (depth), except possibly the deepest, is completely filled. At depth n, the height of the tree, all nod... |
Complete Binary Tree |
|binary-trees| |
[R C Lacher's definition][1]:
> A binary tree is complete iff the only vertices with less than two children are in the bottom two layers.
[Paul E. Black's definition][2]:
> A binary tree in which every level (depth), except possibly the deepest, is completely filled. At depth n, the height of the tree, all nod... |
Sometimes we need some prime number with certain minimum size for modular algorithm. For practical purposes we can precompute table of some primes for range which makes sense in application. However I'm interested how fast theoretically (in terms of time complexity on $n$) we can find prime with at least $n$ bits? It s... |
Best known deterministic algorithm for generation of any (non random) n-bit prime? |
|time-complexity|reference-request|primes| |
In practice, you should absolutely use a randomized algorithm. There is no reason in practice to use a deterministic algorithm, or to care about the complexity of deterministic algorithms.
So I will assume that you are asking only out of theoretical interest. In that case, a reasonable approach is to start with th... |
Let's consider Paul E. Black's definition. As per that,
```
This is a complete binary tree This is not
2 ---------depth 0--------- 2
/ \ / \
1 3 ---------d... |
Sometimes we need some prime number with certain minimum size for modular algorithm.
For practical purposes we can precompute (using fast randomized algorithms) table of some primes for range which makes sense in application.
However I'm interested how fast *theoretically* (in terms of time complexity on $n$) we... |
null |
null |
Let $c \in (0, \frac{1}{2}]$ be any constant. In your case $c = \frac{1}{4}$.
If, at a generic recursive call, you partition the $n$ elements in your input array into a subarray of size $cn$ and another of size $(1-c)n$ (floors and ceilings are omitted for simplicity here), you can describe the running time of merg... |
null |
null |
Let $c \in (0, \frac{1}{2}]$ be any constant. In your case $c = \frac{1}{4}$.
If, at a generic recursive call, you partition the $n$ elements in your input array into a subarray of size $cn$ and another of size $(1-c)n$ (floors and ceilings are omitted for simplicity here), you can describe the running time of merg... |
From Wikipedia on $\mathrm{NP}$-completenes: *"a [decision] problem is NP-complete if it is both in NP and NP-hard."* [[link]][1] I think we can paraphrase this as the first statement:
- An $\mathrm{NP}$-hard (decision) problem $\Pi$ is $\mathrm{NP}$-complete if and only if $\Pi \in \mathrm{NP}$.
- $\#\mathrm P... |
What is the (intuitive) relation of NP-hard and #P-complete problems? |
|complexity-theory|np-complete|np-hard|complexity-classes|counting| |
null |
From Wikipedia on $\mathrm{NP}$-completenes: *"a [decision] problem is NP-complete if it is both in NP and NP-hard."* [[link]][1] I think we can paraphrase this as the first statement:
- An $\mathrm{NP}$-hard (decision) problem $\Pi$ is $\mathrm{NP}$-complete if and only if $\Pi \in \mathrm{NP}$.
- $\#\mathrm P... |
The common element in "while statements" and "do statements" is the continuation condition, which is an expression inside parentheses, always indicated with the keyword `while`. If you wanted to, you could capture this commonality with something like:
```none
<while-clause> ::= "while" "(" expression ")"
<while-stat... |
|formal-grammars|c| |
The common element in "while statements" and "do statements" is the continuation condition, which is an expression inside parentheses, always indicated with the keyword `while`. If you wanted to, you could capture this commonality with something like:
```none
<while-clause> ::= "while" "(" <expression> ")"
<while-st... |
null |
if a BFS is applied on a graph is it necessary that the resultant BFS tree contains all the edges that are in the original graph ? |
i am solving a question related to bfs traversal and there i got this doubt so can anyone plz solves this doubt? |
|graphs|graph-traversal| |
I have an integer constraint system which I seek to find solutions for.
The constraints consist of lesser/equal inequalities which have a difference of two minimum expressions on their right side.
Lacking an implementation of the minimum function, Z3 forces me to use pairwise comparisons in nested conditional stateme... |
How does the SMT solver Z3 handle conditional statements in an integer inequality constraint? |
|optimization|linear-programming|constraint-satisfaction|smt-solvers| |
No, you can check how the BFS algorithm works: if an edge $(u,v)$ is examined and $v$ has already been discovered, then $(u,v)$ won't be in the BFS tree.
Besides, as the name suggests, a BFS tree is a tree (and hence acyclic). This means that a BFS on a graph that is cyclic cannot possibly contain all graph edges. T... |
As far as I can tell, if we ignore the cycle, the images are of minimum spanning trees (a weighted, connected, undirected graph). One way to create them follows:
1. Create a uniformly random set of connected edges.
1. Let the weight for each edge be the distance between its vertices.
1. Apply [Borůvka's Algorithm]... |
I have a constraint system which I seek to find solutions for.
The constraints consist of lesser/equal inequalities which have a difference of two minimum expressions on their right side.
Lacking an in-built minimum function, Z3 forces me to use pairwise comparisons in nested conditional statements. That works well... |
How does the SMT solver Z3 handle conditional statements in a constraint? |
The theory of NP-completeness studies *decision problems* and (indirectly) *optimization problems*. In contrast, the theory of #P-completeness studies *counting problems*. In particular, NP is a class of *decision problems* while #P is a class of *counting problems*. The elements of these two classes are different, so ... |
This is the first concept in *The Little Typer* to give me quite a bit of trouble, and it appears I am not alone ([1](https://github.com/awalterschulze/the-little-typer-exercises#help) [2](https://www.thatgeoguy.ca/blog/2021/03/07/review-the-little-typer/)), so perhaps it would be beneficial to ask here. Hopefully this... |
What is an explanation of the replace operator in the Pie language? |
|dependent-types| |
null |
No, they are not the same thing. They share similarities, in that they are both brain inspired approaches. But this is where the similarities end.
To avoid going into too much detail, I'll explain it with this analogy:
Imagine you're a civilization trying to figure out flight and you're presented with an airplane... |
Your model is Turing complete (unlike what I previously thought), see user23013's answer a sketch of the proof (the essence is you can simulate a queue, and queue automata are Turing complete).
There are several ways to weaken you model to drop to equivalence with linear bound automata or lower.
Ginsburg, Greibac... |
null |
Well, I know that I'm going to ask too much.
So, I really want to ask you a totally (powerful (!)) free completely off-line code to generate **prompt-based** images like midjourney. I want to run with my graphics card and memory without any restrictions of time or number of images and completely private.
**My qu... |
How can I find a Stable Diffusion program? |
|machine-learning|reference-request|artificial-intelligence|computation-models|image-processing| |
null |
I have a constraint system which I seek to find solutions for.
The constraints consist of lesser/equal inequalities which have a difference of two minimum expressions on their right side, for example:
$x_1 <= min((x_2),(x_5 + x_6)) - min((x_3),(x_7 + x_9))$
$x_2 <= min((x_3 + x_4), (x_7)) - min((x_5 + x_8), (x_5... |
I have a constraint system which I seek to find solutions for.
The constraints consist of lesser/equal inequalities which have a difference of two minimum expressions on their right side, for example:
$x_1 \leq min((x_2),(x_5 + x_6)) - min((x_3),(x_7 + x_9))$
$x_2 \leq min((x_3 + x_4), (x_7)) - min((x_5 + x_8), ... |
I have a constraint system which I seek to find solutions for.
The constraints consist of lesser/equal inequalities which have a difference of two minimum expressions on their right side, for example:
$x_1 \leq min((x_2),(x_5 + x_6)) - min((x_3),(x_7 + x_8 + x_9))$
$x_2 \leq min((x_3 + x_4), (x_7)) - min((x_5 + ... |
Pretty new to posting questions, so apologies if I've made some faux-pas.
Professor is teaching us Tuple Relational Calculus, and is not very good at explaining. On our assignment he has solved an example for us. From what he's taught us, it's incorrect to use a quantifier (\exists or \forall) with a variable that's... |
Tuple Relational Calculus |
|relational-algebra|tuple-relational-calculus| |
I can't answer how Z3 works. I can only speculate on some possible ways one could build a solver for this type of constraints, if one wanted.
It appears all of your inequalities have the form
$$A \le \min(B,C) - \min(D,E)$$
where $A,B,C,D,E$ are linear expressions of the variables, i.e., each has the form $a_... |
null |
null |
|asymptotics|terminology|big-o-notation|notation| |
The theory of NP-completeness studies *decision problems* and (indirectly) *optimization problems*. In contrast, the theory of #P-completeness studies *counting problems*. In particular, NP is a class of *decision problems* while #P is a class of *counting problems*. The elements of these two classes are different, so ... |
null |
null |
in his original paper "on computable numbers with an application to the entscheidungsproblem"[[1]](https://www.cs.virginia.edu/~robins/Turing_Paper_1936.pdf) Turing didn't have halting problem (see [[2]](https://www.researchgate.net/profile/Salvador-Lucas/publication/352559794_Did_Turing_Care_of_the_Halting_Problem/lin... |
Given a list of integers ***NUMS*** and an integer ***k*** (buckets), we must allocate every integer from NUMS to some bucket such that *maximum* of sum of integers across all buckets is minimised.
A simple algorithm which first sorts **NUMS** and then allocates integer to smallest bucket so far doesn't work. Eg. 5... |
Minimising maximum sum algorithm |
|algorithms|correctness-proof|optimal-strategy| |
in his original paper "on computable numbers with an application to the entscheidungsproblem"[[1]](https://www.cs.virginia.edu/~robins/Turing_Paper_1936.pdf) Turing didn't have halting problem (see [[2]](https://www.researchgate.net/profile/Salvador-Lucas/publication/352559794_Did_Turing_Care_of_the_Halting_Problem/lin... |
Can we solve the halting problem with a modified model of computation that has an "undefined" state? |
Please recheck definitions in Turing's paper.
1. Circular machines *never* halt, and they get *stuck*, hence the term "circular". In a sense, the algorithm being executed by the machine (machines and algorithm are same) is *not applicable*. Which is why, as Turing remarks, they either enter into a state from which ... |
Consider `NUMS = [9, 7, 5, 4, 3]` and `k=2`.
Greedy algorithm would return `[9, 4]` and `[7, 5, 3]` which is not optimal, as `[9, 5]` and `[7, 4, 3]` is an optimal solution. |
No. Here is a counterexample (you seem to be sorting integers in decreasing order): $60, 50, 40, 29, 20$ and $2$ buckets. Your algorithm creates one bucket with sum $109$ and one bucket with sum $90$, while there exists a solution having a bucket with sum $99$ and the other with sum $100$.
Besides, if you algorithm ... |
No. Here is a counterexample (you seem to be sorting integers in decreasing order): $60, 50, 40, 29, 20$ and $2$ buckets. Your algorithm creates one bucket with sum $109$ and one bucket with sum $90$, while there exists a solution having a bucket with sum $99$ and the other with sum $100$.
Besides, if you algorithm ... |
No. Here is a counterexample (you seem to be sorting integers in decreasing order): $60, 50, 40, 29, 20$ and $2$ buckets. Your algorithm creates one bucket with sum $109$ and one bucket with sum $90$, while there exists a solution having a bucket with sum $99$ and the other with sum $100$.
Besides, if you algorithm ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.