instruction stringlengths 0 29.8k ⌀ |
|---|
|algorithms|search-algorithms| |
When we defining a `Functor` instance in Haskell, it should satisfy the following two laws:
- `fmap id = id`
- `fmap f . fmap g = fmap (f . g)`
But I found these two articles that say the second Functor law can be derived form the first:
- [The second `Functor` law is redundant](https://github.com/quchen/arti... |
The second Functor law is redundant, but I don't understand the proof |
|type-theory|category-theory|haskell| |
null |
I am writing a paper in which I describe some algorithms (using pseudocode) that have point clouds as inputs. In these algorithms, I need a structure to represent those point clouds. I need theses structures to permit to access the $i$-th point in a point cloud. I have read some papers that use sets to represent point ... |
How to represent a point cloud in the pseudocode of an algorithm? |
|type-theory|discrete-mathematics|mathematical-foundations| |
I am writing a paper in which I describe some algorithms (using pseudocode) that have point clouds as inputs. In these algorithms, I need a structure to represent those point clouds. I need these structures to permit to access the $i$-th point in a point cloud. I have read some papers that use sets to represent point c... |
I am writing a paper in which I describe some algorithms (using pseudocode) that have point clouds as inputs. In these algorithms, I need a structure to represent a point cloud. I need this structure to permit to access the $i$-th point in a point cloud. I have read some papers that use sets to represent point clouds, ... |
I have always assumed that "Linked List" is something in the lines of
struct Node
{
SomeClass payload;
Node * next = nullptr;
Node * prev = nullptr;
}
This implies the restriction of working with objects of only one type. Considering lists are horrible in access time I dou... |
null |
there are 3 kinds of TMs
1. a Halting TM on all inputs prints finitely many symbols on it's output tape and halts
2. a Circle-free TM on all inputs prints infinitely many symbols on it's output tape
3. a Crashy TM is neither Circle-free nor Halting
"the kinds of TMs" problem is to find a Crashy TM that computes t... |
Can you solve the "kinds of TMs" problem? |
|turing-machines| |
If there was a crashy-TM that computed $k$ we could use it to recognize the language $L$ of all TMs that print an infinite amount of symbols on the output tape.
Unfortunately $L$ is not recognizable. You can see this by noticing that, given any Turing machine $T$, you can construct a new Turing machine $T'$ that 1) ... |
I'm struggling with question 7-38 from Skiena's Algorithm Design Manual:
> Let G be a directed graph. We say that G is k-cyclic if every (not necessarily
simple) cycle in G contains at most k distinct nodes. Give a linear-time algorithm to determine if a directed graph G is k-cyclic, where G and k are given
as input... |
Checking if a graph contains a (not necessarily simple) cycle of length more than k |
|algorithms|graphs|algorithm-analysis| |
{"Voters":[{"Id":154493,"DisplayName":"V_head"}]} |
Consider any (not necessarily simple) cycle $C$, and notice that we can always build a new cycle $C'$ (possibly $C=C'$) that visits all vertices of $G$ that belong to the same connected component of at least one vertex in $C$.
Since the number of vertices visited by $C'$ is never smaller than those visited by $C$, w... |
If there was a crashy-TM that computed $k$ we could use it to recognize the language $L$ of all TMs that print an infinite amount of symbols on the output tape.
Unfortunately $L$ is not recognizable. You can see this by noticing that, given any Turing machine $T$, you can construct a new Turing machine $T'$ that 1) ... |
Consider any (not necessarily simple) cycle $C$, and notice that:
- All vertices in $C$ must belong to the same strongly connected component, say $A$.
- We can always build a new cycle $C'$ (possibly $C=C'$) that visits all vertices of $G$ that belong to $A$.
The problem now becomes the following: do all strongly ... |
{"Voters":[{"Id":6759,"DisplayName":"Steven"}]} |
{"Voters":[{"Id":6759,"DisplayName":"Steven"}]} |
Notice that:
- Any (not necessarily simple) cycle in $G$ contains only vertices that belong to a single strongly connected component of $G$.
- Given any strongly connected component $C$ of $G$, there is always a (not necessarily simple) cycle that visits all vertices in $C$.
The problem now becomes the followin... |
I have the following diagram showing a case of merge sort:
[![enter image description here][1]][1]
I am trying to find the value that would be in the box with the red cross when applying merge sort in ascending order.
It seems to me that it would be $71$. If we start at the bottom-right, we have $[30, 71]$ fo... |
Applying merge sort: Would the value in the box with the red cross be $71$? Does it matter whether we start at the bottom-left or bottom-right? |
|algorithms|mergesort| |
You don't need to simulate merge sort to figure out what that value will be.
Since you know that mergesort is correct, and you're looking for the 4-th element in that subarray, you just need to find the element with rank $4$ among $\{71, 30, 24, 49, 97\}$, i.e., $71$.
This value is independent of the order in which... |
null |
First of all LPL is Leaf path length & IPL is internal path length. While i was studying algorithm analysis for average complexity of binary search , i saw that inequality. Before that, i proved by induction for any full binary tree T, LPL(T) = IPL(T) + 2*I where I is the number of internal nodes . Now after that i tri... |
Inequality about External path length and internal path length |
|algorithms|algorithm-analysis|binary-trees|binary-search| |
If there was a crashy-TM that computed $k$ we could use it to decide the halting problem.
You can see this by noticing that, given any Turing machine $T$, you can construct a new Turing machine $T'$ that 1) halts if and only if $T$ halts, 2) if $T$ does not halt, then $T'$ prints infinitely many symbols. In your nom... |
Inequality about External path length |
Suppose we have an array of $n$ integers. Suppose that we pick one this elements uniformly at random and call it $x$. Suppose that $\log n$ elements are also sampled (uniformly at random) form the $n$-size array and we call $A$ this sampled array. What is the probability that $x$ lies in the middle third of the sorted ... |
Probability of this random selection |
|combinatorics|probability-theory|probabilistic-algorithms| |
Suppose we have an array of $n$ integers. Suppose that we pick one of these elements uniformly at random and call it $x$. Suppose that $\log n$ elements are also sampled (uniformly at random) from the $n$-size array and we call $A$ this sampled array. What is the probability that $x$ lies in the middle third of the sor... |
null |
Yes, correct but should be specifying 'break' in every case expect the last one because in the switch case the following statement also gets executed.
|
Let $\varphi(L) = L \log_2 L$ and notice that $\varphi$ is a convex function. Let $T$ be a tree with $L$ leaves. You can show by induction on $L$ that $LPL(T) \ge \varphi(L)$.
If $L = 1$, then $LPL(T)=0 = \varphi(1)$.
If $L>1$ then let $T_1$ and $T_2$ be the left and right subtrees of the root and call $L_i$ the ... |
Let $\varphi(L) = L \log_2 L$ and notice that $\varphi$ is a convex function. Let $T$ be a tree with $L$ leaves. You can show by induction on $L$ that $LPL(T) \ge \varphi(L)$.
If $L = 1$, then $LPL(T)=0 = \varphi(1)$.
If $L>1$ then let $T_1$ and $T_2$ be the left and right subtrees of the root and call $L_i$ the ... |
null |
I am writing a scientific paper in which I describe some algorithms (using pseudocode) that have point clouds as inputs. In these algorithms, I need a structure to represent a point cloud. I need this structure to permit to access the $i$-th point in a point cloud. I have read some papers that use sets to represent poi... |
I am writing a scientific paper in which I describe some algorithms (using pseudocode) that have point clouds as inputs. In these algorithms, I need a mathematical structure to represent a point cloud. I need this mathematical structure to permit to access the $i$-th point in a point cloud. I have read some papers that... |
{"Voters":[{"Id":154493,"DisplayName":"V_head"}]} |
{"Voters":[{"Id":154493,"DisplayName":"V_head"}]} |
In lecture the following was mentioned in the context of matchings in bipartite graphs:
>Let $U$ be a finite set and let $\mathcal{S}$ be a family of subsets of $U$.
>For $u \in U$ let $r(u) := \lvert \{S \in \mathcal{S} \mid u \in S\}\rvert$ and let $n := \lvert \mathcal{S} \rvert$ and $N := \sum_{S \in \mathcal{S... |
How to argue that an $A$-covering matching exists in this bipartite graph? |
|graphs|sets|matching|bipartite-matching| |
The inequality $|S| < \frac{N}{n-1}$ indeed is very important. Suppose $\mathcal{S} = \{S_1, S_2, …, S_n\}$, where $|S_1| \leqslant |S_2| \leqslant … \leqslant |S_n| < \frac{N}{n-1}$.
- First, $N = \sum\limits_{S\in \mathcal{S}}|S| = |S_1| + \sum\limits_{i=2}^n|S_i| \leqslant |S_1| + (n-1)|S_n| \leqslant |S_1| + (n... |
Yes, **these two heuristics does sound like inconsistent**. Most Constrained Variable (MCV) (also called MRV for Minimum Remaining Values) tries to reduce the size of the next branch to search while Least Constraining Values tries to enlarge the size of the next branch to search.
However, if you take a close look, t... |
Recently, I study the instruction set of riscv32 and face a order as "mulh" which tends to multiply two 32-bits signed integers and store the high 32 value into the register.
And here comes the problem, there are two integer src1 and src2, I want to implement these instruction in C language by using shift operation... |
how to get the high 32-bit of the answer of two 32-bit integer multiple? |
|algorithms|mathematical-programming|c|instruction-set| |
there are 3 kinds of TMs
1. a Halting TM on all inputs prints finitely many symbols on it's output tape and halts
2. a Circle-free TM on all inputs prints infinitely many symbols on it's output tape
3. a Crashy TM is neither Circle-free nor Halting
 by writing state to storage in blocks? Wouldn’t this allow for a seamless restoration of state when the process needs to continue? Specifically, in graphics intensive processes (ie video games), wouldn’t this make load time way quicker? |
Saving Process State by Writing Pages to Blocks |
|operating-systems| |
Operating systems already do that when they need to. See, e.g., https://en.wikipedia.org/wiki/Context_switch, https://en.wikipedia.org/wiki/Memory_paging, https://en.wikipedia.org/wiki/Process_control_block, https://en.wikipedia.org/wiki/Virtual_memory.
More specifically, if there is plenty of RAM, there is no need... |
If there was a crashy-TM that computed $k$ we could use it to decide this version of the halting problem, which is known to be undecidable: given a Turing machine $T$, does $T$ halt on empty input?
You can see this by noticing that, given any Turing machine $T$, you can construct a new Turing machine $T'$ that 1) ha... |
$$
\def\P{{\mathbb P}}
\def\E{{\mathbb E}}
\def\I{{\mathbb I}}
$$
The probability is approximately $\frac 13$.
"Approximately" depends on $n$, your definition of "third" (i.e. what to do if $3$ doesn't divide $1 + \log n$), and on whether you sample without or with replacement (and in this case, how you h... |
null |
You are computing
$$(2^{16}A_1+B_1)(2^{16}A_2+B_2)$$
which is
$$2^{32}A_1A_2+2^{16}(A_1B_2+A_2B_1)+B_1B_2.$$
If we decompose
$$A_1B_2+A_2B_1=2^{16}A_3+B_3$$
where $A_3$ is at most $17$ bits and $B_3$ is $16$ bits, this turns to
$$2^{32}A_1A_2+2^{32}A_3+2^{16}B_3+B_1B_2.$$
So the carry from the l... |
Yes, **these two heuristics sound like inconsistent**. Most Constrained Variable (MCV) (also called MRV for Minimum Remaining Values) tries to reduce the size of the next branch to search while Least Constraining Values tries to enlarge the size of the next branch to search.
However, if you take a close look, they b... |
The binary expansion of a given real number can be encoded as an amplitude using the inverse QPE. Together with Amplitude Amplification, I wonder if this could indicate that the (some weakened?) trichotomy of the real numbers is physically effective.
---
I think the crux of the question is that these assumptions ... |
The same way as in [this question](https://cs.stackexchange.com/questions/136359/rigorous-proof-that-parametric-polymorphism-implies-naturality-using-parametrici), the gap is once again the identity extension property. This means that the relational interpretation of a type operator maps identity relations to identity ... |
First of all LPL is Leaf path length & IPL is internal path length. While i was studying algorithm analysis for average complexity of binary search , i saw that inequality. Before that, i proved by induction for any full binary tree T, LPL(T) = IPL(T) + 2*I where I is the number of internal nodes . Now after that i tri... |
Andras is correct here. In the interest of full disclosure, I'm the original author of lambdabot and the free theorem plugin, and so I'm in a unique position to tell you exactly what's going on.
The way the plugin works is that it assumes that a type constructor with a single argument is a functor, and generates a f... |
Andras is correct here. In the interest of full disclosure, I'm the original author of lambdabot and the free theorem plugin, and so I'm in a unique position to tell you exactly what's going on.
The way the plugin works is that it assumes that a type constructor with a single argument is a functor, and generates a f... |
Suppose we have an undirected, connected graph $G$ where vertices have positive integer weights. Let $\bar{v}$ be a given vertex in $G$. Take a spanning tree $T$ of $G$ rooted at $\bar{v}$ and define its cost as the maximum total weight among all proper subtrees. (Since weights are positive the proper subtree(s) with m... |
Andras is correct here. In the interest of full disclosure, I'm the original author of lambdabot and the free theorem plugin, and so I'm in a unique position to tell you exactly what's going on.
The way the plugin works is that it assumes that a type constructor with a single argument is a functor, and generates a f... |
I have been thinking a bit about error correcting codes, in particular the following problem:
Consider the problem of transmitting a single real number $x \in [0,1]$ over a lossy connection, where each bit sent has a i.i.d probability $p < 0.5$ of being flipped during transmission.
For a given number of transmitted... |
Error correcting codes for transmitting a real value $x$ in [0,1], minimizing the reconstructed distance to the original $x$ |
|probabilistic-algorithms|error-correcting-codes| |
Back here with some more doubts, i wanted to understand, how can we formally or may be easily calculate time complexity for such question without getting into "DRY RUN", i mean is there any way for it? and for below question i am getting O(loglog(n/2)) which is not right!
Thankyou in advance for sharing your wisdom ... |
Loops and Its Time Complexity |
|algorithms|time-complexity| |
When we defining a `Functor` instance in Haskell, it should satisfy the following two laws:
- `fmap id = id`
- `fmap f . fmap g = fmap (f . g)`
But I found these two articles that say the second Functor law can be derived form the first:
- [The second `Functor` law is redundant](https://github.com/quchen/arti... |
The same way as in [this question](https://cs.stackexchange.com/questions/136359/rigorous-proof-that-parametric-polymorphism-implies-naturality-using-parametrici), the gap is once again the identity extension property. This means that the relational interpretation of a type operator maps identity relations to identity ... |
{"Voters":[{"Id":154493,"DisplayName":"V_head"}]} |
After going through the resource list, is the following a way to explain ford fulkerson concisely ?
```
while exists (P_residual = residual graph path from S to T obtained via BFS )
modify actual and residual graph with P_residual
```
I am assuming *P_residual* is the *augmented path* ?
Resources
-----... |
How can ford fulkerson be explained concisely? |
|graphs|graph-traversal| |
I'm studying for an exam and have run into a problem that I do not understand. The main program starts two threads that execute the following program concurrently, whenever both threads terminate the program will print the result of counter. I am assuming that the maximum value of counter will be 10? But what will the ... |
What is the minimum and maximum value of Counter when the two threads are executed concurrently? |
|concurrency|threads| |
The inequality $|S| < \frac{N}{n-1}$ indeed is very important. Suppose $\mathcal{S} = \{S_1, S_2, …, S_n\}$, where $|S_1| \leqslant |S_2| \leqslant … \leqslant |S_n| < \frac{N}{n-1}$.
- First, $N = \sum\limits_{S\in \mathcal{S}}|S| = |S_1| + \sum\limits_{i=2}^n|S_i| \leqslant |S_1| + (n-1)|S_n| \leqslant |S_1| + (n... |
Suppose we modify the Knuth-Morris-Pratt string-matching algorithm to scan the pattern right-to-left a la Boyer-Moore, and consequently apply the shift rule on the right side of the cursor instead of the left side. The quantity $\text{sp}_i(P)$ is now defined as the length of the longest proper prefix-suffix of $P[i\do... |
Complexity of right-to-left Knuth-Morris-Pratt algorithm |
|runtime-analysis|string-matching| |
Operating systems already do that when they need to. See, e.g., https://en.wikipedia.org/wiki/Context_switch, https://en.wikipedia.org/wiki/Memory_paging, https://en.wikipedia.org/wiki/Process_control_block, https://en.wikipedia.org/wiki/Virtual_memory.
More specifically, if there is plenty of RAM, there is no need... |
The minimum cannot be $0$, because at least one $\text{while}$ will execute, a $\text{while}$ that is entered is performed in full, and the execution of any $\text{while}$ will inevitably increment $\text{counter}$.
But the minimum can be $1$, as follows:
- the left process executes from $i=0$, until the assignme... |
First of all, lets clarify the functional difference between
```
i = i+1
```
and
```
cnt = counter
counter = cnt+1
```
There is none! Both segments must first read a value from global memory into a register, operate on/with said register and write the result back to global memory. So both execute three in... |
The minimum cannot be $0$, because at least one $\text{while}$ will execute, a $\text{while}$ that is entered is performed in full, and the execution of any $\text{while}$ will inevitably increment $\text{counter}$.
But the minimum can be $1$, as follows:
- the left process executes with $i=0$, until the assignme... |
The minimum cannot be $0$, because at least one $\text{while}$ will execute, a $\text{while}$ that is entered is performed in full, and the execution of some $\text{while}$ will inevitably increment $\text{counter}$.
But the minimum can be $1$, as follows:
- the left process executes with $i=0$, until the assignm... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.