instruction stringlengths 0 29.8k ⌀ |
|---|
null |
In a web application, I use a map as a simple in-memory cache/lookup.
- A key is a string, say `A` and maps to an integer value, say `50`.
- The app handles thousands of requests per minute. Requests need to look up keys.
- If the key isn't found in the map, then the value is computed and stored under they key ... |
Data structure to keep track of cache hit ratio? |
|data-structures| |
In a [CP-algorithms](https://cp-algorithms.com/graph/second_best_mst.html) wiki *Second Best Minimum Spanning Tree - Using Kruskal and Lowest Common Ancestor*:
> Let $T$ be the Minimum Spanning Tree of a graph $G$ . It can be observed, that the second best Minimum Spanning Tree differs from $T$ by one edge repla... |
Distinct edge weights assumption in second best MST algorithms only updating an edge in MST |
|graphs|proof-techniques|weighted-graphs|minimum-spanning-tree|spanning-trees| |
The proof provided may be modified to work without distinct edge weights assumption:
> **Proof** (sketch). Let $T$ be an MST and $T'$ be a second-best MST. Suppose for contradiction, there are two edges in $T - T'$, and let $e$ be an edge in $T - T'$ with minimum weight. If we add $e$ to $T'$, we get a cycle $c$, wh... |
How much money do you have?
There is at the moment no technology that could create configurable hardware that is faster than a general purpose CPU. (Improving configurable hardware would improve the general purpose CpU as well).
Apple has improved existing CPUs, I'd say that cost them maybe ten billion dollars.... |
Python is an imperative language, meaning any operation can have side effects. This makes such "gate level" thinking tricky. Its written in a way such that there's no issue with a block of memory being the name of a person at one point and becoming a control flow variable in the next.
This means any attempt to con... |
Suppose I have an array of 2D coordinates {x:number,y:number}[]. What would be an algorithm that could get me the points that, were an X by Y grid of rectangles laid over the cartesian graph created by the array, are closest to the middle of each rectangle that contains points?
Here's a very roughly drawn example:
... |
Algorithm that finds points that best fits grid based on array of 2D coordinates |
|algorithms| |
What you're looking for is not so much a data structure as a problem statement. What is it that you're trying to learn from a metric such as a hit-count? The structures need to match what you're doing with the data.
From the sound of it, the data you wish to work with is a time history of hit ratios. You want to ... |
// Linz Turing machine H --- H applied to ⟨H⟩
H.q0 ⟨H⟩ ⟨H⟩ ⊢* H.qy // H applied to ⟨H⟩ halts
H.q0 ⟨H⟩ ⟨H⟩ ⊢* H.qn // H applied to ⟨H⟩ does not halt
Do you halt on your own Turing Machine description ?
Of the infinite set of implementations of H every one that transitions to H.qy derives an an... |
// Linz Turing machine H --- H applied to ⟨H⟩
H.q0 ⟨H⟩ ⟨H⟩ ⊢* H.qy // H applied to ⟨H⟩ halts
H.q0 ⟨H⟩ ⟨H⟩ ⊢* H.qn // H applied to ⟨H⟩ does not halt
Do you halt on your own Turing Machine description ?
Of the infinite set of implementations of H every one that transitions to H.qy derives an an... |
In the essay [Relating Theories of the lambda-calculus](https://www.andrew.cmu.edu/user/awodey/dump/Scott/ScottRelating.pdf), Scott constructs (from page 418) a category that exhibits a chosen lambda calculus $ L $ with $ \beta $-equality as the collection(s) of morphisms $ E(U)_n = U^n \to U $.
Now, the constructio... |
The isomorphism in "Scott's representation theorem" |
|lambda-calculus|category-theory| |
I recently started learning about the chomsky hierarchy and I am preparing myself for an upcoming exam. Often there are tasks to specify the smallest classification of a given formal language. How does one safely find the smallest class the language is included in? Which criterias should one look for when doing so?
... |
How to determine class of formal language in Chomsky Hierachy |
|formal-languages|automata|chomsky-hierarchy| |
@Highheath has given an [excellent and concise answer](https://cs.stackexchange.com/a/165761/96482) already.
I came up (with the help of some friends) with a much longer one, which I still think it's worth posting. Maybe it's because I worked on it for a few hours, but I find it easier to comprehend despite its leng... |
@Highheath has given an [excellent and concise answer](https://cs.stackexchange.com/a/165761/96482) already.
I came up (with the help of some friends) with a much longer one, which I still think it's worth posting. Maybe it's because I worked on it for a few hours, but I find it easier to comprehend despite its leng... |
I recently started learning about the chomsky hierarchy and I am preparing myself for an upcoming exam. Often there are tasks to specify the smallest classification of a given formal language. How does one safely find the smallest class the language is included in? Which criterias should one look for when doing so?
... |
null |
Suppose I have an array of 2D coordinates {x:number,y:number}[]. What would be an algorithm that could get me the points that, were an X by Y grid of rectangles laid over the cartesian graph created by the array, are closest to the middle of each rectangle that contains points?
Here's a very roughly drawn example:
... |
Algorithm that finds points that are closest to the middle of rectangles in grid |
Suppose I have an array of 2D coordinates {x:number,y:number}[]. What would be an algorithm that could get me the points that, were an X by Y grid of rectangles laid over the cartesian graph created by the array, are closest to the middle of each rectangle that contains points?
Here's a very **roughly drawn** exampl... |
null |
We are given a file of three columns
the first is player name
the second is game item name
the third is the price of the game item while it bought by the player
items may repeat ror the dame player with different prices
what is the best parallel approach in time and space to get the player name with the hig... |
given a list of 3 dimension what is the best approach to find the highest sum |
|sorting|multithreaded| |
null |
null |
In a fully connected Neural Network, each perceptron has it's bias term $b$ which is learnt. Often (example, in Linear/ Logistic Regression), when we don't want to treat this bias term explicitly, we add an extra "constant" feature $x_0 = 1$ to each training example. Can we show whether this will/ will not work in a Ne... |
null |
@Highheath has given an [excellent and concise answer](https://cs.stackexchange.com/a/165761/96482) already.
I came up (with the help of some friends) with a much longer one, which I still think it's worth posting. Maybe it's because I worked on it for a few hours, but I find it easier to comprehend despite its leng... |
## The problem
Trying to improve my algorithms I bumped [into a problem][1] by Pedro Pablo Gómez Martín and Marco Antonio Gómez Martín, which I can summarise like this:
> You are given a list of enemy bases you want to conquer. You can only attack one base at a time. Each base $i$
> requires a minimum number of so... |
@Highheath has given an [excellent and concise answer](https://cs.stackexchange.com/a/165761/96482) already.
I came up (with the help of some friends) with a much longer one, which I still think it's worth posting. Maybe it's because I worked on it for a few hours, but I find it easier to comprehend despite its leng... |
@Highheath has given an [excellent and concise answer](https://cs.stackexchange.com/a/165761/96482) already.
I came up (with the help of some friends) with a much longer one, which I still think it's worth posting. Maybe it's because I worked on it for a few hours, but I find it easier to comprehend despite its leng... |
For refresher, let's first remember ([Wikipedia](https://en.wikipedia.org/wiki/Conjunctive_normal_form)) that we can convert any Boolean expression into conjunctive normal form, which is defined as conjunction ("AND" $\land$) of one or more disjunctions ("OR" $\lor$) of one or more literals, and governed by six context... |
null |
I remember that the [Roc Lang][1] website claimed that their choice to forbid any form of cyclic data structures prohibited their customer to implement some of the best in their class algorithms, id est some algorithms that are better than everything else solving the problem that they are designed to solve.
I have t... |
Examples of algorithms best their class that require cyclical data structures |
|algorithms|graphs|data-structures| |
I've been given a task to determine whether L={〈M〉|M is a TM that loops on the input c (a constant)} is decidable. I can prove co-L is recognizable so I figured a reduction from HALT to co-L would finish my proof that L isn't even recognizable. Now I'm stuck. I just can't seem to master creating mapping reductions.
... |
Mapping Reduction from HALT? |
|turing-machines|computability|reductions|halting-problem|decidability| |
Define the reduction $f$ such that $f(\langle M, w \rangle) = \langle M' \rangle$, where $M'$ is a TM that on word $x$
1. simulates $M$ on $w$ if $x = c$
2. halts
It's easy to see that
$$M \text{ halts on } w \iff M' \text{ halts on } c$$
so
$$\langle M, w\rangle \in \texttt{HALT} \iff f(\langle M, w \r... |
{"Voters":[{"Id":166766,"DisplayName":"Knogger"}],"DeleteType":1} |
{"Voters":[{"Id":166766,"DisplayName":"Knogger"}]} |
Define the reduction $f$ such that $f(\langle M, w \rangle) = \langle M' \rangle$, where $M'$ is a TM that on word $x$
1. simulates $M$ on $w$ if $x = c$
2. halts
It's easy to see that
$$M \text{ halts on } w \iff M' \text{ halts on } c$$
therefore
$$\langle M, w\rangle \in \texttt{HALT} \iff f(\langle ... |
As the other answers indicate, the language is indeed context-free.
Writing a grammar for it is a bit tricky, but we can do it as follows.
---
$N_a(x) = N_b(x)$
---
First, let's consider the (much) simpler language where every string has the *same* number of *a*'s as *b*'s.
We don't need a very methodic... |
null |
null |
I've been given a task to determine whether L={〈M〉|M is a TM that loops on the input c (a constant)} is decidable. I can prove co-L is recognizable so I figured a reduction from HALT to co-L would finish my proof that L isn't even recognizable. Now I'm stuck. I just can't seem to master creating mapping reductions.
... |
null |
Yes, this particular method doesn't use the y.parent pointer. However, other methods rely on it. Consider finding `successor`:
1. Traverse to the right if x.right is present to find smallest key greater than x.key
2. If the right subtree of node x is empty and x has a successor y, then y is the lowest `ancestor` of x... |
// Linz Turing machine H --- H applied to ⟨H⟩
H.q0 ⟨H⟩ ⟨H⟩ ⊢* H.qy // H applied to ⟨H⟩ halts
H.q0 ⟨H⟩ ⟨H⟩ ⊢* H.qn // H applied to ⟨H⟩ does not halt
Do you halt on your own Turing Machine description ?
Of the infinite set of implementations of H every one that transitions to H.qy derives an an... |
Any graph algorithm that works on general graphs (i.e., is not restricted to acyclic graphs) qualifies. You should be able to look through your favorite textbook and find many algorithms that work on graphs.
For instance, you could consider shortest-path algorithms. |
For refresher, let's first remember ([Wikipedia](https://en.wikipedia.org/wiki/Conjunctive_normal_form)) that we can convert any Boolean expression into conjunctive normal form, which is defined as conjunction ("AND" $\land$) of one or more disjunctions ("OR" $\lor$) of one or more literals, and governed by six context... |
For refresher, let's first remember ([Wikipedia](https://en.wikipedia.org/wiki/Conjunctive_normal_form)) that we can convert any Boolean expression into conjunctive normal form, which is defined as conjunction ("AND" $\land$) of one or more disjunctions ("OR" $\lor$) of one or more literals, and governed by six context... |
For refresher, let's first remember ([Wikipedia](https://en.wikipedia.org/wiki/Conjunctive_normal_form)) that we can convert any Boolean expression into conjunctive normal form, which is defined as conjunction ("AND" $\land$) of one or more disjunctions ("OR" $\lor$) of one or more literals, and governed by six context... |
For refresher, let's first remember ([Wikipedia](https://en.wikipedia.org/wiki/Conjunctive_normal_form)) that we can convert any Boolean expression into conjunctive normal form, which is defined as conjunction ("AND" $\land$) of one or more disjunctions ("OR" $\lor$) of one or more literals, and governed by six context... |
For refresher, let's first remember ([Wikipedia](https://en.wikipedia.org/wiki/Conjunctive_normal_form)) that we can convert any Boolean expression into conjunctive normal form, which is defined as conjunction ("AND" $\land$) of one or more disjunctions ("OR" $\lor$) of one or more literals, and governed by six context... |
How to prove that every clause that is implied by the input formula (learned or not) can be derived using resolution with weakening rule:
$\frac{C}
{C \vee D}$
($A$ clause $C$ is implied by $F$ if for all possible assignments $A$ it holds that $F[A]\implies C[A]$.) |
Resolution on weakening rule by derived clause |
|satisfiability|first-order-logic|propositional-logic|3-sat| |
I need to design a binary DFA to accept strings where the last three characters read are either "110", "101" or "011". <br>My brutal solution is:
<br>[![automata][1]][1]
----------
I need help either reducing this one or with a simpler solution. Thanks
[1]: https://i.stack.imgur.com/Aw0PH.png |
DFA that accepts strings ending with an even number of 1 in the last three characters ("110","101","011") |
|automata|finite-automata| |
{"Voters":[{"Id":150715,"DisplayName":"A. H."}],"DeleteType":1} |
I need to design a binary DFA to accept strings where the last three characters read are either "000", "110", "101" or "011". <br>My brutal solution is:
<br>[![automata][1]][1]
----------
I need help either reducing this one or with a simpler solution. Thanks
[1]: https://i.stack.imgur.com/Aw0PH.png |
DFA that accepts strings ending with an even number of 1 in the last three characters ("000","110","101","011") |
I need to design a binary DFA to accept strings where the last three characters read are either "000", "110", "101" or "011". <br>My brutal solution is: [![enter image description here][1]][1]
<br>
----------
I need help either reducing this one or with a simpler solution. Thanks
[1]: https://i.stack.imgu... |
There are some merging of states that you could make, but the minimal automaton is still quite big, I think:
- states with the same number of characters are not equivalent, because either one is final and not the other, or you could read one or two more letters to get into a final state for one and not the other.
-... |
In a fully connected Neural Network, each perceptron has it's bias term $b$ which is learnt. Often (example, in Linear/ Logistic Regression), when we don't want to treat this bias term explicitly, we add an extra "constant" feature $x_0 = 1$ to each training example. Can we show whether this will/ will not work in a Ne... |
Suppose we have collection of n sets $S_1, S_2, \dots, S_n$. Each set has a size of at least $k$. We know for sure that $\exists k$ sets where all of them contain the same $k$ elements; $|S_1 \cap S_2 \cap,\dots,\cap S_k| \geq k$. We don't know the sets nor the intersection elements. I would like to know if these quest... |
Is this intersection set problem NP-Hard? |
|complexity-theory|np-complete|np-hard|sets|polynomial-time| |
Yes, this particular method doesn't use the y.parent pointer. However, other methods rely on it. Consider finding `successor`:
1. Traverse to the right if x.right is present to find smallest key greater than x.key
2. If the right subtree of node x is empty and x has a successor y, then y is the lowest `ancestor` of x... |
I am trying to recreate the code for a paper. The paper describes a noising scheme like the following. z = f(x) +S(x)*epsilon
Where epsilon is the noise we call echo noise. It is because in the limiting case, the distribution of z and epsilon should be same. That is if we have a dataset {x_0, x_1, ....,x_i,.....,x... |
Help me with the pseudocode |
|algorithms|pseudocode| |
{"Voters":[{"Id":150715,"DisplayName":"A. H."}]} |
|satisfiability|correctness-proof|first-order-logic|propositional-logic|3-sat| |
Take numbers from 1 to 100. Put all of them in a binary search tree. Now, one of those 100 numbers is picked uniformly at random and given to us. We'd like to find it in the binary search tree. The tree should be constructed in a way that the expected number of comparisons in minimal. It's intuitive that a balanced tre... |
Prove that balanced binary search tree has lowest expected cost |
|optimization|binary-trees|binary-search-trees| |
Take numbers from 1 to 100. Put all of them in a binary search tree. Now, one of those 100 numbers is picked uniformly at random and given to us. We'd like to find it in the binary search tree. The tree should be constructed in a way that the expected number of comparisons in minimal. It's intuitive that a balanced tre... |
null |
null |
The cost for searching a node in a BST is the node's depth in the BST.
What you need to show is that the average depth is lower in a balanced BST than in any BST.
An informal way to see it is that if the BST is not balanced, then you could delete one of its leaf to put it in a lower depth.
Note that if the set... |
null |
Firstly, note the following claim:
**Claim**: Let $S$ be any set of $n$ elements. Let $B$ be any binary tree with $n$ empty nodes. Then, there exists a mapping of $S$ to the nodes of $B$ such that $B$ is a binary search tree of set $S$.
**Proof**: The claim follows since inorder traversal of the tree can be mapp... |
I am trying to recreate the code for a paper. The paper describes a noising scheme like the following. $z = f(x) +S(x) \cdot \epsilon$
Where $\epsilon$ is the noise we call echo noise. It is because in the limiting case, the distribution of $z$ and $\epsilon$ should be same. That is if we have a dataset $\{x_0, x_... |
Pseudocode for a noising scheme |
Naturality is sufficient.
An easy way is to use the Yoneda lemma, which gives the equivalence:
$$ a\times a\to a \equiv (\mathbb2 \to a ) \to a \equiv \mathbb2 $$
where $\mathbb2$ denotes the Boolean type and it is assumed that the arrow $a\times a\to a$ is a natural transformation.
We can adapt the proof of... |
I had a few functions that were written in C which I had to rewrite in assembly for aarch64. How do I go about setting unit tests for the functions. And what environment would I require to do the same. I have a rasberry pi and linux pc with me, would I be able to compile and run the aarch code on them
```
#include ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.