instruction
stringlengths
0
29.8k
⌀
|algorithms|data-structures|
Change the description to "n is even or an odd square". For every r, let $k = 4r^2$. $a^k a^j$ is in the language if j is even, or if j is odd and k+j is a square. The smallest odd j is $(4r+1)^2 - 4r^2 = 8r+1$. For every r, the smallest odd j is different, so we have an infinite number of equivalence classes.
null
Change the description to "n is even or an odd square". For every r, let $k = 4r^2$. $a^k a^j$ is in the language if j is even, or if j is odd and k+j is a square. The smallest odd j is $(4r+1)^2 - 4r^2 = 8r+1$. For every r, the smallest odd j is different, so we have an infinite number of equivalence classes. ...
If the range of the integers is small then you can compute the histogram of the inputs then compute the prefix sum of this histogram. This preprocessing takes $O(n) $ time. Now given the prefix sum, you can now perform each query in $O(1)$ time. If the range of the integers is large compared to $N$, then your idea ...
null
This operation is often called "rank", and there are many data structures that can implement it. Binary search is certainly an option, and arguably the simplest. However, you can do better, both in time usage and in space usage, by using what is known as a *rank index*. I'll give one example of how you can do this, ...
This operation is often called "rank", and there are many data structures that can implement it. It is often seen in the combination "rank/select", where "select" is the converse operation: for any k, it returns the kth smallest integer in the set. These two operations are surprisingly general. For example, you don'...
null
Given n distinct sets `S1, S2, ..., Sn`, how to find a set `X`, such that `X ∩ S1, X ∩ S2, ..., X ∩ Sn` are still distinct, and the size of `X` is minimum. For example, given `{1, 2}, {1, 3}, {2, 3}`. Let `X={1, 2}`, then the intersections are `{1, 2}, {1}, {2}`, which are still different to each other. Are the...
How to find the minimum number of elements to distinguish several given sets
|untagged|
This operation is often called "rank", and there are many data structures that can implement it. It is often seen in the combination "rank/select", where "select" is the converse operation: for any k, it returns the kth smallest integer in the set. These two operations are surprisingly general. For example, you don'...
null
Hello I am trying to solve this recurrence equation using the recursion tree method: T (n) = T (n −1) + n^2 In particular, what is big-O of T (n)? Here is what I have done so far: [![enter image description here][1]][1] I am not sure if I drew the tree correctly, and I don't know how to figure out the r...
Help me solve recursion equation by using recursion tree method
|runtime-analysis|
null
|runtime-analysis|recurrence-relation|
null
I've learnt basic computer architecture over the past years, and now want to learn about the lowest level of software. I've understood from https://nandgame.com that instructions are not only machine instructions in hardware (such as activating a multiplexer or such), but also combinations of instructions that allow fo...
Is assembly macros part of operative system / kernel, or lower down and more seen as hardware?
|computer-architecture|
Given $n$ distinct sets $S_1, S_2, \cdots, S_n$, how to find a set $X$ such that $X \cap S_1, X \cap S_2, \cdots, X \cap S_n$ are still distinct, and the size of $X$ is minimum? For example, given $\{1, 2\}, \{1, 3\}, \{2, 3\}$, let $X=\{1, 2\}$, then the intersections are $\{1, 2\}, \{1\}, \{2\}$, which are still d...
How to find the minimum number of elements to distinguish several given sets?
|algorithms|optimization|terminology|reference-request|sets|
Any explanation why Solution 1 is faster than Solution 2? Input passed to both solutions let myArraySortedSquares = Array(stride(from: -100000, through: 100000, by: 1)).shuffled() **Solution 1** with O(nlog(n)) time complexity & O(n) time complexity Time elapsed for solution: 2.76 s. // Time:...
solution with with O(n) is always slower than solution with O(nlog(n)) even though they have the same space complexity
|algorithms|complexity-theory|time-complexity|data-structures|space-complexity|
This operation is often called "rank", and there are many data structures that can implement it. It is often seen in the combination "rank/select", where "select" is the converse operation: for any k, it returns the kth smallest integer in the set. These two operations are surprisingly general. For example, you don'...
This operation is often called "rank", and there are many data structures that can implement it. It is often seen in the combination "rank/select", where "select" is the converse operation: for any k, it returns the kth smallest integer in the set. These two operations are surprisingly general. For example, you don'...
null
null
My book Sebasta's Concepts of Programming Language (Chapter 1) states: > Orthogonality in a programming language means that a relatively small > set of primitive constructs can be combined in a relatively small > number of ways to build the control and data structures of the > language. Furthermore, every pos...
What is this definition of orthogonality in programming language trying to convey?
|programming-languages|
double array of floats pointer to character array of pointers to arrays of integers array of array of pointers to pointers to double ...
A likely explanation is the hidden constant. We can assume the following empirical formulas for the running times: c.n.log(n) and d.n. Then it is possible that c.log(200000) > d, for instance due to the parts of the code that are interpreted and those using precompiled functions.
Unfortunately the site you have been looking at has confused you by using the word "instructions" to mean two different things. A machine instruction tells the machine to do something. For instance, on the Intel 8080 the instruction with byte value 3E says "Read the byte after this, and store it in the A register". ...
Any explanation why Solution 1 is faster than Solution 2? Input passed to both solutions let myArraySortedSquares = Array(stride(from: -100000, through: 100000, by: 1)).shuffled() **Solution 1** with O(nlog(n)) time complexity & O(n) time complexity Time elapsed for solution: 2.76 s. // Time:...
solution with with O(n) time complexity is always slower than solution with O(nlog(n)) time complexity even though they have the same space complexity
null
One solution will run in time up to $c_1 n log n$ for some constant $c_1$ if n is large enough. The other solution will run in time up to $c_2 n$ for some $c_2$ is n is large enough. So you have three problems: First, you don't know which n is "large enough". This formula might only work if $n > 10^{30}$. Second, y...
It's really quite simple. Step 1: Calculate the target sum, which is round (sum (x_i)). Let's say you get a value of 597. Step 2: Calculate the sum that you get if you round every number down, that is sum (floor (x_i)). Let's say you get a value of 594. Step 3: Calculate how many values must be rounded up. ...
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...
Is Mathematical halting problem different than Computational halting problem?
|halting-problem|real-numbers|
I have some algorithmic complexity estimates in Giga Operations Per Second (GOPS) and I would like to compare those with the capabilities of state-of-the-art processors. However, the processor's performance is commonly measured in FLOPs. According to [this](https://en.wikichip.org/wiki/flops) (Eq.4) FLOPS_core = OP...
translating operations per second (OPS) to floating point operations per second (FLOPS)
|complexity-theory|time-complexity|computer-architecture|
I have some algorithmic complexity estimates in Giga Operations Per Second (GOPS) and I would like to compare those with the capabilities of state-of-the-art processors. However, the processor performance is commonly measured in FLOPs. According to [this](https://en.wikichip.org/wiki/flops) (Eq.4) FLOPS_core = OPS ...
null
I have some algorithmic complexity estimates in Giga Operations Per Second (GOPS) and I would like to compare those with the capabilities of state-of-the-art processors. However, the processor performance is commonly measured in FLOPS. According to [this](https://en.wikichip.org/wiki/flops) (Eq.4) FLOPS_core = OPS ...
Processors without built-in floating point arithmetic usually require say 50 non-floating point operations to implement a floating point operations. Processors with built-in floating point arithmetic usually have about equivalent or slightly higher non-floating point capabilities, but slightly lower (say five times...
null
There's an iceberg of concepts here. By "type operators", the author roughly means the methods by which arrays or pointers are created. By "applying type operators to themselves", the author basically means that pointers can be created which point to pointers, and arrays can be created which contain arrays. The ...
null
You may be referring to the "macros" that can be defined when using a symbolic assembler for development. Such a program is a translator from a human readable representation of the processor opcodes to machine language (see illustration, middle columns and left columns). In this frame, a macro is just a shorthand to...
You may be referring to the "macros" that can be defined when using a symbolic assembler for development. Such a program is a translator from a human readable representation of the processor opcodes to machine language (see illustration, middle columns and left columns). In this frame, a macro is just a shorthand to...
Change the description to "n is even or an odd square". For every r, let $k = 4r^2$. $a^k a^j$ is in the language if j is even, or if j is odd and k+j is a square. The smallest odd j is $(4r+1)^2 - 4r^2 = 8r+1$. For every r, the smallest odd j is different, so we have an infinite number of equivalence classes. ...
Any explanation why Solution 1 is faster than Solution 2? Input passed to both solutions let myArraySortedSquares = Array(stride(from: -100000, through: 100000, by: 1)).shuffled() **Solution 1** with O(nlog(n)) time complexity & O(n) time complexity Time elapsed for solution: 2.76 s. // Time:...
null
The [big O time notation][1] is a way to talk about relative time behavior of different algorithms **as *n* approaches infinity**. Shooting towards infinity is a trick that allows us to ignore the constant parts of the time behavior. In the real world of course your n will not be anywhere close to infinity, and ofte...
The [big O time notation][1] is a way to talk about relative time behavior of different algorithms **as *n* approaches infinity**. Shooting towards infinity is a trick that allows us to ignore the constant parts of the time behavior. In the real world of course your n will not be anywhere close to infinity, and ofte...
Why is Solution 1 faster than Solution 2? The input passed to both solutions: let myArraySortedSquares = Array(stride(from: -100000, through: 100000, by: 1)).shuffled() **Solution 1** with O(nlog(n)) time complexity and O(n) time complexity Time elapsed: 2.76 s. // Time: O(nlog(n)) | Space O(n) ...
A solution with O(n) time complexity is always slower than a solution with O(nlog(n)) time complexity even though they have the same space complexity
null
The [big O time notation][1] is a way to talk about relative time behavior of different algorithms **as *n* approaches infinity**. Shooting towards infinity is a trick that allows us to ignore the constant parts of the time behavior, and the lower-level factors. In the real world of course your n will not be anywher...
The [big O time notation][1] is a way to talk about relative time behavior of different algorithms **as *n* approaches infinity**. Shooting towards infinity is a trick that allows us to ignore the constant parts of the time behavior, and the lower-level factors. In the real world of course your n will not be anywher...
The [big O time notation][1] is a way to talk about relative time behavior of different algorithms **as *n* approaches infinity**. Shooting towards infinity is a trick that allows us to ignore the constant parts of the time behavior, and the lower-level factors. In the real world of course your n will not be anywher...
null
Let's say there are four sets containing integers. Each set does not have duplicates in itself, but duplicates exist across sets. ``` A = [1, 2, 3, 4] B = [2, 3, 4, 5] C = [3, 4, 5, 6] D = [4, 5, 6, 7] ``` The goal is to store each unique element in a resulting set `R`. The naïve single-threaded solution would...
Multithreaded deduplication of sets
|algorithms|
Why is Solution 1 faster than Solution 2? The input passed to both solutions: let myArraySortedSquares = Array(stride(from: -100000, through: 100000, by: 1)).shuffled() **Solution 1** with O(nlog(n)) time complexity and O(n) time complexity Time elapsed: 2.76 s. // Time: O(nlog(n)) | Space O(n) ...
A likely explanation is the hidden constant. We can assume the following empirical formulas for the running times: c.n.log(n) and d.n. Then it is possible that c.log(200000) < d, for instance due to the parts of the code that are interpreted and those using precompiled functions.
As part of pre-processing my (very large) graph, I want to eliminate as many unnecessary edges as possible. As far as I know, there is no way to exactly compute transitive reduction faster than corresponding matrix multiplication which is why I'm looking for an approximation. Is there a practical algorithm that can ...
Approximate/iterative algorithm for transitive reduction of DAG
|graphs|
As part of pre-processing my (very large) directed acyclic graph, I want to eliminate as many unnecessary edges as possible. By "unnecessary" I mean an edge that could be absent from the transitive reduction of the graph. For example, in the graph `{(1 -> 2), (2 -> 3), (1 -> 3)}`, edge `(1 -> 3)` is considered unnecess...
null
Given a finite alphabet $\Sigma := \{a, b, \dots\}$, consider the so-called "tagged" alphabet $\Sigma' := \{a', b', \dots\}$. Consider the monoid morphisms $untag, killTag : \Sigma \cup \Sigma' \to \Sigma$ given by - $untag(a) := a$ for $a \in \Sigma$, $untag(a') := a$ for $a' \in \Sigma'$. - $killTag(a) := a$ for ...
I will assume that each set is stored as a sorted list/array. You can compute the union of two sets using a [merge algorithm](https://en.wikipedia.org/wiki/Merge_algorithm). This should run in linear time, and is quite I/O friendly, as you only scan through the list in a forward direction (no random access needed). ...
$L$ is a regular language, so you have a DFA $M$ for it. First remove every “dead” state in $M$, i.e. every state that cannot lead to an accepting state. Make every state in $M$ an accepting state, and make a new start state that $\epsilon$-branches to every state in $M$. The resulting NFA $M'$ recognizes $P$, because:...
Update: To clarify. MyNOR (http://mynor.org/) stores some combined instructions in ROM to make programs take up less space. It seems very possible that instruction sets for CPUs might do similar, in more normal computers. I was interested if such load as part of some operative system/kernel/whatever it is called, or is...
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 this new model of computation?
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...
|halting-problem|
[Wikipedia][1] defines `range of data type`: <blockquote> <i>the set of possible values that that variable can hold.</i> </blockquote> Suppose we have two data types <i>A</i> and <i>B</i>. Now, with attention to the definition of <i>widening</i> in section `7.4` of [Concepts of Programming Languages][2], we can...
formal definition for "data type with larger range"
|programming-languages|
|programming-languages|definitions|
First of all there is a distinction between clock cycle of a computer and central processing unit frequency. In general frequency and Time (i.e period) is directly related i.e 2 seconds is equivalent to 1/2 Hz. This means it took 2 seconds between two clock ticks or signals and frequency is handy to describe what happe...
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...
$$B_{\text{min}}\le A_{\text{min}}\land B_{\text{max}}\ge A_{\text{max}}$$ should do.
$$B_{\text{min}}\le A_{\text{min}}\land B_{\text{max}}\ge A_{\text{max}}$$ should do (with the implicit assumption that the types $A$ and $B$ are appropriate to represent numbers).
null
null