instruction stringlengths 0 29.8k ⌀ |
|---|
Upper bounding this expression |
|asymptotics|big-o-notation|landau-notation|upper-bound| |
In section 30.2 of CLRS (third edition), they given an algorithm for computing the fast Fourier transform of a vector represented as an $n$ dimensional array when $n$ is a power of $2$. They say that an algorithm for general $n$ is beyond the scope. Is generalizing the algorithm to any $n$ very tricky? Any references w... |
null |
Notice that there is always a power of two $2^k$ between $n$ and $2n$. Thus you can extend your array of $n$ numbers to $2^k$ and fill the empty cells with zero. Because $2^k \leq 2n$ the algorithms asymptotic runtime $O(2n\log(2n)) = O(n\log(n))$ doesn't change. This is trick is commonly used in competitive programmi... |
null |
Are the following two `stat` rules equivalant?
```
stat : 'if' expr 'then' stat ('else' stat)? ;
```
```
stat : 'if' expr 'then' stat // with higher priority
| 'if' expr 'then' stat 'else' stat
;
```
That is, does ANTLR 4 always put the alternative without the optional part before the one wi... |
How does ANTLR4 handle optional rules? |
|context-free|formal-grammars|compilers| |
I am trying to understand Circuit Complexity's relation to classical Time Complexity. Here is what wiki mentions:
"If a certain language, ${\displaystyle A}$, belongs to the time-complexity class ${\displaystyle {\text{TIME}}(t(n))}$ for some function ${\displaystyle t:\mathbb {N} \to \mathbb {N} }$, then ${\display... |
null |
Just like $n=O(2^n)$ (the exponential grows much much faster), $\dfrac1n=\Omega\left(\dfrac1{2^n}\right)$. |
It's not necessarily true that green threads cannot achieve parallelism. Just check out the runtimes for Go, Elixir, and Clojure - they're doing just fine.
While the actual reason as to why Python didn't go for this route is unclear, if I had to guess: it's probably because green threads don't play nice with C.
... |
null |
I'm trying to implement [self-organizing lists][1] DS to publish as a public module. Over the course of Algorithms, we learnt that if you add a new element to the list, it should still do the huriectics. For example, in Move-To-Front, when you do `insert(2)` it will add `2` to the end of the list and then move it to th... |
What is the literature implementation of self-organizing lists? |
|algorithms|data-structures|lists| |
null |
I need to prove that the following expression is $\mathcal O(n \log n)$ with the substitution method: $$ T(n) \leq 3\log n + n + \frac{6}{n}\sum^{n - \frac{\log n}{3}}_{i=\frac{\log n}{3}} T(i)$$
This is my attempt, assumming $T(n) \leq c n \log n$:
\begin{align*}
T(n) &\leq 3\log n + n + \frac{6c}{n}\int^{n - \fr... |
Suppose we have a minimization ILP. Denote its value by $OPT$.
Let $PER$ be the solution to its LP relaxation.
Given a real number $t$, we would like to decide whether $OPT \leq (1+t) \cdot PER$, in time polynomial in the problem size and $1/t$.
Denote by FPTAD, the class of ILPs for which this is doable in polyno... |
Approximation Class that Decides |
|complexity-theory|approximation|complexity-classes| |
null |
Suppose we have a minimization ILP. Denote its value by $OPT$.
Let $PER$ be the solution to its LP relaxation.
Given a real number $t$, we would like to decide whether $OPT \leq (1+t) \cdot PER$, in time polynomial in the problem size and $1/t$.
Denote by FPTAD, the class of ILPs for which this is doable in polyno... |
null |
Suppose Alice has a verifiable (message, signature) pair from Cedric, who would not cooperate and routinely uses an algo (ecdsa, eddsa, rsa, or insert yours here) to sign messages.
Alice wants to interactively prove to Bob she has that (message, signature) pair with the valid signature, obviously. It doesn't have to... |
Interactive ZKP of possession of a signed message |
|cryptography|security|zero-knowledge-proofs| |
null |
This is a NP statement, so there is a zero-knowledge proof for it (as there is a zero-knowledge proof for every NP statement). The exact form of the proof will depend on which signature algorithm is chosen, and what is already known to Bob (e.g., does Bob know the message? can it be disclosed to him safely?). |
You can do the other way around; use a [HashTable][1] to map the synonyms to the main word:
```
feline -> cat
kitten -> cat
```
Now, you can do the lookup in $O(1)$ time, although this may have some spatial overhead.
[1]: https://en.wikipedia.org/wiki/Hash_table |
null |
I need to prove that the following expression is $\mathcal O(n \log n)$ with the substitution method: $$ T(n) \leq 3\log n + n + \frac{6}{n}\sum^{n - \frac{\log n}{3}}_{i=\frac{\log n}{3}} T(i)$$
This is my attempt, assumming $T(n) \leq c n \log n$:
\begin{align*}
T(n) &\leq 3\log n + n + \frac{6c}{n}\int^{n - \fr... |
null |
It is common to have proofs that use contradiction to show that some language is undecidable in computability theory.
An example proof can be seen in 4.2 Undecidability “Introduction to the Theory of Computation” by Sipser proving 4.11 the undecidability of A_tm.
Basically, these proofs assume the existence of ... |
Does contradiction definitively prove nonexistence |
|undecidability|proof-techniques| |
That's not how I would describe it. I would say, the proof proves that such a decider cannot exist.
I know that many people find [proof by contradiction](https://en.wikipedia.org/wiki/Proof_by_contradiction) unconvincing or it makes them uncomfortable, and they wonder whether one can really trust the results one ob... |
That's not how I would describe it. I would say, the proof proves that such a decider cannot exist.
I know that many people find [proof by contradiction](https://en.wikipedia.org/wiki/Proof_by_contradiction) unconvincing or it makes them uncomfortable, and they wonder whether one can really trust the results one ob... |
I'm trying to understand how problems in NP-hardness reduce to one another. As I understand it now, if X reduces to Y, Y is *at least* as hard as X.
What I think that means, and would like confirmed or denied, is the following:
1) Any category can reduce to itself.
Ex: P can reduce to P. NP can reduce to NP, NP... |
In NP-hardness, can any category reduce to itself? How can you intuitively explain which categories reduce to the others? |
|np-complete|np-hard|np|p-vs-np| |
A proof is a proof, even if the system you work in is inconsistent.
So if you prove that the existence of a decider leads to contradiction, you have proved that such a decider does not exist. If in addition your system is contradictory, then it will also prove that the decider exists, as well as that you are the Pop... |
null |
As plshelp said, sometimes a 2^k FFT is useful even when you want a 2^n Fourier transform with n < 2^k. A 1024 point FFT is not the same as a 1023 point Fourier transform, but in many situations it is useful.
You can do Fourier transformations for any n, just following the definitions. If you can write n as a produ... |
As plshelp said, sometimes a 2^k point FFT is useful even when you want an n point Fourier transform with n < 2^k. A 1024 point FFT is not the same as a 1023 point Fourier transform, but in many situations it is useful.
You can do Fourier transformations for any n, just following the definitions, in O(n^2). If you ... |
null |
null |
first time posting here.
I've encountered many examples which its format is like: a^n b^n. For this I understand that w = 2n and is pretty straightforward, but what happens in my case? Is w = 1 + 2n? And in this case would |xy| be a subword of just a, or a subword of a b^n?
I'm struggling to pump the language in... |
Using the pumping lemma, show that L = {a b^n c^n | n ≥ 0} is not regular |
|regular-languages|pumping-lemma| |
null |
Suppose that $L$ is regular and let $p$ be its pumping length. Consider $w = a b^p c^p \in L$. From the pumping lemma you know that $w$ can be written as $w=xyz$ with $|xy| \le p$ and $|y| \ge1$ such that $xy^ip \in L$ for all $i \ge 0$.
Notice that $y$ must contain the initial $a$ or at least one $b$ (possibly both... |
I am studying theoretical computer science and I am in the part about resolution in propositional calculus. I was reading a theorem (and its proof) that propositional resolution is refutation complete, but I could not fill a particular detail.
The theorem is:
> **Refutational Completeness of Propositional Resol... |
Proof that propositional resolution is refutation complete |
|logic|propositional-logic| |
There is an error in the example: $S = \{p_1 \lor p_2, p_1 \lor \lnot p_2 \}$ is actually satisfiable. Every interpretation $I$ that sends $p_1$ to $true$ actually works.
With this in mind, notice that if $S$ is unsatisfiable, then for every proposition symbol $p_i$ we may have both $p_i$ and $\lnot p_i$ occurring ... |
I'm reading Operating System Concepts by Silberschatz and in chapter 5, there is this text:
1.
> CPU-scheduling decisions may take place under the following four
> circumstances:
>
> 1. When a process switches from the running state to the waiting state (for example, as the result of an I/O request or an invo... |
Choices in cpu-scheduling decisions |
|operating-systems|scheduling| |
I'm reading Operating System Concepts by Silberschatz and in chapter 5, there is this text:
1.
> CPU-scheduling decisions may take place under the following four
> circumstances:
>
> 1. When a process switches from the running state to the waiting state (for example, as the result of an I/O request or an invo... |
The problem is described as such:
Given $n$ tasks $\{J_1, \ldots , J_n\}$where each task has a deadline and a ‘profit’.
So for some $i \in \{1,\ldots , n\}$, $J_i=\{t_i,p_i\}$ where $t_i$ is the deadline to complete the task, and $p_i$ is the expected profit.
It is given that:
* starting time is $0$
* each... |
Single machine scheduling with profit and deadline constraints |
|dynamic-programming|np-hard|scheduling|maximum-subarray| |
null |
While your idea is correct for certain reductions and is a good first intuition, it is quite vague and could be clarified:
1. it depends on the type of reduction: for example, it is unknown if there is a polytime **many-one** (or Karp) reduction from a $\mathsf{NP}$-complete problem to a $\text{co}\mathsf{NP}$-comp... |
While your idea is correct for certain reductions and is a good first intuition, it is quite vague and could be clarified:
1. it depends on the type of reduction: for example, it is unknown if there is a polytime **many-one** (or Karp) reduction from a $\mathsf{NP}$-complete problem to a $\text{co}\mathsf{NP}$-comp... |
While your idea is correct for certain reductions and is a good first intuition, it is quite vague and could be clarified:
1. it depends on the type of reduction: for example, it is unknown if there is a polytime **many-one** (or Karp) reduction from a $\mathsf{NP}$-complete problem to a $\text{co}\mathsf{NP}$-comp... |
Every running process runs on a core. When a process causes an interrupt, there is actually an interrupt on that core, and not on any other core. The operating system will detect which core had an interrupt. And the operating system will know which process is running on which core at any time, so it knows which process... |
Use $\log(n-\frac{\log n}{3})\leq \log n,$ to simplify the $\log n$ terms. Clearly the second term is at most $$3 c n \log(n)={\cal O}(n \log n).$$
Now $n=O(n \log n)$ as well which you can use to get rid of linear terms.
All the remaining terms are powers of $\log n$ or smaller (begin divided by $n$ for exampl... |
While i was going thru my course in Computer System Architecture (book taken Morris Mano) , I saw a question on KMaps can be solved in two ways but couldn't get which one to use when :-
I’m taking for an example kmaps for 3 var
A’B’ A’B AB AB’
C’ 0 1 3 2
C 4 5 ... |
K-Maps (Digital Logic, Computer System Architecture) |
|computer-architecture|digital-circuits| |
While i was going thru my course in Computer System Architecture (book taken Morris Mano) , I saw a question on KMaps can be solved in either of the ways but couldn't get which one to use when :-
I’m taking for an example kmaps for 3 var
A’B’ A’B AB AB’
C’ 0 1 3 2
C ... |
While i was going thru my course in Computer System Architecture (book taken Morris Mano) , I saw a question on KMaps can be solved in either of the ways but couldn't get which one to use when :-
I’m taking for an example kmaps for 3 var
A’B’ A’B AB AB’
C’ 0 1 3 2
C ... |
The RAII pattern in C++ is very powerful when you have deterministic object lifetime (stack objects go out of scope, heap objects are deleted), it is widely used to manage both memory and other resources (usually more precious, like file handles, sockets, locks, etc.).
However in GC languages where objects have inde... |
I have a very big set of non-empty arrays of possibly repeated numbers sorted in a weakly-decreasing order where each number belongs to the interval $[1, 55]$ and the sum of the elements of each array is always $\leq 55$. For example, the array $A=[5, 5, 3, 3, 3, 3, 1, 1, 1]$ contains 9 elements and its sum is $25$.
... |
Minimum number of bits to codify arrays with bounded sums |
|partitions| |
I need to determine for what range of n the algorithm that costs $1000n^3$ is faster than one that costs $2^n$, now I solved it on wolfram alpha and I know the answer is <= 24.
The issue is I have to prove it with using the math only and I don't understand the "W" thing in the solution (nor at this class (Data Structu... |
Simple solution to 1000n^3> 2^n without Lambert and "W" |
|algorithms| |
I need to determine for what range of n the algorithm that costs $1000n^3$ is faster than one that costs $2^n$, now I solved it on wolfram alpha and I know the answer is <= 24.
The issue is I have to prove it with using the math only and I don't understand the "W" thing in the solution (nor at this class (Data Structu... |
I need to determine for what range of n the algorithm that costs $1000n^3$ is faster than one that costs $2^n$, now I solved it on wolfram alpha and I know the answer is >= 24.
The issue is I have to prove it with using the math only and I don't understand the "W" thing in the solution (nor at this class (Data Structu... |
The RAII pattern in C++ is very powerful when you have deterministic object lifetime (stack objects go out of scope, heap objects are deleted), it is widely used to manage both memory and other resources (usually more precious, like file handles, sockets, locks, etc.).
However in GC languages where objects have inde... |
Both are correct in their own way. The goal of K-map is to aid the minimization of boolean functions, it doesn't impose any rules on how it is created.
With reference to your example, if you are minimizing a function $F(C,A,B)$ then you interpret it as rows first$(MSB = C)$ and then columns $(A,B)$. If you are mini... |
Both are correct in their own way. The goal of K-map is to aid the minimization of boolean functions, it doesn't impose any rules on how it is created.
With reference to your example, if you are minimizing a function $F(C,A,B)$ then you interpret it as rows first$(MSB = C)$ and then columns $(A,B)$. If you are mini... |
A simple greedy algorithm is known for this problem [1].
First, sort jobs by non-decreasing order of deadline. Let $S := \emptyset$ be a variable to denote a set of jobs. Then, for each job $i$,
```
if |S| < t_i then:
Add job i to S
# Job i is scheduled at time |S|-1
else if there exists a job k in S such... |
That's not how I would describe it. I would say, the proof proves that such a decider cannot exist.
I know that many people find [proof by contradiction](https://en.wikipedia.org/wiki/Proof_by_contradiction) unconvincing or it makes them uncomfortable, and they wonder whether one can really trust the results one ob... |
I've tried taking this to a suffix tree/ suffix array approach, only to realize that these tools are good for contiguous subsequences.
The problem is:
Given strings $S,T$ such that $n=|T|>|S|$ , find an algorithm to count number of occurances of $S$ in $T$, not necessarily contiguous.
Example:
$T=aababc, S=ab... |
Count number of non-contiguous occurances in string |
|strings|counting|substrings| |
null |
Given strings $S,T$ such that $n=|T|>|S|$ , I'd like an algorithm to count number of occurrences of $S$ in $T$ (as a subsequence), not necessarily contiguous.
Example:
if $T=aababc, S=abc$, the algorithm should return $5$.
I've tried taking a suffix tree/ suffix array approach, only to realize that these tools a... |
Count number of non-contiguous occurrences in string |
Your question concerns ranking and unranking of integer partitions. Ranking is the process of converting an integer partition into an index, and unranking is the opposite operation.
Let us first consider ranking and unranking of partitions of exactly $n$ with $k$ parts, which are counted by $p(n,k)$. Enumerating ove... |
A dynamic programming algorithm in $\mathcal{O}(|S| |T|)$ should do the trick.
Let's denote $S = s_1…s_m$ and $T = t_1…t_n$. For $0\leqslant i \leqslant m$, $0\leqslant j \leqslant n$, let $N(i, j)$ be the number of occurrences of $s_1…s_i$ in $t_1…t_j$. We have $N(0, j) = 1$ (by convention, for computation purposes... |
I think this should do it (string indexes starts by 1):
```
stack = [1] // start iterating from T[1]
count = 0
while stack.length > 0
while (stack.last <= T.length and T[stack.last] != S[stack.length])
++stack.last;
if (stack.last <= T.length)
if (stack.length == S.length)
+... |
Consider the right hand side. Use $\log(n-\frac{\log n}{3})\leq \log n,$ to simplify the $\log n$ terms. Clearly the second term is at most $3 c n \log n.$
Since all other terms are of lower order (since they are powers of $\log n$ or smaller (such as being divided by $n$ for example)) the right hand side is $\leq ... |
A dynamic programming algorithm in $\mathcal{O}(|S| |T|)$ should do the trick.
Let's denote $S = s_1…s_m$ and $T = t_1…t_n$. For $0\leqslant i \leqslant m$, $0\leqslant j \leqslant n$, let $N(i, j)$ be the number of occurrences of $s_1…s_i$ in $t_1…t_j$. We have $N(0, j) = 1$ (by convention, for computation purposes... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.