instruction
stringlengths
0
29.8k
⌀
How to handle Insert and Delete requests arriving out of order?
|distributed-systems|concurrency|
I want to optimally assign $m$ jobs equally to $n$ workers, where $m>n$. Assume $m = an$ for some integer $a$, so that each worker must get exactly $a$ jobs. (The rectangular linear assignment problem, as defined [here][1]). I know this can be done by duplicating the workers to have $a$ copies of each, and then solving...
The obvious thing is that both Insert and Delete report exactly what has happened, so the caller can react. Second, design the Delete call so that it needs to pass for example the ID of a record. The Insert call would insert the record, create a new ID for it, and report that ID. As a result, you cannot call Delete...
If space and amount of hardware is no concern, then you can do what most CPUs do: For two n-bit numbers, use n^2 AND gates to produce n^2 zeroes and ones, then use n^2 full adders to reduce the number of values by 1/3, do that again until you can get the final result with one set of full adders. Time = O(log n), ha...
null
Background first, too: I am currently third-years student in Information and Computing Science at a Chinese university. I think most of your problems can be solved by common algorithms. For example, Sudoku game, can be solved by searching, or DLX(Dancing links and X algorithm) if you wanna improve the performance. ...
In almost all websites and papers, the complexity of LP problem is given in the number of iterations (such as https://or.stackexchange.com/a/5924). I was wondering if there are any references where worst-case "time" complexity is discussed. Like, the time to solve LP problem is bounded above by...?
Time complexity of LP problems
|complexity-theory|time-complexity|
You say "If there is an ADD instruction in memory, then the adder is activated"... You're missing something very important here: Your CPU doesn't _know_ that there's an ADD instruction. So Step 1: Read the first byte or bytes of the instruction. Step 2: Figure out from the bytes read that it is an ADD instruction (o...
The text alludes to the fact in the early days of computing machines, the "program" was hard-wired, for instance via a board of switches or via electric wires drawn between terminals. Only data was stored in the working memory. But the engineers soon understood that the program itself could be handled like data and ...
The text alludes to the fact in the early days of computing machines, the "program" was hard-wired, for instance via a board of switches or via electric wires drawn between terminals, or even directly read from punched tape/cards. Only data was stored in the working memory, instructions were... elsewhere. But the en...
I claim that this algorithm returns the integer square root of any integer in the range 1 to 1000: Sqrt(int X) return 0 Is it correct ? How can you convince me that it is correct (or incorrect) ? What about Sqrt(int X) int Y= 1, Z= 0 while Y != Z: Z= Y Y= (X / ...
Entries need to be stored in a database. There is `Insert(entry)` RPC, which adds a new entry in a database, and `Delete(entry)` RPC, which deletes an existing entry from a database. The problem happens, when `Insert(entry)` RPC is supposed happen before `Delete(entry)` RPC, but due to various reasons (e.g. network ...
Entries need to be stored in a database. There is `Insert(entry)` RPC, which adds a new entry in a database, and `Delete(entry)` RPC, which deletes an existing entry from a database. Neither RPC can be blocking, because that adds undesired latency. Both RPCs are scheduled to run asynchronously when required, from diffe...
null
While doing the exercise about questions about transforming NDFA to CFG, I encountered the following question: Find a CFG for the following NDFA $M = (\{q_0, q_1\}, \{a, b\}, \{A, z\}, \delta, q_0, z, \{q_1\})$, with transitions: $$ \begin{align} \delta(q_0, a, z) &= \{(q_0, Az)\} \\ \delta(q_0, b, A) &= \{(q_0...
Non-deterministic Finite Automata to Context-Free Grammar
|context-free|pushdown-automata|nondeterminism|
While doing the exercise about questions about transforming NDFA to CFG, I encountered the following question: Find a CFG for the following NDFA $M = (\{q_0, q_1\}, \{a, b\}, \{A, z\}, \delta, q_0, z, \{q_1\})$, with transitions: $$ \begin{align} \delta(q_0, a, z) &= \{(q_0, Az)\} \\ \delta(q_0, b, A) &= \{(q_0...
While doing the exercise about questions about transforming NPDA to CFG, I encountered the following question: Find a CFG for the following NPDA $M = (\{q_0, q_1\}, \{a, b\}, \{A, z\}, \delta, q_0, z, \{q_1\})$, with transitions: $$ \begin{align} \delta(q_0, a, z) &= \{(q_0, Az)\} \\ \delta(q_0, b, A) &= \{(q_0...
Non-deterministic Pushdown Automaton to Context-Free Grammar
null
One of the most compelling arguments people cite for believing $P \ne NP$ is that there are many problems of both theoretical and practical significance for which an efficient solution has eluded many intelligent people's concerted efforts for a very long period of time. The strength of this argument seems to depend...
Are there problems in $P$, long suspected to be $NPC$ (or $NPI$)?
|complexity-theory|p-vs-np|
No, $\Omega(m^3)$ is not a lower bound. Your problem can be solved in $O((nm)^{1 + o(1)} \log a)$ time, by [reducing to max flow](https://cstheory.stackexchange.com/a/51804/5038) and then using a state-of-the-art min cost max flow algorithm, such as the recent algorithm by [Chen et al](https://arxiv.org/abs/2203.006...
There are a few problems where we were not sure whether they were in P or not, and then later were found to be in P. Not a lot, but a few. Probably the leading example is [primality testing](https://en.wikipedia.org/wiki/Primality_test). Even before it was known to be in P, I think many computer scientists still s...
There are a few problems where we were not sure whether they were in P or not, and then later were found to be in P. Not a lot, but a few. Probably the leading example is [primality testing](https://en.wikipedia.org/wiki/Primality_test). Even before it was known to be in P, I think many computer scientists still s...
null
I have a 3D scan of an object with multiple faces, for example a standard 6 face die. The scan is a point cloud file of the die. I am able to convert the point cloud into a mesh and retrieve faces from the mesh. But what I'm not able to figure out is how to smooth the faces so instead of having thousands of faces ...
How can I smooth thousands of faces in a 3D-mesh so as to end up with 6 faces of a die?
|computational-geometry|computer-vision|
Given computable function $f : LispTerm \rightarrow LispTerm$ is it possible to implement it in Lisp? The $LispTerm$ is any term that is constructed using `cons`, `nil` and `set-car!`, `set-cdr!` (because it can be cyclic). Of course Lisp is Turing-Complete, but that does not immediately imply an answer because L...
Simple proof that Lisp expresses all computable list functions
|computability|programming-languages|turing-completeness|lisp|
If the corners aren't too rounded, you can try to find vertices close to the eight actual corners. - compute the centroid; - find V0, the vertex farthest from the centroid; - find V1, the vertex farthest from V0 (V0V1 is a long diagonal of the cube); - find V2, the vertex farthest from the line V0V1; - f...
null
Given computable function $f : LispTerm \rightarrow LispTerm$ is it possible to implement it in Lisp? The $LispTerm$ is any term that is constructed using `cons`, `nil` and `set-car!`, `set-cdr!` (because it can be cyclic). Of course Lisp is Turing-Complete, but that does not immediately imply an answer because L...
null
**1. Detecting cycle using Floyd's cycle detection algorithm** - for this we need answer to the question: what's the guarantee that the hare and the tortoise will meet? **2. Detecting the starting point of the cycle (in a linked-list)** - As per the behavior of Floyd's algorithm, i.e., from the meeting point (`µ`)...
null
null
Assume there is a cycle of length r, which is entered after m steps. Once you enter the cycle, you stay in the cycle. After either m steps, or after 1 step if m = r, both tortoise and hare are in the cycle. Either they are in the same position, or the hare is k steps behind the tortoise for some 1 ≤ k ≤ r-1. With every...
By [duality](https://en.wikipedia.org/wiki/Duality_(projective_geometry)), this problem is equivalent to the halfplane range query problem. For the worst-case complexity, there is a known space-time tradeoff of [1]: - $O(n^2/\log^2 n)$ data structure size and $O(\log n)$ query time. - $O(n)$ data structure size ...
*For any grammar in Greibach normal form, every sentential form obtained from S by a partial left-most derivation is of the form xy with x terminals and y variables.* I think that this can be proven inductively based on the length of the derivation. Base case: length 1 S -> a with 'a' being a terminal. This fo...
Greibach Normal Form: Proof every sentential form is of the form xy with x terminals and y variables
|formal-languages|context-free|formal-grammars|normal-forms|derivation|
null
I am looking at some social network analysis and I need to do link prediction. By link prediction I mean that I only have a subset of the relationships in the network, and I need to make predictions about the unseen relationships. I am familiar with the more traditional or common methods for link prediction from ...
Link prediction in a network using GNNs versus Matrix Completion and other methods
|graphs|neural-networks|factoring|
null
I am a newbie to the world of algorithms design and currently working on a algorithm which is related to **cell-phone user associating** with **cell-phone tower**. Let $\mathcal{K} = \{1,\dots,K\}$ be set of cell-phone users and $\mathcal{J} = \{1,\dots,J\}$ be set of cell-phone towers. One of the step of this algor...
Understanding the step in given algorithm?
|algorithms|combinatorics|algorithm-design|
I am a newbie to the world of algorithms design and currently working on a algorithm which is related to **cell-phone user associating** with **cell-phone tower**. Let $\mathcal{K} = \{1,\dots,K\}$ be set of cell-phone users and $\mathcal{J} = \{1,\dots,J\}$ be set of cell-phone towers. Let $k$ and $j$ be index of cell...
Management frowns upon "check my proof" questions, but this is a good exercise on induction. Your answer is basically correct, except for a little tuning at the base case. We are not necessarily dealing with succesful derivations, so we cannot restrict to terminal productions in the first step. In fact, if this woul...
Given computable function $f : LispTerm \rightarrow LispTerm$ is it possible to implement it in Lisp? The $LispTerm$ is any term that is constructed using `cons`, `nil` and `set-car!`, `set-cdr!` (because it can be cyclic). Of course Lisp is Turing-Complete, but that does not immediately imply an answer because L...
Given computable function $f : LispTerm \rightarrow LispTerm$ is it possible to implement it in Lisp? The $LispTerm$ is any term that is constructed using `cons`, `nil` and `set-car!`, `set-cdr!` (because it can be cyclic). Of course Lisp is Turing-Complete, but that does not immediately imply an answer because L...
null
Given computable function $f : LispTerm \rightarrow LispTerm$ is it possible to implement it in Lisp? The $LispTerm$ is any term that is constructed using `cons`, `nil` and `set-car!`, `set-cdr!` (because it can be cyclic). Of course Lisp is Turing-Complete, but that does not immediately imply an answer because L...
null
null
Preparata & Shamos in "Convex Hulls: Basic Algorithms" (1985), give a linear algorithm for merging two convex hulls in $O(n+m)$ time, where $n$ and $m$ are the numbers of vertices in each input hull. Now, if you had a third convex hull to merge of size $l$, you could do that in $O(x+l)$ time, where $x \le n + m$, which...
What is the optimal algorithm for merging an arbitrary number of convex hulls?
|algorithm-analysis|computational-geometry|convex-hull|
the result will not be linear. Doing the merge between partial result and the next hull will be $O(x_{i-1}+m_i)$ where $x_{i-1}$ is the amount of points in the partial result. So doing the merge iteratively means you end up with $$O(\sum{(x_{i-1}} + {m_i}))$$ $$O(\sum{x_{i-1}} + \sum{m_i})$$ that first sum of...
null
null
Given a finite set of equations in [ANF][1], for example: $$ \begin{cases} (x_1 \land x_2) \oplus (x_1 \land x_3 \land x_4) \oplus 1 = 0 \\ x_3 \oplus (x_2 \land x_3 \land x_4) = 0 \\ (x_1 \land x_4) \oplus (x_1 \land x_2) \oplus (x_3 \land x_4) = 0 \end{cases} $$ Is this P or NP? The only assumption is t...
Is system of ANF polynomials P or NP?
|complexity-theory|satisfiability|p-vs-np|
I am following a [LeetCode tutorial for Disjoint sets][1] I have trouble understanding why the so called "Quick Find" method needs to take O(n) time. I have implemented an data structure that has an optimised Union operation and it is O(1). // Base class for all types of disjoint sets. class DisjointSe...
Disjoint Set Constant Time Union Operation
|disjoint-sets|
Is ANF-SAT P or NP?
If you are asking about the problem where the input is a system of equations in ANF (algebraic normal form) and the output is whether the system of equations is satisfiable, this problem is NP-complete. There is a reduction from 3SAT. Suppose we have a 3CNF formula $\varphi = C_1 \land \cdots \land C_m$, where $C_i...
Unfortunately, your implementation of disjoint sets does not work. For example, consider the following calling sequence. ```c s = FastUnionSlowFindSet(3); s.union_(0,1); s.union_(2,1); ``` After two union operations, all three vertices `0, 1, 2` should be in the same set. However, the only relation we...
null
null
null
null
null
null
null
Final Answer in Python which could probably be written better: def check_winner(A): n = 6 # rows m = 6 # columns Os = ["O","O","O","O"] Xs = ["X","X","X","X"] # horizontal lines row_check = [] for i in range(n): for...
In our class we considered the problem written in the title. The below given time complexities where simply given, but not derived or explained. Therefore I tried myself to derive them, while I using math or simply intuition. I am able to explain, how one of the complexities comes about, but not the other one. I haven...
Time complexity for finding the nr. of triangles in a graph
|algorithms|time-complexity|runtime-analysis|
The question is LALR(1) parsing of the following: S->AA A->aA A->b The link to the question is on this page:https://www.javatpoint.com/lalr-1-parsing My question concerns I3, where despite a being read there is another production A->aA, a/b, where the a is *not* read. I wish to know the reasons for this. I...
Why do we retain A->.aA,a/b in I3 stage of LALR parsing of S->AA, a->Aa/B?
|compilers|parsers|
To represent complexity of an algorithm, Computer Scientist is used to using big-O notation. How about complexity of boolean algebra? Boolean algebra is commonly used in digital circuit design with using logic gates, practically useful in FPGA programming. Speaking about logic gates circuit, This topic maybe loo...
Is there a notation for boolean algebra complexity?
|complexity-theory|boolean-algebra|boolean-complexity|
null
This is called *Circuit Complexity*: https://en.wikipedia.org/wiki/Circuit_complexity > The size of a circuit is the number of gates it contains and its depth > is the maximal length of a path from an input gate to the output gate. > > There are two major notions of circuit complexity. The *circuit-size* > compl...
In our class we considered the problem written in the title. The below given time complexities where simply given, but not derived or explained. Therefore I tried myself to derive them, while I using math or simply intuition. I am able to explain, how one of the complexities comes about, but not the other one. I haven...