instruction stringlengths 0 29.8k ⌀ |
|---|
Non-dominated maximal paths in a DAG |
null |
null |
null |
null |
Somehow turn the opaque lambdas
<!-- language-all: ml -->
```python
next_cont = lambda result: current_cont(current_value * result)
```
into transparent data
```
next_cont = Compose( current_cont, Mult(current_value))
```
then use the fact that
```
Compose( Compose( a_cont, Mult(val)), Mult(current_value... |
Partition an array in two groups while keeping the relative order within both groups |
null |
In parallel programming the iteration scheduling is defined as the determination of the logical execution time for each loop iteration, while in operating systems, the processor scheduling (FCFS etc) is defined as the ordering in which the processes get the CPU to execute. Since the execution of a loop is a process its... |
Iteration scheduling vs processor scheduling |
|scheduling|loops| |
# To sort 64 elements
Time required is $n*log_2{n}$ units
The equivalent posteriori time is 30 sec.
# In 6 minutes
I get 768 elements sorted.
But the answer is not 768 and is instead 512, I wonder why?
|
If mergesort takes 30 sec to sort 64 elements in worst case, how many elements can be sorted at worst case by using it in 6 minutes? |
|algorithms|mergesort| |
Consider a circular graph $G_1$ with $n$ vertices and a complete graph $G_2$ with $m$ vertices. What is the maximum attainable ratio when determining the Minimum Spanning Tree (MST) using Boruvka, Kruskal, or Prim algorithms? I know there is no MST in a circular graph, but let's consider the amount of steps until we ha... |
MST algorithms worst scenarios for halting on circular graph/computing complete graph |
|complexity-theory|minimum-spanning-tree| |
The following is a real world problem, for which I adjusted the explanation, such that it is easier to understand.
In a very abstract form, the challenge is to find a group-sorting algorithm, that is only allowed to use queues.
**Instance of the problem**<br>
Let’s assume we have people arriving in cars at the ent... |
Consider a circular graph $G_1$ with $n$ vertices and a complete graph $G_2$ with $m$ vertices. What is the maximum attainable ratio when determining the Minimum Spanning Tree (MST) using Boruvka, Kruskal, or Prim algorithms?
I think about it in the following way:
A complete graph with $v$ vertices has $\dfrac{(v... |
MST algorithms worst scenarios for circular graph/complete graph |
Disregarding the fact that these calculations make no sense in real world, here is what we get:
$n \cdot log_2 n \cdot T = 30$
where $T$ is the time for single operation. We substitute $n=64$ and we get
$64 \cdot 6 \cdot T = 30$
this gives $T=0.078125$
We can now solve the following:
$n \cdot log_2n... |
null |
Rice's theorem asserts that as soon as $f$ is non-trivial (i.e., non-constant), and extensional (i.e., $f(M) = f(M')$ as soon as $M$ and $M'$ are codes of Turing machines with the same behavior, in the sense that both halt and return the same output or both don't halt), $f$ is uncomputable.
One classic way to prove ... |
Turing degree of some functions related to Rice's theorem |
|turing-machines|computability| |
6 minutes to 30 seconds is a factor of 12, so you want:
$$ \frac{N\cdot\text{log}(N)}{64\cdot\text{log}(64)} = 12 $$
You can easily verify that for N=512, the result is indeed 12. For N=768 the result is 19.17, which is the wrong answer. Note that it doesn't matter which logarithm (binary, natural, ...) you use, the ... |
null |
They are different problems in practice.
In computing, you know the entire problem in advance and you want to find the optimal schedule (order of operations, split between multiple machines) and then execute it. If we have a product of four matrices `ABCD` we can solve this as `((AB)C)D` or `(AB)(CD)` or `(A(BC))D` ... |
They are different problems in practice.
In computing, you know the entire problem in advance and you want to find the optimal schedule (order of operations, split between multiple machines) and then execute it. If we have a product of four matrices `ABCD` we can solve this as `((AB)C)D` or `(AB)(CD)` or `(A(BC))D` ... |
Just to clarify the question, you are demanding that $f$ be *total*, i.e. that $f(M)$ terminate in all cases, even if $M$ does not terminate (otherwise we can simply run $M$ and return its output).
**Relation to another question:** This being said, question turns out to be the same as the one [I asked here on MathO... |
They are different problems in practice. Task scheduling is about fulfilling constraints, computation scheduling is about minimizing work.
In computing, we know the entire problem in advance and we want to find the optimal schedule (order of operations, split between multiple machines) and then execute it. If we hav... |
Rice's theorem asserts that as soon as $f$ is non-trivial (i.e., non-constant), and extensional (i.e., $f(M) = f(M')$ as soon as $M$ and $M'$ are codes of Turing machines with the same behavior, in the sense that both halt and return the same output or both don't halt), $f$ is uncomputable.
One classic way to prove ... |
Consider a circular graph $G_1$ with $n$ vertices and a complete graph $G_2$ with $m$ vertices. What is the maximum attainable ratio when determining the Minimum Spanning Tree (MST) using Boruvka, Kruskal, or Prim algorithms?
I think about it in the following way:
A complete graph with $v$ vertices has $\dfrac{(v... |
I'm adding an answer to share my rough JavaScript version of V8's `FromStringLarge` algorithm:
```typescript
const fromBase = (text: string, base: bigint): bigint => {
let parts = text.split("").map((part) => [BigInt(part), base]);
if (parts.length === 1) {
return parts[0][0];
}
let pairFull: boolean... |
I am trying to solve the following problem. I've tried to find the name of this problem, but could not really find what I was looking for. I assume there should be some graph-theory that covers it, but it's been a while since my last algorithms class.
I do not need the global best solution, a "pretty good" solution ... |
null |
Let $L \subseteq \Sigma^*$ be a language in PSPACE, and let $T$ be a TM that decides $L$ is polynomial space-complexity $s: \mathbb{N} \to \mathbb{N}$. We need to show that $L\leq_p ALL_{NFA}$. So we need to define a polynomial-time reduction that on input $x$, outputs an NFA $A_x$ such that $T$ accepts $x$ iff $A_x$ ... |
Let's show a generic PTIME reduction from any language in $\text{PSPACE}$ to $ALL_{NFA}$.
Let $L \subseteq \Sigma^*$ be a language in PSPACE, and let $T$ be a TM that decides $L$ with polynomial space-complexity $s: \mathbb{N} \to \mathbb{N}$. We need to show that $L\leq_p ALL_{NFA}$. So we need to define a polynomia... |
Let's show a generic PTIME reduction from any language in $\text{PSPACE}$ to $ALL_{NFA}$.
Let $L \subseteq \Sigma^*$ be a language in PSPACE, and let $T$ be a TM that decides $L$ with polynomial space-complexity $s: \mathbb{N} \to \mathbb{N}$. We need to show that $L\leq_p ALL_{NFA}$. So we need to define a polynomia... |
Let's show a generic PTIME reduction from any language in $\text{PSPACE}$ to $ALL_{NFA}$.
Let $L \subseteq \Sigma^*$ be a language in PSPACE, and let $T$ be a TM that decides $L$ with polynomial space-complexity $s: \mathbb{N} \to \mathbb{N}$. We need to show that $L\leq_p ALL_{NFA}$. So we need to define a polynomia... |
Just to clarify the question, you are demanding that $f$ be *total*, i.e. that $f(M)$ terminate in all cases, even if $M$ does not terminate (otherwise we can simply run $M$ and return its output).
**Relation to another question:** This being said, question turns out to be the same as the one [I asked here on MathO... |
Just to clarify the question, you are demanding that $f$ be *total*, i.e. that $f(M)$ terminate in all cases, even if $M$ does not terminate (otherwise we can simply run $M$ and return its output).
**Relation to another question:** This being said, question turns out to be the same as the one [I asked here on MathO... |
null |
null |
Consider the following problem stated formally:
> You are given $n$ objects $o_1$, $o_2$, ..., $o_n$ and $k$ classes $c_1$, $c_2$, ..., $c_k$, each class containing some objects; an object is chosen. Construct queries asking about the class of the object, such that it can find the chosen object respective to the res... |
How to optimally construct queries asking about the class of an object to eventually find it? |
|algorithms|optimization|classification|binary-search| |
Why is the time complexity of the following code **Big O of Log n base k
$\ O(Log_k n)$ ?**
```
for(int i=0;i<n;i++){
i*=k;
}
```
------------------------------------------
The problem is number 8 from: <br>
https://www.geeksforgeeks.org/practice-questions-time-complexity-analysis/
I trace the p... |
Why is the time complexity of the following code **Big O of Log n base k
$\ O(Log_k n)$ ?**
```
for(int i=0;i<n;i++){
i*=k;
}
```
------------------------------------------
The problem is number 8 from: <br>
https://www.geeksforgeeks.org/practice-questions-time-complexity-analysis/
I trace the p... |
Consider the following problem stated formally:
> You are given $n$ objects $o_1$, $o_2$, ..., $o_n$ and $k$ classes $c_1$, $c_2$, ..., $c_k$, each class containing some objects; an object is chosen. Construct queries asking about the class of the object, such that it can find the chosen object respective to the res... |
In the pumping lemma conditions for context-free grammar we have that the string can be divided into $uv^{i}xy^{i}z$, but in the case of $i = 0$, why does it still belong to the language?, is it possible to have an example with a string?
Should it be $i = 1$, a repetition and for $i = 0$?
In the case $i = 0$ the w... |
Doubt about the pumping lemma for CFG when i = 0 |
|context-free|pumping-lemma| |
In the pumping lemma conditions for context-free grammar we have that the string can be divided into $uv^{i}xy^{i}z$, but in the case of $i = 0$, why does it still belong to the language?, is it possible to have an example with a string?
Should it be $i = 1$ is one repetition and for $i = 0$?
In the case $i = 0$ t... |
|algorithms|time-complexity|algorithm-analysis|dynamic-programming|greedy-algorithms| |
null |
Why is the time complexity of the following code **Big O of Log n base k
$\ O(Log_k n)$ ?**
```
for(int i=0;i<n;i++){
i*=k;
}
```
------------------------------------------
The problem is number 8 from: <br>
https://www.geeksforgeeks.org/practice-questions-time-complexity-analysis/
I trace the p... |
If the string generated by the grammar is long enough then somewhere in the derivation tree we will find a repeated variable. Below that is $A$. This induces the devision $vwxyz$ in substrings, following the subtrees in the derivation.
Using the rules of the grammar we can play with the derivations $A \Rightarrow^* ... |
null |
Besides what has been said, I wonder: what kind of real physical object would such a thing modelize?
I mean, a Turing machine can be in an infinity of states but at least you can start running it with a bounded memory (say n states), then after some run time if you have exhausted the memory you can "buy more RAM" an... |
Question
-----------------
Prove that the number of comparisons between elements in binary heap build is at most $2n-2$.
$n$ is the total number of the nodes.
----------
pseudo code
-----------------
```
BUILD-MAX-HEAP (A)
1 heap-size [A] < - length[A]
2 for i <- Length[A]/2| downto 1
3 do MAX-H... |
Consider a circular graph $G_1$ with $n$ vertices and a complete graph $G_2$ with $m$ vertices. What is the maximum attainable ratio when determining the Minimum Spanning Tree (MST) using Boruvka, Kruskal, or Prim algorithms?
I think about it in the following way:
A complete graph with $v$ vertices has $\dfrac{(v... |
Usually, when defining the size of a Rabin automaton, we take into consideration the automaton's index (the number of Rabin pairs) and not only the number of states. What you asked for is well-known, and here are the known lower bounds of the $NBW \to DRW$ translation. Where $NBWs$ is an abbreviation for nondeterminist... |
While the answer by Hendrik Jan is accurate. Here is a simple example that demonstrates the idea. Consider a CFG $G$ with the following rules $S \to aSb|\epsilon$. It is not hard to see that $L(G) = \{a^n b^n: n\geq 0\}$, and that for example, $p = 4$ is a pumping constant for $L(G)$. Indeed, every word $d$ in $L(G)$ o... |
While the answer by Hendrik Jan is correct. Here is a concrete example. Consider a CFG $G$ with the following rules $S \to aSb|\epsilon$. It is not hard to see that $L(G) = \{a^n b^n: n\geq 0\}$, and that for example, $p = 4$ is a pumping constant for $L(G)$. Indeed, every word $d$ in $L(G)$ of length at least $4$, is ... |
null |
{"Voters":[{"Id":77862,"DisplayName":"Bader Abu Radi"}],"DeleteType":1} |
While the answer by Hendrik Jan is correct. Here is a concrete example. Consider a CFG $G$ with the following rules $S \to aSb|\epsilon$. It is not hard to see that $L(G) = \{a^n b^n: n\geq 0\}$, and that for example, $p = 4$ is a pumping constant for $L(G)$. Indeed, every word $d$ in $L(G)$ of length at least $4$, is ... |
{"Voters":[{"Id":77862,"DisplayName":"Bader Abu Radi"}]} |
As has been pointed out in the comments, the sum approaches two in the limit to infinity.
$$\sum_{m=0}^\infty \frac{m}{2^m} = 2$$
You attempted to make use of this finding, in vain. Turns out the bound isn't tight enough. We need something better. The exact value of the sum for a finite limit is:
$$\sum_{m=0}^M\frac... |
Consider the simply read-write lock algorithm that allows many readers and a single writer. Why is this algorithm flawed?
I was thinking about the implementation of a well-known read-write lock library and wondering why it didn't do this simpler approach.
**To read:**
1. atomically add 1.
2. if the old value ... |
Naive Read-Write Lock |
|concurrency|deadlocks| |
Here's a proof using induction. For now, this proof only works for a full heap of height **h**, which contains **n=2<sup>h</sup>-1** items. I'm open to suggestions on how to extend it for partial heaps.
Induction hypothesis: The build cost is the cost for constructing the heap from scratch. The merge cost is for mer... |
Let $\cal M$ be a deterministic stack automaton
${\cal M } = (Q, \Sigma, \Gamma, \delta, q_0, F, Z_0 )$.
Let $\gamma \in \Gamma^* $ a word on the stack alphabet.
Is it true that the language
$$L = \{ w \in \Sigma^* \mid (q_0,w,Z_0) \vdash^* (q,\epsilon, \gamma),\ q \in F \}$$
is a deterministic context free l... |
Is the language accepted by a DFA with a fixed word on the stack after consuming it a deterministic context free language? |
|formal-languages|automata|context-free| |
Yes, $L$ is a deterministic context-free language.
I will describe how to build a deterministic pushdown automaton $\mathcal{M}'$ to recognize $L$. The stack alphabet of $\mathcal{M}'$ is $\Gamma' = \Gamma \times \{0,1,\dots,|\gamma|,\bot\}$. When the stack of $\mathcal{M}$ contains the word $\beta=(\beta_1,\beta_... |
Besides what has been said, I wonder: what kind of real physical object would such a thing (a deterministic infinite automata) modelize?
I mean, a Turing machine can be in an infinity of states but at least you can start running it with a bounded memory (say n states), then after some run time if you have exhausted ... |
Besides what has been said, I wonder: what kind of real physical object would such a thing (a deterministic infinite automata) modelize?
I mean, a Turing machine has an infinity of possible states but at least you can start running it with a bounded memory (limiting it to $n$ reachable states), then after some run t... |
I've a set $N$ of $n$ distinct numbers of $d$-bits each; call them **words** ($1\leq n\leq 2^d$, with $d\geq 1$). I want to store $N$ using as least space as possible, by partitioning $N$ and factoring out the common bits within each group. The problem is finding the optimal partition, taking into account group payload... |
Succint data structure for storing n numbers using a xor-based partition |
|algorithms|data-structures|data-compression|encoding-scheme| |
I've a set $N$ of $n$ distinct numbers of $d$-bits each; call them **words** ($1\leq n\leq 2^d$, with $d\geq 1$). I want to store $N$ using as least space as possible, by partitioning $N$ and factoring out the common bits within each group. The problem is finding the optimal partition, taking into account group payload... |
For now, this proof only works for a fully populated heap of height **h**, which contains **n=2<sup>h</sup>-1** items. I'm open to suggestions on how to extend it for incomplete heaps. Throughout this answer, i will use two functions called **BuildCost** and **MergeCost**. The build cost is the cost for constructing a ... |
null |
For now, this proof only works for a fully populated heap of height **h**, which contains **n=2<sup>h</sup>-1** items. I'm open to suggestions on how to extend it for incomplete heaps. Throughout this answer, i will use two functions called **BuildCost** and **MergeCost**. The build cost is the cost for constructing a ... |
null |
null |
Consider the following problem stated formally:
> You are given $n$ objects $o_1$, $o_2$, ..., $o_n$ and $k$ classes $c_1$, $c_2$, ..., $c_k$, each class containing some objects; an object is chosen. Construct queries asking about the class of the object, such that it can find the chosen object respective to the res... |
So I have a bunch of strings that represent routes in a HTTP web framework. Each string has a leading `/`, some `/`-separated path segments which can either be a string, a single-segment wildcard `?`, or a trailing multi-segment wildcard `*`. e.g.
```
/foo
/bar
/qux/?
/?/baz/thingy
/xyz/*
```
I am trying to... |
Algorithm for identifying ambiguities in a set of HTTP routes with wildcards? |
|algorithms| |
So I have a bunch of strings that represent routes in a HTTP web framework. Each string has a leading `/`, some `/`-separated path segments which can either be a string, a single-segment wildcard `?`, or a trailing multi-segment wildcard `*`. e.g.
```
/foo
/bar
/qux/?
/?/baz/thingy
/xyz/*
```
I am trying to... |
null |
Algorithm for efficiently identifying ambiguities in a set of HTTP routes with wildcards/Unix Globs? |
So I have a bunch of strings that represent routes in a HTTP web framework. Each string has a leading `/`, some `/`-separated path segments which can either be a string, a single-segment wildcard `?`, or a trailing multi-segment wildcard `*`. e.g.
```
/foo
/bar
/qux/?
/?/baz/thingy
/xyz/*
```
I am trying to... |
So I have a bunch of strings that represent routes in a HTTP web framework. Each string has a leading `/`, some `/`-separated path segments which can either be a string, a single-segment wildcard `?`, or a trailing multi-segment wildcard `*`. e.g.
```
/foo
/bar
/qux/?
/?/baz/thingy
/xyz/*
/xyz/abc
```
I am... |
So I have a bunch of strings that represent routes in a HTTP web framework. Each string has a leading `/`, some `/`-separated path segments which can either be a string, a single-segment wildcard `?`, or a trailing multi-segment wildcard `*`. (For this problem, we can assume that `*` can only be in a trailing position)... |
So I have a bunch of strings that represent routes in a HTTP web framework. Each string has a leading `/`, some `/`-separated path segments which can either be a string, a single-segment wildcard `?`, or a trailing multi-segment wildcard `*`. (For this problem, we can assume that `*` can only be in a trailing position)... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.