instruction
stringlengths
0
29.8k
⌀
After posting my question, I realized that it contains the answer. As there can be many duplicates, the size of the compressed array tends to be quite short. So - it is advisable to avoid eliminating the duplicates as soon as possible. A modified straight insertion sort could do, the modification consisting of just...
After posting my question, I realized that it contains the answer. As there can be many duplicates, the size of the compressed array tends to be quite short. So - it is advisable to avoid eliminating the duplicates as soon as possible. A modified straight insertion sort could do, the modification consisting of just...
{"OriginalQuestionIds":[121156],"Voters":[{"Id":472,"DisplayName":"Juho"},{"Id":755,"DisplayName":"D.W.","BindingReason":{"GoldTagBadge":"algorithms"}}]}
After posting my question, I realized that it contains the answer. As there can be many duplicates, the size of the compressed array tends to be quite short. So - it is advisable to avoid eliminating the duplicates as soon as possible. A modified straight insertion sort could do, the modification consisting of just...
I have thousands of short arrays (length less than 9) holding integers. These numbers can be identical with high probability (in many arrays there are two triples of equal numbers). I need to remove the duplicates in each array, as efficiently as possible. An obvious solution is to sort using a fast sort (such as st...
Algorithm ========= Step 1: Build the set of all possible ratios from the first list, by enumerating all pairs of items from the first list and dividing. Sort this set, and call $A$ the result. Step 2: Do the same for the second list, and call $B$ the result. Step 3: Now, scan through these two sorted sets o...
null
Algorithm ========= Step 1: Build the set of all possible distances from the first list, by enumerating all pairs of items from the first list and subtracting. Sort this set, and call $A$ the result. Step 2: Do the same for the second list, and call $B$ the result. Step 3: Now, scan through these two sorted ...
ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss
sssssssssssssssssssssssssssssssssssssssssssssss
|big-o-notation|
Before an exam in Computability I go through questions from last year's test. So the question is: $$A= \{ \langle M\rangle x | M \text{ is a TM and accepts } x \}$$ $$ L = \{ \langle M \rangle | M \text{ is a TM and halts only on words starting with 101 } \} $$ Prove by reduction that $L$ is undecidable. So this ...
Prove by reduction that language of TMs accepting only words starting with 101 is undecidable
|complexity-theory|turing-machines|reductions|
How to find the standard theta notation of this?
|time-complexity|asymptotics|big-o-notation|
Hi i am practising standard theta notation: How could i find the standard theta notation of the following : - ```2n + 3n^2(log n)^3 + 2``` and - ```((2n^2 + 7n+5)(7n+1))/7``` So far i have used the "drop constants and find dominating term" strategy where we remove the constants from the expressions and then w...
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|big-o-notation|
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...
Hi i am practising standard theta notation: How could i find the standard theta notation of the following : - ```2n + 3n^2(log n)^3 + 2``` and - ```((2n^2 + 7n+5)(7n+1))/7``` So far i have used the "drop constants and find dominating term" strategy where we remove the constants from the expressions and then w...
How to find the standard theta notation of this?
|time-complexity|asymptotics|big-o-notation|
Let $\begin{bmatrix}0\\ 0\end{bmatrix}$ be a two-column vector with $0$ in the first row and $0$ in the second row. Let $\Sigma_2 = \left\{ \begin{bmatrix}0\\ 0\end{bmatrix}, \begin{bmatrix}0\\ 1\end{bmatrix}, \begin{bmatrix}1\\ 0\end{bmatrix}, \begin{bmatrix}1\\ 1\end{bmatrix}\right\}$ be the set of all 2-ele...
How to design a DFA that accepts the language of pairs of binary words (a,b) with 5a=b?
|regular-languages|finite-automata|arithmetic|
Define function $d:{\Sigma_2}^*\to \mathbb Z$, $d(w)=\underline w-5\overline w$, where - $\overline w$ is the base-$2$ number formed by the digits on the first row of the letters in $w$ - $\underline w$ is the base-$2$ number formed by the digits on the second row of the letters in $w$. For example, if $w=\begin...
Assuming unbounded memory, it seems many data structures can contain an arbitrary finite number of members. However, *how* they store data differs. In particular, it seems useful to represent the said "how" by an ordinal. For examples: * The list data structure is represented by the fixpoint of $O = 1 + O$, which i...
Does every computable ordinal admit a data structure corresponding to it?
|data-structures|
I need help in finding a more performant algorithm. I have two timelines in the form of two indexed lists where each element is a floating-point value that represents seconds. The values in each list are only growing with higher indices. Each list has about 2000 elements. From every timeline, I take two indices a...
Before I try to explain your question, I need to make a few observations: 1. You claim that: "a process may be needed to be removed from the running queue when it is faced with an I/O request", not only, when a process is running, one of the following events can occur: **the process issues an I/O request and then is...
Assume that $L$ is decidable. Then there is a Turing machine, $T$ that, on input $M$ decides whether $M$ halts only on words starting with $101$. Using $T$, we will be able to decide $A$. Given $\langle M\rangle x$, we would like to decide if $M$ accepts $x$. In order to do that, imagine another Turing Machine $M_x$...
The halting problem states that there is no $h$ function that works on any input. You are missing that you need to supply a concrete implementation of a function $h$ (which is as hard as writing a compiler), and prove that it works on any input function. The latter is an impossible task, as you should feed $h$ with all...
null
I know that if there is a Turing Reduction from $A$ to $B$, say $A \le_T B$, and $B \in R$ then $A \in R$. I also know that Turing Reduction is for Decision, and not Recognition. Is it possible to design a new type of reduction, such that if $B \in RE$ then $A \in RE$ ? Thank you!
If $B \in RE$ then $A \in RE$ - Reduction
|complexity-theory|turing-machines|computability|reductions|turing-recognizable|
Given the following code: int f3(int n) { if(n <= 2) return 1; f3(1 + f3(n-2)); return n - 1; } I was trying to find the complexity and I got this expression: $T(n)=1+T(T(n-2))$ which I've never seen before. I know the answer is $O(2^{\frac{n}{2}})$ but I have no idea how t...
Complexity of recursive function that calls itself with it's own return value
|time-complexity|recursion|big-o-notation|
Given the following code: int f3(int n) { if(n <= 2) return 1; f3(1 + f3(n-2)); return n - 1; } I was trying to find the time complexity and I got this expression: $T(n)=1+T(T(n-2))$ which I've never seen before. I know the answer is $O(2^{\frac{n}{2}})$ but I have no idea ...
null
Consider $$1+x+x^2+x^3+\dots+x^n=\frac{x^{n+1}-1}{x-1}.$$ Differentiate from two sides: $$1+2x+3x^2+\dots+nx^{n-1}=\frac{(n (x-1)-1) x^n+1}{(x-1)^2}.$$ Multiply two sides by $x$: $$x+2x^2+3x^3+\dots+nx^{n}=\frac{(n (x-1)-1) x^{n+1}+x}{(x-1)^2}.$$ Plug $x=2$ into into formula you will get: $$\begin{align} \s...
**Hint:** The correct recurrence is $$T(n)=T(1+f_3(n-2))+T(n-2),\\T_0=T_1=1.$$ That should be easier to solve.
null
null
I am working on designing a DFA with the language a^i b^j c^k | i + j + k is odd I thought along the following lines: i+j+k is off => two of them are even and one is odd or all of them are odd. But designing a DFA like this will lead to a complex and big DFA. I am not sure if there is a simpler way to design a DF...
Designing DFA for a language
|automata|finite-automata|
this language is an intersection of 2 regular languages: a sequence of any number of a b and c in order: `a*b*c*` (a 3 stage + sink DFA will handle this one), and `[abc]([abc][abc])*` (which a 2 state DFA) To create the DFA for the interesection you take the cartesian product of all stages and then connect them acc...
I am interested in the following problem > Input: A boolean function F with n boolean inputs and m boolean outputs. > > Output: A circuit C implementing F such that C has as few gates as possible. The function F could either be given as a boolean truth table, or more likely, another circuit D. I realize tha...
Suggestion for tools/libraries for multi-output circuit minimization?
|optimization|reference-request|np-hard|circuits|
Suggestion for tools/libraries for multi-output boolean circuit minimization?
I know that a computer can be mechanical, screws/nuts or even water/pipes. Of course, it would be slow and big, but it doesn't have to be electric, transistors, etc. How can a machine like this do all that it does? I can't understand. I would like a thought path for this, analogy. Especially one where I can think it...
How does a computer works?
|computer-architecture|programming-languages|cpu|binary|introductory-lesson|
How a computer works?
Given an NFA with more than one initial or final state, it is possible to convert it to another NFA with only one initial or final state by using epsilon transitions. To remove the epsilon transitions, we may need to add final or initial states, depending on the method used (backwards removal vs forward removal). Is...
Getting an NFA with only one initial and final state without epsilon transitions
|formal-languages|automata|finite-automata|nondeterminism|
Yes, in fact we can. Provided the original automaton does not accept the empty string $\varepsilon$. The construction is as follows. We start with the usual NFA with a single initial state (and no $\varepsilon$-edges). Add a new final state $f$. Whenever there is a transition $(s,a,t)$ into a final state $t$ we add ...
null
Suppose we are given an array-based list data structure. Suppose that its initial capacity is $m > 0.$ When the appending an element to the end of the list, if the list is full, we extend its capacity by $d > 0$ elements, copy the old content, and finally add the element. Suppose we are to append $n \geq m$ elements ...
Finding the total work of an array list expansion effort
|arrays|induction|experimental-analysis|dynamic-array|
Suppose we are given an array-based list data structure. Suppose that its initial capacity is $m > 0.$ When the appending an element to the end of the list, if the list is full, we extend its capacity by $d > 0$ elements, copy the old content, and finally add the element. Suppose we are to append $n \geq m$ elements ...
I am a total noob to programming, and one of the basic ideas in Haskell is how one can define new types using some things called constructors. I haven't quite understood it fully, but why would one want to make any types beyond the basic ones? What practical utility does it hold?
Why would we want to define new types in a functional programming language?
|type-theory|
Let A[1 : n] be a vector of n integers such that all elements except O(n^2/3) elements are between 1 and 10n. Design an algorithm with linear complexity that sorts A. Beyond the algorithm, what I can't fully understand is why we are provided with the information "all elements except O(n^2/3)" It is certainly an info...
Design an algorithm with linear complexity
|algorithms|time-complexity|big-o-notation|linear-complexity|
"Lookahead" is an aspect of a particular parsing algorithm, and might be different for different parsing algorithms using the same grammar. You can't talk about lookahead without specifying which parsing algorithm is in use. If you are using a top-down LL parsing algorithm, parsing decisions need to be made very ear...
null
All cpu pipelines are multi-cycle. In the MIPS five-stage pipeline registers are read in the second stage called ID (instruction decode/register fetch). And instructions usually stall as late as possible. For example in daddi r1, r2, r3 daddi r4, r5, r1 the second instruction will stall for th...
Hoare Triple formalizes program correctness, which contains postcondition, program and precondition such as $\vdash P \{Q\} R$ Provided code snippet: i := 0; s := 0; while i < N do s := s + max(arr[i]); i := i + 1; od The program's goal is to compute the **sum** of the max...
Hoare triple: introducing Loop invariant and partial correctness
|hoare-logic|
I have two arrays that both contain n elements (positive,non zero, not negative) {x1....xn} {y1....yn} I want to pair them up optimally, one from each array, so that the pairs come out as even as possible, when paired up optimally, I want the difference between the highest value pair and the lowest value pair to b...
How do I find the most even combination for two arrays
|algorithms|dynamic-programming|arrays|coding-theory|
Assuming $G=(V,E)$ is a 3-colorable graph, then there are 3 disjoint independent subsets of $V$: $S_1,S_2,S_3$ such that $S_1 \cup S_2 \cup S_3=V$, by taking each $S_i$ to include the vertices of color $i$. I wanted to know - if $G$ is not 3-colorable, then can it has 3 disjoint subsets that their union is $V$? I...
If a graph is not 3-COLORable, then there are at most 2 Independant Sets in G?
|algorithms|complexity-theory|graphs|np-complete|
Let A[1 : n] be a vector of n integers such that all elements except O(n^2/3) elements are between 1 and 10n. Design an algorithm with linear complexity that sorts A. Beyond the algorithm, what I can't fully understand is why we are provided with the information "all elements except O(n^2/3)" It is certainly an info...
The complementary language of a recognizable undecidable language is not recognizable. If the complementary language of an recognizable language is a non-recognizable language, is the recognizable language a non-decidable language?
If the complementary language of an recognizable language is a non-recognizable language, is the recognizable language a non-decidable language?
|turing-machines|computability|undecidability|turing-recognizable|
This sounds like homework, so you should try to prove it. The title, by the way, doesn't make sense. **Proof sketch.** Suppose that you can partition the vertex set into three independent sets, $S_1, S_2, S_3$. Color the vertices in partition $S_1$ red, $S_2$ green, and $S_3$ blue. **Claim.** This is a proper ...
This [post](https://cs.stackexchange.com/q/19582/157195) introduces a new variant of 3-SAT called EQUAL-3-SAT, where the number of 3-Literal clause is equal to the number of variable. I was curious if this still holds true for the following variants of EQUAL-3-SAT: 1. **EQUAL-3-NAE-SAT** where the number of cla...
Complexity of this variant of 3-SAT?
|np-complete|3-sat|
If a language $L$ is recognizable but it's complement $\overline{L} $ is not, then there is no TM that will halt and accept any string $w \in \overline{L} $, which implies that there is no TM that will halt and reject $w \notin L$. A language is decidable iff there is a TM that can accept $w$ if it is in $L$ or reject ...
If a language $L$ is recognizable but it's complement $\overline{L} $ is not, then there is no TM that will halt and accepts a string $w \in \overline{L} $, which implies that there is no TM that will halt and rejects $w \notin L$. However for a language to be decidable there must be a TM that accepts $w$ if it is in $...
I was provided with the solution to the language being represented. An example of accepted input would be [001][101]. The DFA that would recognize this language is below. [![enter image description here][1]][1] [1]: https://i.stack.imgur.com/yDsQx.png What do the states represent? What are the meaning of the ...