instruction
stringlengths
0
29.8k
⌀
Given an array of numbers with allowed replication, what is the algorithm to find the max amount possible only with summing or multiplying elements?
Maximizing sum and product of an array
|greedy-algorithms|
I have a question on the implementation of the Johnson's algorithm in C that is actually at the interface of theory and practice. [Link to Johnson's paper][1] I already implemented this algorithm in R without any issue and did the same in C but I now have only one issue with the latter implementation. Precisel...
In Johnson's algorithm for enumerating elementary circuits in a directed graph, why do B-lists have a different structure than the adjacency list?
|graphs|
Generally, and to build upon [this](https://cstheory.stackexchange.com/q/50815/3984) discussion, there is plenty of work which describes types exactly as you'd like, that is as a collection of "values" of a certain shape, with natural set theoretic operations on them, like complement, union and intersection. Worth r...
null
Let $\Sigma$ be an alphabet. Is the set of all strings over $\Sigma$ (i.e. $\Sigma^*$) countably infinite or uncountably infinite?
Is the set of all strings over $\Sigma$ countably infinite or not?
|formal-languages|regular-languages|counting|uncountability|
null
I was thinking about the language $a^nb^nc^n$, which is obviously not context free, but if we run it through 2 automata at the same time (the first for $a$ and $b$ and the second for $b$ and $c$ and they both accept, the construction would basically accept the language)
null
A quick test shows what I'm describing: > const text = 'foobarhelloworld' > const pattern = /.+or/ > text.match(pattern) //=> 'foobarhellowor' What is the basic algorithm for matching "anything up to some explicit text"? The reason I ask is I am working on hacking together a spell checker / morph...
How does a regular expression match `.+x`?
|algorithms|regular-expressions|
If **ZPP** = **EXPTIME** then **NP** $\subseteq$ **ZPP**, which implies **NP** $\subseteq$ **BPP**. As described in Russell Impagliazzo's informal paper ["A personal view of average-case complexity"](https://stuff.mit.edu/afs/sipb/project/reading-group/past-readings/2009-06-08-five-worlds.pdf), we would be living in a...
null
Can somebody explain the following: [![image][1]][1] <sub>(source: [fbcdn.net](https://scontent.fmuc2-1.fna.fbcdn.net/v/t1.15752-9/64433962_260132621514424_3576346785511112704_n.png?_nc_cat=108&_nc_oc=AQmCT-Vzb712Si5utFR_5EVpD1W5xFW_cOseawFkh9Aj82srwFt7rX-ummj5WbfLBrI&_nc_ht=scontent.fmuc2-1.fna&oh=962acd87872541b...
null
Given an array of *positive* numbers with allowed replication, what is the algorithm to find the max amount possible only with summing or multiplying elements? All numbers must be involved in some operation. I don't know how to look at this problem with greedy approach. For example, given the array $[1, 1, 1, 1, ...
So I have a regular language L and a non-regular language L' and i want to proof wether the union of both is regular or not. Since I found counterexamples for both cases I want to look at more distinct cases to show when the union is regular and when it isn't: case 1: L ⊆ L' case 2: L ⊇ L' case 3: L ∩ L' re...
Union of non regular and regular language
|formal-languages|regular-languages|proof-techniques|check-my-answer|proof-assistants|
null
So I have a regular language L and a non-regular language L' and i want to proof wether the union of both is regular or not. Since I found counterexamples for both cases I want to look at more distinct cases to show when the union is regular and when it isn't: case 1: L ⊆ L' case 2: L ⊇ L' case 3: L ∩ L' re...
|polynomials|interactive-proof-systems|
null
Let's say I have a set of two columns - Name, Surname. I have a list of possible values for - *Name* -> Jacob, John - *Surname* -> Mayerson, Kindle. I want to generate a set of unique combinations for columns Name and Surname. The result looks like this. ``` -------------------- | Jacob | Mayerson | | J...
null
This is probably the main difference between "regular expressions" as a formal language, and "regexes" as an implementation tool. Extending a regular expression matching algorithm to support greedy capture (i.e. the maximal munch rule) is straightforward. Consider this DFA: [![enter image description here][1]][1]...
Let the array contains $n$ elements. We use the following four lemmas/observations to design an $O(n^3)$ time algorithm. *Lemma 1*: In any optimal solution $O$, if there is any addition operation $a + b$, then either $a = 1$ or $b = 1$. The vice-versa statement is true as well. That is, if the array contains $1$, th...
null
I have a complete k-ary tree with a depth of $d$. If I'm given a node's depth-first index, I'd like a closed-form formula for calculating both the nodes children's depth-first indexes along with a formula for calculating the node's depth. It's possible I just haven't searched the correct terms, but I was only able t...
Finding the Depth-First Index of a Child Given the Parent's Depth First Index Index in Complete k-ary Tree
|trees|
null
null
null
null
Cases $1$, $2$, and $5$ are trivial: - If $L \subseteq L'$ then $L \cup L' = L'$, which is non-regular by hypothesis. - If $L' \subseteq L$ then $L \cup L' = L$, which is regular by hypothesis. - When $L \cup L'' = \Sigma^*$ this language is clearly regular. If $L \cap L'$ is regular then you cannot conclude an...
|formal-languages|regular-languages|proof-techniques|check-my-answer|
Cases $1$, $2$, and $5$ are trivial: - If $L \subseteq L'$ then $L \cup L' = L'$, which is non-regular by hypothesis. - If $L' \subseteq L$ then $L \cup L' = L$, which is regular by hypothesis. - When $L \cup L'' = \Sigma^*$ this language is clearly regular. If $L \cap L'$ is regular then you cannot conclude an...
Our current understanding of prime factorization places it somewhere in NP, but not in P. The problem asks us to find the list of prime factors for an integer. For example, 18's prime factors are 3, 3, and 2. But since 3 is repeated, we only count it once. But what about a slightly easier problem---finding how many ...
Is Determining the Number of Prime Factors Polynomial?
|number-theory|primes|factoring|
null
Our current understanding of prime factorization states that it is hard to solve. The problem asks us to find the list of prime factors for an integer. For example, 18's prime factors are 3, 3, and 2. But since 3 is repeated, we only count it once. But what about a slightly easier problem---finding how many prime fa...
You can construct such a family, with $|V_{n+1}| = 2|V_n|$, using random lifts. The classical work in the area is Bilu and Linial, [Lifts, discrepancy and nearly optimal spectral gap](https://www.cs.huji.ac.il/~nati/PAPERS/raman_lift.pdf). There are several recent papers of Marcus, Spielman and Srivastava on the topic ...
No problem involving factorization is known to be polynomial time, and these problems (formulated as decision problems in any reasonable way) are suspected to be NP-intermediate. The only problem which is known to be polynomial time is primality testing.
As a follow up to this question already been asked [here][1], I was wondering - if we supposed that P != NP, would then the following reasoning be correct: In NP problems we can only verify in poly-time whether x is in L based on the certificate that is also given as input. Hence we could be inputting the wrong cert...
Is the class NP closed under complement? (Follow-up)
|np|co-np|
As A. Schulz said [here](https://cs.stackexchange.com/q/24266), it is not known if $\operatorname{P} \neq \operatorname{NP} \implies \operatorname{NP} \neq \operatorname{coNP}$. The fact that we don't know how to build a polytime NTM for $\bar{L}$ if we have a polytime NTM that decides $L$ doesn't mean there is no w...
null
So I'm kind of confused as I'm not that deep into the algebraic theory of languages. I've seen that star-free regular languages seem to be just the same as counter-free languages. Is this the same as the complement of counter-languages (within the regular languages)? I.e. are regular languages either star-free or a cou...
Is the class of star-free languages just the complement to counter languages within the regular language class?
|formal-languages|regular-languages|formal-grammars|kleene-star|
Assume we have this recurrence: $$T(n)=2T(\dfrac{n}{2})+\dfrac{8}{9}T(\dfrac{3n}{4})+\Theta(\dfrac{n^2}{\log{n}})$$ We want to solve it using Akra-Bazzi method. As we know, $\sum_{i=1}^k\dfrac{a_i}{b_i^p}=1$. So $\dfrac{2}{2^p}+\dfrac{\dfrac{8}{9}}{(\dfrac{4}{3})^2}=1$ and we get $p=2$. We know: $$T(n)=\Theta\left(...
solve $T(n)=2T(\dfrac{n}{2})+\dfrac{8}{9}T(\dfrac{3n}{4})+\Theta(\dfrac{n^2}{\log{n}})$ using Akra-Bazzi method
|recurrence-relation|
null
null
It is sufficient for the lower limit of integration to be large enough (see the [original paper][1]). If you pick any $n_1 > 1$, $\log \log n_1$ exists and is just some constant. Then $$\int_{n_1}^n \frac{1}{x \log x} \text{d}x = \log \log n - \log \log n_1 = \Theta(\log \log n),$$ and the solution of the recurr...
Assume we have this recurrence: $$T(n)=2T(\dfrac{n}{2})+\dfrac{8}{9}T(\dfrac{3n}{4})+\Theta(\dfrac{n^2}{\log{n}})$$ We want to solve it using Akra-Bazzi method. As we know, $\sum_{i=1}^k\dfrac{a_i}{b_i^p}=1$. So $\dfrac{2}{2^p}+\dfrac{\dfrac{8}{9}}{(\dfrac{4}{3})^p}=1$ and we get $p=2$. We know: $$T(n)=\Theta\left(...
It is sufficient for the lower limit of integration to be large enough (see the [original paper][1]). If you pick any $n_1 > 1$, $\log \log n_1$ exists and is just some constant. Then $$\int_{n_1}^n \frac{1}{x \log x} \text{d}x = \log \log n - \log \log n_1 = \Theta(\log \log n),$$ and the solution of the recurr...
Your classmates elected you to be in charge of the creation of the short and long distance running teams for the upcoming Sports Day event in your school. They have kindly given you their timings for both the short and long distance relay. Classes are will be ranked based on the shortest total time of both events combi...
Given a group of people with timings for 2 events, find the shortest total time for X and Y given that events are mutually exclusive
|optimization|
Your classmates elected you to be in charge of the creation of the short and long distance running teams for the upcoming Sports Day event in your school. They have kindly given you their timings for both the short and long distance relay. Classes are will be ranked based on the shortest total time of both events combi...
I have been reading these [distributed computing notes][1]. In some of the proofs, for proving lower bound of $\Omega(f(n))$, we prove that no algorithm which solves the problem in $o(f(n))$ exists. I can't see how not having a $o(f(n))$ algorithm proves the lower bound is $\Omega(f(n))$. I tried using the defin...
Proving lower bound by proving not little o
|time-complexity|lower-bounds|
null
I am looking at [DAWGs](http://stevehanov.ca/blog/?id=115), which are compressed tries, like this: [![enter image description here][1]][1] It is an _acyclic_ graph though, and I'm wondering if you are allowed to create loops or cycles in such a data structure. For example, I am [thinking](https://github.com/mc...
Can a trie or DAWG loop?
|graphs|data-structures|loops|dag|trie|
Your classmates elected you to be in charge of the creation of the short and long distance running teams for the upcoming Sports Day event in your school. They have kindly given you their timings for both the short and long distance relay. Classes are will be ranked based on the shortest total time of both events combi...
I will try to answer your questions from my personal experience with tries. Some time ago I had to face a similar problem: I had to store all well-formed meaningful Italian words (300'000 more or less) using a trie for detecting duplicates in a text and possibly suggest them to the user during typing. I didn't have th...
A valid tree decomposition of a graph $G =(V,E)$ is also a valid tree decomposition of any subgraph $G' = (V', E') $ provided that you simply remove all vertices $v \in V \setminus V'$ from all the bags. Let's look at the definition. A tree decomposition $\mathcal T$ of $G$ is a tree of "bags" where each bag is a s...
Assume we have this recurrence: $$T(n)=2T(\dfrac{n}{2})+\dfrac{8}{9}T(\dfrac{3n}{4})+\Theta(\dfrac{n^2}{\log{n}})$$ We want to solve it using Akra-Bazzi method. As we know, $\sum_{i=1}^k\dfrac{a_i}{b_i^p}=1$. So $\dfrac{2}{2^p}+\dfrac{\dfrac{8}{9}}{(\dfrac{4}{3})^p}=1$ and we get $p=2$. We know: $$T(n)=\Theta\left(...
This is false, various construction for computing simultaneously the same function on disjoint sets of variables are discussed in [this cstheory.stackoverflow question][1]. [1]: https://cstheory.stackexchange.com/q/3085
null
Is there any books, papers or blogs 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 more intuitive methods that does not go deep into the low level implementation principles ...
Is there any reference materials on complexity analysis for lazy languages?
|complexity-theory|functional-programming|haskell|theory|
Your confusion is completely justified. When we say that some problem $A$ has a lower bound of $\Omega(f(n))$ usually we mean that "No algorithm that runs in time $o(f(n))$ solves $A$" or equivalently, "there is an infinite class of instances for which any algorithm that solves $A$ requires time at least $cf(n)$ fo...
In a non-preemptive scheduler, the running process cannot be interrupted by **another process**. The running process **can** be interrupted by hardware interrupts.
## My Problem ## I'm currently dealing with an algorithmic problem that involves two input lists: 1. A list of natural numbers $[A_1, A_2, \dots, A_n]$ with $A_1, \dots, A_n \in \mathbb{N}$. 2. A list of triples $[(B_1, C_1, D_1), (B_2, C_2, D_2), \dots, (B_m, C_m, D_m)]$ with $m\geq n$, natural numbers $B_1, ...
Optimizing an Algorithm for Timestamp-Aware Partitioning of Data
|algorithms|complexity-theory|dynamic-programming|
## My Problem ## I'm currently dealing with an algorithmic problem that involves two input lists: 1. A list of natural numbers $[A_1, A_2, \dots, A_n]$ with $A_1, \dots, A_n \in \mathbb{N}$. 2. A list of triples $[(B_1, C_1, D_1), (B_2, C_2, D_2), \dots, (B_m, C_m, D_m)]$ with $m\geq n$, natural numbers $B_1, ...
## My Problem ## I'm currently dealing with an algorithmic problem that involves two input lists: 1. A list of natural numbers $[A_1, A_2, \dots, A_n]$ with $A_1, \dots, A_n \in \mathbb{N}$. 2. A list of triples $[(B_1, C_1, D_1), (B_2, C_2, D_2), \dots, (B_m, C_m, D_m)]$ with $m\geq n$, natural numbers $B_1, ...
## My Problem ## I'm currently dealing with an algorithmic problem that involves two input lists: 1. A list of natural numbers $[A_1, A_2, \dots, A_n]$ with $A_1, \dots, A_n \in \mathbb{N}$. 2. A list of triples $[(B_1, C_1, D_1), (B_2, C_2, D_2), \dots, (B_m, C_m, D_m)]$ with $m\geq n$, natural numbers $B_1, ...
I am studying for an algorithm design course, and can't understand this demonstration about how Dinitz’ algorithm computes a maximum flow in $O(m \sqrt{n})$ time. This is what is written on the slides I am reading: > Theorem. [Even–Tarjan 1975] In simple unit-capacity networks, Dinitz’ > algorithm computes a ma...
Dinitz’ algorithm in simple unit-capacity networks
|complexity-theory|graphs|network-flow|bipartite-matching|bipartite-graph|
I am studying for an algorithm design course, and can't understand this demonstration about how Dinitz’ algorithm computes a maximum flow in $O(m \sqrt{n})$ time. This is what is written on the slides I am reading: > Theorem. [Even–Tarjan 1975] In simple unit-capacity networks, Dinitz’ > algorithm computes a ma...
null