instruction
stringlengths
0
29.8k
⌀
|algorithms|streaming-algorithm|
Let the sequences be $A_{1..n}$ and $B_{1..n}$, merging takes $2n - 1$ comparisons if $A_1 < B_1 < A_2 < B_2 < A_3 < B_3 < \cdots < A_n < B_n$. It compares $A_1$ with $B_1$, $A_2$ with $B_1$, $A_2$ with $B_2$, $A_3$ with $B_2$, $A_3$ with $B_3$, to $A_n$ with $B_n$. It is identical to $A_1$ with $B_1$, $B_1$ with...
|operating-systems|efficiency|memory-hardware|os-kernel|comparison|
I am trying to understand how to approach the question below and I am stuck. I understand that each memory request is 32 bits and so there will be 262144 requests. There are 42 blocks in the cache. I am not sure how to think about this in terms of cache hits and misses. Can someone give me a hint? Consider a machine...
Expected hit ratio for a cache
|computer-architecture|
You can't. It's not possible to do this in $O(\log n)$ time. Consider the following two possibilities for the tritonic array: 1. We have an array $A^1$ that contains the values $1,2,3,4,\dots,n$, except that at index $i$, we have the value $2n$. 1. We have an array $A^2$ that contains the values $1,2,3,4,\dot...
null
I would recommend "Proofs as Games" by Pavel Pudlak. I find the prover-adversary model quite useful for building intuition. For example, soundness and completeness of resolution are trivial (Prover just queries all variables). It has been used, for example, in "Planar tautologies are hard for resolution" by Dantchev an...
I would recommend "Proofs as Games" by Pavel Pudlak. I find the prover-adversary model quite useful for building intuition. For example, soundness and completeness of resolution are trivial (Prover just queries all variables). It has been used, for example, in "Planar tautologies are hard for resolution" by Dantchev an...
null
Do we know anything about the hardness of the optimization version of the [multiway number partitioning problem](https://en.wikipedia.org/wiki/Multiway_number_partitioning) when the set of numbers to partition consists of the reciprocals of the first $n$ integers? That is, for $n, k\in \mathbb{N}$, find $\{S_i\}_{i=1}^...
Optimally partitioning the reciprocals of the first n integers
|algorithms|partitions|
Locating a sequence of 2D points in a set of polygons with holes
|graphs|computational-geometry|polygons|
Using the CGAL library, I am working on a 2D layout graph which contains an array of 2D polygons with holes. The aim is to generate random points (based on some conditions) and only keep the points inside the area of 2D polygons but not in their holes. The function I use for this is `CGAL::bounded_side_2`. Please see t...
[![Picture of a standard 4 player catan board with all edges filled with blue roads][2]][2] In Catan you can calculate the longest road by finding the longest (most roads) path with does not repeat any edges/roads, and does not cross through a vertex controlled by another player. I started doing an algorithm tha...
How to efficiently calculate the longest road in catan?
|graph-traversal|
null
Do you want to know why "the others" obtained a different expression? When constructing a regular expression, there is no unique correct answer. There are usually several expressions "that make sense." In this case, you use the state elimination method (I learned this under the name of Brzozowski and McCluskey). Her...
null
Do you want to know why "the others" obtained a different expression? When constructing a regular expression, there is no unique correct answer. There are usually several expressions "that make sense." In this case, you use the state elimination method (I learned this under the name of Brzozowski and McCluskey). Her...
[![Picture of a standard 4 player catan board with all edges filled with blue roads][2]][2] In Catan you can calculate the longest road by finding the longest (most roads) path which does not repeat any edges/roads, and does not cross through a vertex controlled by another player. I started doing an algorithm th...
[![enter image description here][1]][1] [![enter image description here][2]][2] **The info I am given** : block_ID, block_width, block_height as well as how the cuts between the rectangles are(horizontal or vertical); for example two rectangles can be joined by a horizontal cut or a vertical cut. **See above pict...
[![what the floorplan should look like][1]][1] [![enter image description here][2]][2] [![enter image description here][3]][3] **The info I am given** : block_ID, block_width, block_height as well as how the cuts between the rectangles are(horizontal or vertical); for example two rectangles can be joined by a ...
null
You stated "Obviously it is NOT good for keeping count of items". The sentence shows that you lack a clear understanding of both the problem that the Count-min sketch tries to solve (in particular how much difficult it is) and of the techniques it actually uses. Let's start with the problem. Count-min is a freque...
I am trying to understand how to approach the question below which is a coursework question. I understand that each memory request is 32 bits and so there will be 262144 requests. There are 42 blocks in the cache. I am not sure how to think about this in terms of cache hits and misses. Is this question even well define...
I am trying to understand how to approach the question below which is a coursework question. I understand that each memory request is 32 bits and so there will be 262144 requests. There are 42 blocks in the cache. I am not sure how to think about this in terms of cache hits and misses. Is this question even well define...
I've been looking online for quite some time for some 'general' rules on this. for example, there's a 'rule' that claims that if a language is like $$L={w\in {a,b,c}^* : count_\alpha (w) =count_\beta (w) \pm count_\gamma (w) }$$ where $\alpha , \beta , \gamma $ could take on the form of one of the characters in $\Si...
General rules to tell if a language is regular/CFL/decidable/recognizable
|regular-languages|context-free|decidability|
I can't find space complexity of this problem with search engines. I think I have NL algorithm for it (just a basic "one by one non-deterministically accept values if possible"), but I wonder what other research was done on it. Any references and/or ideas?
Is "Length of Longest Increasing Subsequence" in L?
|complexity-theory|reference-request|space-complexity|subsequences|longest-increasing-subsequence|
null
So, I know that this is true, but I can't seem to prove it. My approach was the following: Let $f(n) = o(g(n)) \Rightarrow 0 \le f(n) < c_2g(n)$ for some $c_2 > 0$ and for all $n \ge n_1 \ge 0$ Similarly, $f(n) = \omega(g(n)) \Rightarrow 0 \le c_1g(n) < f(n)$ for some $c_1 > 0$ and for all $n \ge n_2 \ge 0 ...
Prove that $o(g(n)) \cap \omega(g(n))$ is the empty set
|algorithms|time-complexity|
This question is from CLRS (3rd Edition). So, I know that this is true, but I can't seem to prove it. My approach was the following: Let $f(n) = o(g(n)) \Rightarrow 0 \le f(n) < c_2g(n)$ for some $c_2 > 0$ and for all $n \ge n_1 \ge 0$ Similarly, $f(n) = \omega(g(n)) \Rightarrow 0 \le c_1g(n) < f(n)$ for s...
The problem: > Given two boolean formulas in 2-CNF, decide if they are equivalent. I know that the problem is $\mathsf{coNP}$-hard when at least one formula is in 3-CNF. However, the same proof of $\mathsf{coNP}$-hardness does not apply when both formulas are in 2-CNF. Conversely, I don't see a straightforward...
Is boolean formula equivalence problem for 2-CNFs $\mathsf{coNP}$-hard?
|complexity-theory|satisfiability|boolean-algebra|
{"Voters":[{"Id":71879,"DisplayName":"rus9384"}],"DeleteType":1}
{"Voters":[{"Id":71879,"DisplayName":"rus9384"}]}
What is wrong is your definition of $o$ and $\omega$. $f\in o(g)$ if and only if $f(n) = h(n)g(n)$ with $h(n) \underset{n\rightarrow +\infty}{\longrightarrow}0$. $f\in \omega(g)$ if and only if $g\in o(f)$. What you used as definition are $\mathcal{O}$ and $\Omega$ (which are different).
The sum of all elements is H_n (n-th harmonic number), approximately ln n + c where ln is the natural logarithm and c is quite small. If k > H_n then the average size of a set is less than 1. So take {1} as the first set and you have H_n - 1 and k-1 sets left. If the average is > 1/2 then you take the set {1/2} etc...
I am a mathematician that is going to switch subjects to theoretical computer science. From maths I am used to reading papers and books very slowly (almost as slow as possible) and I usually expect to need an hour per page, so reading a book of 500pages is almost impossible (and I never did). But now I am reading a boo...
How fast should you read a textbook?
|general|
Given a set of points $S$ which is a subset of a vector space $V$ I want to want the smallest subspace of $A$ of $V$ such that $|A \cap S| \geq k $. I suspect some variant of this problem would have already been studied but I have not been able to find it. Have anyone seen this or something similar before?
Given a set of points $S$ which is a subset of a vector space $V$, find the smallest subspace which intersect $S$ in at least $k$ points
|algorithms|linear-algebra|
any (heuristic) algorithm for non-metric symmetric TSP that works on a complete weighted undirected graph with 100-1000 vertices?
heuristic algorithm for non-metric symmetric TSP on a complete weighted undirected graph with 100-1000 vertices
|traveling-salesman|
i'm designing a CPU from scratch so i want it to be small. i decided to go with 4 bits registers. but 16 words of memory is a bit too small and i want more so i guess i need wider address bus (ie. 6). that raises a few questions: 1. how should i set address to memory address register? - using multiple data re...
How CPU uses wider address bus than register size?
|computer-architecture|cpu|memory-hardware|
In general, this problem is hard. For instance, if we have a vector space over $GF(2)$, then checking whether there is a one-dimensional subspace $A$ with the desired property is as hard as [learning parity with noise](https://en.wikipedia.org/wiki/Parity_learning) (LPN). LPN is conjectured to be hard: I believe ther...
Do we know anything about the hardness of the optimization version of the [multiway number partitioning problem](https://en.wikipedia.org/wiki/Multiway_number_partitioning) when the set of numbers to partition consists of the reciprocals of the first $n$ integers? That is, for $n, k\in \mathbb{N}$, find sets $S_1,\dots...
Look at early Intel processors designed under similar conditions, as 4004, 8008, 8051, 8080. In 8080, for example, 16-bit address is combined of register pairs like HL (so H+L), BC (B+C), DE (D+E), which also could be accessed separately (and there were few 16-bit operations, mainly for address handling). In 8086, r...
I believe the problem is in $P$. Let $\varphi,\psi$ be the two 2-CNF formulas. The plan of approach will be to test satisfiability of $\varphi \land \neg \psi$ and of $\psi \land \neg \varphi$. If either is satisfiable, then $\varphi,\psi$ are not equivalent; otherwise, they are equivalent. How do we test satis...
null
The picture below shows how to reduce the Boolean Satisfiability problem in CNF to the circulation problem in undirected graph ([see here][1]). As you can see, `a[i]` are the variables and `C[j]` are the clauses of a formula in the conjunctive normal form. If there is an edge between a variable (or negated variable) a...
P=NP? A reduction of CNF boolean satisfiability to the circulation problem in an undirected graph
|graphs|logic|satisfiability|network-flow|
I'm creating a plagiarism detection algorithm in Python, which scores how much of document A has been plagiarised in document B, and returns all the copied sections in B that were plagiarised from A. Here's my working version: ```python from textdistance import LCSStr DEFAULT_MIN_SUBSTRING_LEN = 30 def g...
Can I speed up this multi-LCSS (Longest Common Substring) algorithm?
|python|longest-common-substring|
Questions about specific programs or libraries are off-topic here, but let's talk about text similarity algorithms. I have two suggestions that may help. First off, consider tokenising the text into words first. It obviously depends on your goals, but I suspect that a score based on the number of matching words w...
null
Is there any books, papers or articles on how to analyze the time complexity of programs written in lazy languages such as Haskell? I know how laziness is implemented and how it can be expanded and thus analyzed, but is there any "intuitive" methods that does not go deep into the low level implementation principles ...
|complexity-theory|programming-languages|functional-programming|haskell|
You could do worse than Chris Okasaki's *Purely Functional Data Structures*. It was published as a book, [but here's the thesis version][1]. Another couple of theses that I haven't read, but may be worth trying to track down: Meira, S.R.L., *On the efficiency of applicative algorithms.* PhD thesis, Computer Labor...
Is a reference type (agnostic of PL) the object being pointed at, or the object doing the pointing? I'm having a hard time wrapping my head around the concept fundamentally (of course, I have backgrounds in pointers, C, C++, Java, Prolog, Ocaml, etc. and am familiar with the implementations in all of them). I mea...
Reference types
|formal-languages|formal-grammars|terminology|programming-languages|type-theory|
When given one *grammar*, we can formally prove that it can recognize one language using [QA_1][1] Since [Kleene's Theorem][2] gives the equivalence between the regular grammar and the NFA, we can also use QA_1 to prove that one NFA can recognize one language by *transfroming the NFA to the grammar* firstly. Then...
formal proof of one Turing Machine recognizes one language
|formal-languages|turing-machines|proof-techniques|
null
The formal proof that one Turing Machine recognizes one language
As title says, what I am trying to do is to find a way to sum integers and later compare them with another integer W, in a manner that when the sum of integers is less or equal than W, using only CNF. My best approach to the sum was to convert every integer in its binary form and use a XOR to perform the addition. H...
Check if sum of positive integers is less than a W integer in CNF
|satisfiability|arithmetic|
When given one *grammar*, we can formally prove that it can recognize one language using [QA_1][1] Since [Kleene's Theorem][2] gives the equivalence between the regular grammar and the NFA, we can also use QA_1 to prove that one NFA can recognize one language by *transfroming the NFA to the grammar* firstly. Then...
The formal proof that one Turing Machine recognizes one specific language
I'm studying asymotic analysis and i encounter this problem: Given a recurance relation: $$T(n)= aT(n/b)+cn^a (n>0;a>=1;b>=1)$$ prove that<br> if $a>a^b$ then Tn=$\mathfrak\theta(n^{log_b(a)})$<br> if $a=a^b$ then Tn=$\mathfrak\theta(n^alog(n))$<br> if $a<a^b$ then Tn=$\mathfrak\theta(n^a)$<br> This problem ...
Solving recurance relation with master theorem
|asymptotics|big-o-notation|
Neither. A type is not an object. An object has a type. Objects don't do pointing. References do. A reference type refers to a value that is a reference to an object. In Java, `int` is a value type. A `List` or (in your example) `Dog` is a value type. In `Dog x = new Dog();`, `x` gets assigned the type `Dog...
$\sqrt(n)$. The smallest function polynomial in n is $c \cdot n$ for some $c > 0$.
The picture below shows how to reduce the Boolean Satisfiability problem in CNF to the circulation problem in undirected graph ([see here][1]). As you can see, `a[i]` are the variables and `C[j]` are the clauses of a formula in the conjunctive normal form. If there is an edge between a variable (or negated variable) a...
Consider the CNF formula $a \wedge \neg a$. This has two clauses, $a$, and $\neg a$. If I understand your scheme correctly this maps to the following flow problem: [![flow problem][1]][1] This clearly has a solution (1 flow going in a circle) while the formula itself is clearly unsatisfiable. So your algorithm gi...
The halting problem doesn't really tell you anything about whether you can prove that a TM recognises a given language. We can prove that the TM recognises $\{0^n1^m : n \geq 1\}$ using the definition of $L(M)$ and $\mapsto_M$. One thing to note is that the machine is *deterministic*, so for each state and characte...
I'm trying to write a grammar for w being a nonempty word and z any word. That is, these are words that start with a nonempty word and end with its reverse. I've seen a very similar grammar before but it uses the alphabet {a,b}* rather than just {a,b}. Could anyone help me come up with this grammar or give me some advi...
Grammar of wxw^r over the alphabet {a,b}