instruction stringlengths 0 29.8k ⌀ |
|---|
The signal operation can be implemented with spinlocks? |
|os-kernel|semaphore| |
Is it possible for an online algorithm to perform better than the optimal solution for the offline version of a problem, and if so, in what circumstances?
Doesn't competitive ratio rely on the fact that online algorithm can only reach at most the same performance as the optimal offline solution ? |
Competitiveness of online algorithm |
|online-algorithms| |
I'm currently reading Design Patterns: Elements of Reusable Object-Oriented Software by GoF and having trouble understanding the following sentence (page 19, Section 1.6):
> Composition requires objects to respect each others' interfaces,
which in turn requires carefully designed interfaces that don't stop you from... |
Clarification about a sentence from GoF Design Patterns book |
|books|object-oriented|design-patterns| |
Say there exist some optimal online $A$ that is better than any offline, we can still create an offline algorithm $A'$ such that when $A'$ recieves the input sequence, it will not perform any preprocessing, instead it will feed each request to $A$. This offline algorithm must be optimal, given that $A$ is optimal and b... |
null |
Say there exist some optimal online algorithm $A$ that is better than any offline algorithm. We can create an offline algorithm $A'$ such that when $A'$ recieves the input sequence, it will not perform any preprocessing, instead it will feed each request to $A$ one at a time. This offline algorithm must be optimal, giv... |
Another common name for such a "map" data structure is *Map*. That's what it is called in [C++](https://cplusplus.com/reference/map/map/), [Java](https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/util/Map.html), [ECMAScript](https://tc39.es/ecma262/#sec-map-objects), [PHP](https://php.net/manual/en/clas... |
Let $H$ be the max-heap represented as an array. We assume that the elements of the heap occupy the non-zero indices of $H$ e.g. the maximum element is at index 1. Also, I will use depth instead of level but that should not be a problem.
Notice that all elements at depth $d$ of the heap and their children, which are... |
ERROR: type should be string, got "https://complexityzoo.net/Complexity_Zoo:R\r\n\r\n> RL: Randomized Logarithmic-Space Has the same relation to L as RP does\r\n> to P. The randomized machine must halt with probability 1 on any\r\n> input. It must also run in polynomial time (since otherwise we would\r\n> just get NL).\r\n> \r\n> Contains R<sub>H</sub>L.\r\n\r\nWhile requiring runtime in polynomial time avoids trivial RL=NL, it also allows running time stored. If an algorithm would on average take $f(n)$ steps, then trying to run $100f(n)$ steps would only have 1% chance of not halting, and rejecting in this case doesn't harm.\r\n\r\nSo why only \"Contains R<sub>H</sub>L\" shown?" |
How can $R_HL$ differ from $RL$? |
|complexity-classes|probabilistic-algorithms| |
null |
Let $H$ be the max-heap represented as an array. We assume that the elements of the heap occupy the non-zero indices of $H$ e.g. the maximum element is at index 1. Also, I will use depth instead of level but that should not be a problem.
Notice that all elements at depth $d$ of the heap and their children, which are... |
You have the right approach.
------
Let the original flow network be the directed graph $G = (V, E)$ with capacity function $c$. Consider a new flow network $(G, c')$, where the capacity function $c^-$ is $\epsilon $ less than $c$. That is, there is constant $\epsilon>0$ such that $c^-(e)=c(e)-\epsilon$ for each... |
P.S. Sorry if this question is not meant for this community, was wondering whether or not to ask this question here or on Stack Overflow.
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 ... |
null |
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 it's implementation.
But now I... |
null |
***Newton-Raphson solution for n***
Need to find a root for this formula with one unknown, n
(p ((1 + r)^n - (1 + x)^n))/(r - x) + c (1 + r)^n - fv = 0
Using the algorithm here: https://en.wikipedia.org/wiki/Newton%27s_method#Code
This method requires the derivative of the formula.
[, [Java](https://docs.oracle.com/en/java/javase/19/docs/api/java.base/java/util/Map.html), [ECMAScript](https://tc39.es/ecma262/#sec-map-objects), [PHP](https://php.net/manual/en/clas... |
It is not currently known whether your problem is $\mathsf{NP}$-complete, but it can definitely be solved in polynomial time since it can be reduced to 2-SAT. If we assume $\mathsf{P} \neq \mathsf{NP}$, then your problem is not $\mathsf{NP}$-complete.
The reduction is as follows: a clause $(\ell_1, \ell_2, \ell_3)$ ... |
In "Modelling Computing Systems: Mathematics for Computer Science", I came across a logic exercise to inductively define a merge sort function 'mergeSort', with a hint to first define auxillary functions 'split' and 'merge'. The style of the logic so far looks like this for inductively defined sets Odd and Even, and so... |
Logic for Computer Science - How to define msort, merge and split functions inductively? |
|logic|induction|lists| |
While I was learning the Constraint Satisfaction Problems, I analyzed the Knapsack problem(https://www.csplib.org/Problems/prob133/) and I saw the approach with the neural network was not the best approach in solving this problem since it has not shown the best results. Knowing that the neural network approach has show... |
New Knapsack Problem solution with neural network approach |
|artificial-intelligence|knapsack-problems|constraint-satisfaction|research| |
You can avoid odd and even by considering one more case in `split`. Any you need recursive calls in `mergeSort`. Here's a working Haskell solution.
```haskell
split :: [a] -> ([a], [a])
split [] = ([], [])
split [x] = ([x], [])
split [x,y] = ([x], [y])
split (x : y : l) = (x:xs, y:ys) where ... |
null |
Here is a simple algorithm that is based on your idea to modify the capacity function.
------
Suppose the given flow network is directed graph $G=(V,E)$ with capacity function $c$.
Let $\epsilon>0$ be a constant that is small enough. Consider a new capacity function $c^-$ that is $\epsilon $ less than $c$, i.... |
ERROR: type should be string, got "https://complexityzoo.net/Complexity_Zoo:R\r\n\r\n> RL: Randomized Logarithmic-Space Has the same relation to L as RP does\r\n> to P. The randomized machine must halt with probability 1 on any\r\n> input. It must also run in polynomial time (since otherwise we would\r\n> just get NL).\r\n> \r\n> Contains R<sub>H</sub>L.\r\n\r\nWhile requiring runtime in polynomial time avoids trivial RL=NL, it also allows running time stored. If an algorithm would on average take $f(n)$ steps, then trying to run $100f(n)$ steps would only have 1% chance of not halting, and rejecting in this case doesn't harm.\r\n\r\nSo why only \"Contains R<sub>H</sub>L\" shown?\r\n\r\n\r\n---\r\n\r\nAnswering D.W.\r\n\r\n> What does \"allows running time stored\" mean?\r\n\r\nLogarithmic-Space allows storing polynomial-size integer\r\n\r\n> What do you mean by \"rejecting doesn't harm\"?\r\n\r\nIf X is in RL, then there's an algorithm that accept for 51% chance for input in X, and we can construct one that accept for 50% chance and never fall into infinite loop\r\n\r\n> Why do you think the two classes should be equal? Their definitions are different.\r\n\r\n> R<sub>H</sub>L: Randomized Halting Logarithmic-Space\r\n>\r\n> Has the same relation to L as RP does to P. The randomized machine must halt for every input and every setting of the random tape. " |
|complexity-theory|graphs|polynomial-time-reductions|vertex-cover|independent-sets| |
null |
Would it be correct to say that on a operation with a Non-regular language (L) with a Regular language will always return the language L?
I'm came across a property that when we intersect a non-regular language (say L) with Regular Language the resultant result will always remain in Language L.
$L \cap Reg = L$
... |
Operation of non-regular with regular language |
|regular-languages| |
null |
I am looking for all possible ways to find and eliminate ambiguity in CF grammar. Please share your knowledge or opinion (preferably you will indicate the literature so that I can familiarize myself). I know that ambiguity can generate chain rules. I also know that some constructions, for example S->SaS, generate ambig... |
Methods of eliminating ambiguity in CFG |
|formal-languages|context-free|formal-grammars|ambiguity| |
I want to know if checking whether a 3-SAT is satsifiable if and only if every clause has at least 2 or all three literal set to true NP-complete?
It seems similar to Exact-3SAT but it differs from it as the version of this problem which we'll call Exact2or3-3SAT ,where all literals are positive is trivial as its a... |
null |
This question:https://cs.stackexchange.com/q/16483
asked whether quasi-monotone SAT is NP-complete or not ?
I want to know if the restricted version of this SAT that is quasi-monotone 3-SAT is NP-complete or not, in this restricted quasi-monotone 3-SAT each clause has exactly 3 literal ? |
Complexity of deciding the satisfiability of quasi-monotone 3-SAT? |
|complexity-theory|np-complete| |
A question in a textbook says, suppose the regular Clique problem, which takes as input a graph G and a natural number k, and returns whether or not G has a clique of size >= k, can be decided in time T(n) (for some function T: N → N). Then, prove that the problem of finding the size of the largest clique in G can be d... |
Clique Complexity Problem |
|time-complexity|asymptotics|big-o-notation|clique| |
Basic Clique Complexity Problem |
Complexity of finding size of largest clique given subroutine for checking the existence of a clique of size k |
The answer to the question you linked already shows how to transform a quasi-monotone 3-SAT formula into a quasi-monotone formula in which each clause has either $2$ or $3$ literals.
To get a formula in which each clause has exactly 3 literals, we just need to "pad" each clause with $2$ literals while preserving qua... |
null |
The answer to the question you linked already shows how to transform a quasi-monotone 3-SAT formula into a quasi-monotone formula in which each clause has either $2$ or $3$ literals.
To get a formula in which each clause has exactly 3 literals, we just need to "pad" each clause with $2$ literals while preserving qua... |
Basic Clique Complexity Question |
I'm trying to know what is the exact function in medium term scheduler in operating systems.
As far my understanding, a process may be needed to be removed from the running queue when it is faced with an I/O request. So it is usually sent to blocked list which is also situated in the main memory. Medium term schedul... |
What does exactly Medium term scheduler do? |
|operating-systems| |
I'm studying the algebraic view of automata theory. One of the basic results is that the **syntactic monoid** of a language $L$ is the transition monoid $M(A)$ of the **minimal automaton** $A(L)$ accepting $L$. It is also very easy, from a monoid $M$ and a morphism $\mu:\Sigma^*\to M$, to build an equivalent determinis... |
Building the minimal automaton from the syntactic monoid of a language |
|finite-automata|reference-request| |
Studying for the exam in "Advanced Algorithms" course. I'm trying to solve the following question:
> This question discusses a search operation for a vertex `x` in a splay tree. Determine how the depth of the vertices changes along the route from the root of the tree to `x` when, during the splay to the root, zig-za... |
How the depth of the vertices changes along the route in the splay tree after search |
|algorithms|data-structures|trees|splay-trees| |
null |
For C and C++, the linker's job is the same, ignoring template classes/functions.
The .o / .obj files are split into Sections, each of which has a Symbol Table.
The Symbol Table has the offset into this Section of each exported Symbol (function, global variable), and a set of relations. These are the function cal... |
To be more precise, Is `~(a+b) = ~a + ~b`? Here, `"~"` bitwise NOT operator.
I ran into this question while thinking about the 2's complement, which adds `1` to `~x` (i.e., `-x = ~x + 1`).
Suppose we are given `-x` (in binary), and we need to find `x` (in binary). We can do this by computing `x = ~(-x-1)`, but co... |
Is "Bitwise Complement Operator" (~ tilde) distributive? |
|logic|propositional-logic|mathematical-foundations|mathematical-analysis|bit-manipulation| |
f(n) = log n^2; g(n) = log n + 5 => f(n) = Θ (g(n))
I think we can prove this for omega but how can we prove it for Big oh ?
because if we simplify it to logn + logn <= logn +5 => logn<=5 is not true ! |
How to prove this because if we consider big-oh than logn^2 <= log n + 5 can never happen if n grows? |
|algorithms|time-complexity|data-structures|asymptotics|big-o-notation| |
To show $f(n) = O(g(n))$ pick $n_0 = 1$ and $c=2$. Then, for any $n \ge n_0$,
$$
f(n) = \log n^2 = 2 \log n < 2 \log n + 10 = 2(\log n+5) = c g(n).
$$
For the opposite direction (i.e., $g(n) = O(f(n))$) pick $n_0 = 2^5$ and $c=1$. For any $n \ge n_0$:
$$
g(n) = \log n +5 = \log n + \log 2^5 = \log 2^5n \le \log... |
Obviously, $$2\log(n)\le 2(\log(n)+5)$$ for all $n$, so
$$\log(n^2)=O(\log(n)+5).$$
----------
The $\Omega$ bound is slightly more difficult, as it does not hold for all $n$:
$$\log(n)+5\le2\log(n)$$ only for $n\ge e^5$. |
Obviously, $$2\log(n)\le 2(\log(n)+5)$$ for all $n$, so
$$\log(n^2)=O(\log(n)+5).$$
----------
The $\Omega$ bound is slightly more difficult, as it does not hold for all $n$:
$$\log(n)+5\le2\log(n)$$ only for $n\ge e^5$.
(More generally, $c(\log(n)+5)\le 2\log(n)\iff n\ge e^{ 5c/(2-c)}\land c<2$.) |
A question in a textbook says, suppose the regular Clique problem, which takes as input a graph G and a natural number k, and returns whether or not G has a clique of size >= k, can be decided in time T(n) (for some function T: N → N) where n is the size of the input. Then, prove that the problem of finding the size of... |
The given trees are, in fact, paths. They can be encoded/given as a multiset of pairs $(\ell, \text{direction})$ where $\ell$ is the length of the path and $\text{direction}$ is either $\text{top}$ or $\text{bottom}$ that indicates whether the path should start at the top row or at the bottom row. For instance, the tre... |
Hoare triple derivations use axioms and rules of Hoare logic. In this case, one would use (1) an instance of the assigment axiom followed by (2) an instance of the consequence rule. Yves Daoust's comment spells out the relevant premise (2). |
All the sources I find on the internet say the time complexity of quick sort is worse if:
> - input array is sorted and we choose the leftmost element as the pivot
> - input array is sorted reversely and we choose the rightmost element as the pivot
I am wondering if time complexity is still $O(n^2)$ if we do the... |
Tweaking traditional quicksort worst cases |
|algorithm-analysis| |
How can i derive this Hoare Tripel?
{false} x := x + 1; {x = 0}
I do not know which rule should i use on this.
I am confused on this wrong precondition. |
null |
For most of the time one can't make sweeping statements about operations between any non-regular language and any regular language. The intuitive reasoning is that regular languages are a very broad collection of languages. Every non-regular language is the subset of a regular language, and every non-regular language h... |
As I stumbled upon this today and found after some further research out that this has been solved, I want to mention this here.
[![screenshot of abstract][1]][1]
By this, the asked problem is FPT (so $t=0$ for the last sentence in the abstract).
The paper is "On the parameterized complexity of (k,s)-SAT" by Pa... |
As I stumbled upon this today and found after some further research out that this has been solved, I want to mention this here.
[![screenshot of abstract][1]][1]
By this, the asked problem is FPT (so $t=0$ for the last sentence in the abstract).
The paper is "On the parameterized complexity of (k,s)-SAT" by Pa... |
The language is undecidable, and is proven immediately by [Rice's Theorem][1].
These languages are recursively enumerable (since they are the languages of Turing machines), and being accepted by a Turing Machine of at most 37 states is a property of those languages; furthermore some languages will fit the criteria (... |
Quicksort's behavior is bad when every partition is imbalanced (instead of splitting $m$ elements in two, the split is like $1$ vs. $m-1$). A good pivot is one which has a rank close to the median. In case of an already sorted array, the middle element would be a good choice. |
Quicksort's behavior is bad when every partition is imbalanced (instead of splitting $m$ elements in two, the split is like $1$ vs. $m-1$), leading to $O(n^2)$. A good pivot is one which has a rank close to the median ($O(n\log n)$). In case of an already sorted array, the middle element would be a good choice. |
Certainly not. By De Morgan's law,
$$\lnot(a\lor b)=(\lnot a)\land(\lnot b)\\\ne(\lnot a)\lor(\lnot b)$$
and this carries on the bitwise case. |
Certainly not. By De Morgan's law,
$$\lnot(a\lor b)=(\lnot a)\land(\lnot b)\\\ne(\lnot a)\lor(\lnot b)$$
and this carries to the bitwise case.
----------
Adding one to a binary number is virtually as easy as flipping: start from the right, flip the bit and if was a $1$, carry to the next.
|
As we all know, 3-SAT is NP-hard.
Two of the less known results are that [Planar 3-SAT is NP-hard][1] and also a ['restricted' 3-SAT][2], where any literal appears in at most two clauses turns out to be NP-hard.
My question is if there is any known result on what happens if we combine these two conditions? That is, ... |
Restricted Planar 3-SAT NP-hard |
|complexity-theory|graphs|np-complete|satisfiability| |
As we all know, 3-SAT is NP-hard.
Two of the less known results are that [Planar 3-SAT is NP-hard][1] and also a ['restricted' 3-SAT][2], where any literal appears in at most two clauses turns out to be NP-hard.
My question is if there is any known result on what happens if we combine these two conditions? That is, ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.