instruction stringlengths 0 29.8k ⌀ |
|---|
There are several players at the end of the poker night with wins and losses, with zero sum. What is the optimal solution to settle the balance that minimize the total number of transactions (eg. if we consider a transaction as a venmo payment).
name | balance (N means how much net win, negative means lost)
... |
There are several players at the end of the poker night with wins and losses, with zero sum. What is the optimal solution to settle the balance that minimize the total number of transactions (eg. if we consider a transaction as a venmo payment).
name | balance (N means how much net win, negative means lost)
... |
null |
I have to prove whether a certain property is safety or liveliness. The property represents the absence of deadlock so I expected it to be a safety property from what I read online.
The issue is that I seem to show that it is both, but this is impossible as the only property that is both safety and liveliness wou... |
Safety VS. Liveliness Property |
|logic|model-checking|check-my-answer|linear-temporal-logic| |
null |
null |
{"Voters":[{"Id":79440,"DisplayName":"Nathaniel"},{"Id":755,"DisplayName":"D.W."}]} |
There are many ways to approach this problem, you could:
1. sort the list and then drop the first or last element based on which one isn't equal to a third item in the list (with index 1 ... n-2, where n is the size of the list)
2. you could have two pointers, one at the beginning (p1) and one at the end of the l... |
Compare the first two elements (1 comparison.)
If they are equal, find the different element among the remaining ones (n-2 comparisons).
If they are different, compare the third element to the first (1 comparison). If they differ, the different element is the first; otherwise the second.
So you conclude in eit... |
- Compare the first two elements (1 comparison.)
- If they are equal, find the different element among the remaining ones (n-2 comparisons).
- If they are different, compare the third element to the first (1 comparison). If they differ, the different element is the first; otherwise the second.
So you conclude ... |
- Compare the first two elements (1 comparison.)
- If they are equal, find the different element among the remaining ones (n-2 comparisons).
- If they are different, compare the third element to the first (1 comparison). If they differ, the different element is the first; otherwise the second.
So you conclude ... |
- Compare the first two elements (1 comparison.)
- If they are equal, find the different element among the remaining ones (n-2 comparisons).
- If they are different, compare the third element to the first (1 comparison). If they differ, the different element is the first; otherwise the second.
So you conclude ... |
- Compare the first two elements (1 comparison.)
- If they are equal, find the different element among the remaining ones (n-2 comparisons).
- If they are different, compare the third element to the first (1 comparison). If they differ, the different element is the first; otherwise the second.
So you conclude ... |
- Compare the first two elements (1 comparison.)
- If they are equal, find the different element among the remaining ones (n-2 comparisons).
- If they are different, compare the third element to the first (1 comparison). If they differ, the different element is the first; otherwise the second.
So you conclude ... |
- Compare the first two elements (1 comparison.)
- If they are equal, find the different element among the remaining ones (n-2 comparisons).
- If they are different, compare the third element to the first (1 comparison). If they differ, the different element is the first; otherwise the second.
So you conclude ... |
- Compare the first two elements (1 comparison.)
- If they are equal, find the different element among the remaining ones ($n-2$ comparisons).
- If they are different, compare the third element to the first ($1$ comparison). If they differ, the different element is the first; otherwise the second.
So you concl... |
- Compare the first two elements (1 comparison.)
- If they are equal, find the different element among the remaining ones ($n-2$ comparisons).
- If they are different, compare the third element to the first ($1$ comparison). If they differ, the different element is the first; otherwise the second.
So you concl... |
Let $\Sigma$ be an alphabet, and denote by $\mathrm{ind}(\varphi_M^{(k)})$ the index set (w.r.t some numbering) of the $k$-ary partial computable function $\varphi_M^{(k)} : (\Sigma^*)^k \rightarrow \Sigma^*$, which represents the $k$-ary proper function of the Turing machine $M$. Is it the case that $\mathrm{ind}(\var... |
In this question, I'm going to introduce a prime factorization algorithm which I'm working on as my personal project.
I may attach a Python code to introduce the algorithm. If it contravenes the rule please let me know, I will consider it editing as a pseudo-code or substitute it with some link.
import timeit... |
I'm taking a database systems course and we were presented for the following defenition for $3NF$ form:
> A relation R is in $3NF$ means:
> A nontriviral dependency $A_1,\dots,A_n\to B_1,\dots B_m$ can hold in $R$ only if
> $\{A_1,\dots,A_n\}$ is a key (either minimal or super) in $R$
> or
> for $1<= i <... |
Check whether a decomposition is in 3nf |
|database-theory|databases| |
In a database systems course, we have been presented with the following definition for third normal form (3NF):
> A relation $R$ is in 3NF means:
> a nontrivial dependency $A_1,\dots,A_n\to B_1,\dots B_m$ can hold in $R$ only if
> $\{A_1,\dots,A_n\}$ is a key (either minimal or super) in $R$
> or
> for $1 \l... |
I’d suggest running your algorithm and comparing its runtime to the trivial trial division algorithm. (Try dividing by 2, 3, followed by 6K-1 and 6K+1 until the square of the divisor exceeds the remaining number).
Try especially the behaviour for products of two or three large primes or for primes or numbers like 2... |
I’d suggest running your algorithm and comparing its runtime to the trivial trial division algorithm. (Try dividing by 2, 3, followed by 6K-1 and 6K+1 until the square of the divisor exceeds the remaining number).
Try especially the behaviour for products of two or three large primes or for primes or numbers like 2... |
The problem I am trying to solve is that there is an underlying undirected graph `G = (V, E)` with weights on the vertices, where the weight on vertex `v` is
denoted by `wv = d(v)` (the degree of the vertex). My goal is to find a vertex cover set `U` (a set where for every `e = (u, v)`, one of vertices `u, v` is in `U... |
How to show that any greedy algorithm gives a 2-approximation for the best min weighted vertex cover |
|algorithms|approximation|weighted-graphs|vertex-cover| |
I found the error on the safety proof.
> Let $\hat\sigma=\sigma[..i]$, this is a bad prefix for our property.
This is of course wrong. If the property is not satisfied, i.e., $\sigma \not\Vdash \mathsf{G}((P1E \wedge P2E) \rightarrow (\mathsf{F}\, (P1C \vee P2C)))$ then indeed there is as $i\geq 0$ such that $\... |
The problem I am trying to solve is that there is an underlying undirected graph `G = (V, E)` with weights on the vertices, where the weight on vertex `v` is
denoted by `wv = d(v)` (the degree of the vertex). My goal is to find a vertex cover set `U` (a set where for every `e = (u, v)`, one of vertices `u, v` is in `U... |
I had to re-read the question multiple times to understand what you wanted to do, but I think I finally understood.
To prove that any greedy algorithm returns a $2$-approximation is the same as showing that any vertex cover is a $2$-approximation (assuming that any greedy algorithm returns a vertex cover, which is n... |
I had to re-read the question multiple times to understand what you wanted to do, but I think I finally understood.
To prove that any greedy algorithm returns a $2$-approximation is the same as showing that any vertex cover is a $2$-approximation (assuming that any greedy algorithm returns a vertex cover, which is n... |
null |
In depth first search each vertex can be associated with a discovery time and a finish time. I am reading the following implementation of topological sort in terms of depth first search
```
TOPOLOGICAL-SORT(G)
1 call DFS(G) to compute finish times for each vertex
2 as each vertex is finished, insert it to the fro... |
Why compute finish time in topological sort |
|algorithms|graph-traversal|depth-first-search|topological-ordering| |
In depth first search each vertex can be associated with a discovery time and a finish time. I am reading the following implementation of topological sort in terms of depth first search
```
TOPOLOGICAL-SORT(G)
1 call DFS(G) to compute finish times for each vertex
2 as each vertex is finished, insert it to the fro... |
I am working on a sparse autoencoder but Andrew NG notes are hard to understand. My question is about the following equation: Loss Function. How sparsity term inactives the hidden units because whatever the value of KL divergence is, it still adds up in the actual loss and makes the loss value bigger.
I am expecting... |
How sparsity term in loss function for sparse autoencoder is making hidden units inactive? |
|machine-learning|neural-networks|weighted-graphs|python|sparse-matrices| |
You are right that the finishing time is not necessary for the algorithm to work. Once the vertex is completely explored (all its neighbors are visited) then you can just marked the vertex as explored and then add it to the linked list. In a way, the finish time will be implied by the order of the vertices in the list.... |
null |
null |
Assume that I have designed an algorithm A, which runs two sub-methods: M1 and M2.
M1 has a O($n$) expected time complexity.
M2 has a O($n^2$) time complexity.
Clearly A uses O($n + n^2$) = O($n^2$) time. Since $n^2$ > $n$, in terms of time complexity, should A be described as having an **expected** time compl... |
Algorithms that depend on expected time and "regular" time complexities |
|time-complexity| |
I am wondering, what is the top type, $\top$, in JavaScript? The diagrams at [MDN][1] make it look as if 'null' is a top type, but [wikipedia's entry for top type][2] indicate that it is Object in JS, which makes more sense. Am I misreading the MDN article?
[1]: https://developer.mozilla.org/en-US/docs/Learn/Jav... |
Top type in JavaScript? |
|type-theory|type-checking| |
I'm assuming that $M_1$ is a randomized algorithm and that the expectation is taken over the random bits.
If you just say that $A$ has time complexity $O(n^2)$, the default assumption is that your are talking about *worst-case* time.
Then it would be incorrect to say that $A$ runs in time $O(n^2)$ since, (without ... |
i got this question in a theory of computation quiz "give pda for a^(n) b^(2n) c^(2n) d^(n)"
i am arguing that there is no pda for that question but our ta says that we can push 5x to the stack then pop x each time we read a b or c or d. i am arguing that doesn't guarantee count because we might get only "d"s wh... |
PushDown automata for a^(n) b^(2n) c^(2n) d^(n) |
|automata|context-free|pushdown-automata| |
If there would be an efficient quantum computer algorithm for $NP$-complete problems, then the $P$ vs. $NP$ problem would be still unsolved. But if one can show, that there is no quantum computer to solve an $NP$-hard problem
in polynomial time, then $P$ is unequal $NP$, because $P\subseteq BQP$.
It is unlikely, th... |
If this is a recursive algorithm, and you want it fast: Calculate the exact runtime for both algorithms for small n. Then algorithm A doesn't recursively call A for smaller n, but the faster of algorithm A and algorithm B. And you will have a base case for small n that is calculated without recursion. Consider that one... |
I'm assuming that $M_1$ is a randomized algorithm and that the expectation is taken over the random bits.
If you just say that $A$ has time complexity $O(n^2)$, the default assumption is that your are talking about *worst-case* time.
Then it would be incorrect to say that $A$ runs in time $O(n^2)$ since (without f... |
Try these: Sorted. Reverse sorted. Two sorted halves. One half ascending, one half descending. Sorted with 0.1%, 1%, 10% random changes. Random. All values equal, 99% equal, 50% equal. Two different values only.
Unless you are 100% sure that one of these case cannot happen (and you are never 100% sure), all of thes... |
I guess the algorithm you presented is from CLRS. You are right that the finishing time is not necessary for the algorithm to work. Once the vertex is completely explored (all its neighbors are visited) then you can just marked the vertex as explored and then add it to the linked list. In a way, the finish time will be... |
Denote $\text{post}(v)$ (for *postvisit number*) its finish time. Then for any directed graph $G = (V, E)$, the two following properties are equivalent:
1. $G$ contains a cycle;
2. there exists an edge $(u, v)\in E$ such that $\text{post}(u)<\text{post}(v)$.
So the postvisit ordering can be used to decide the ex... |
You are right that the suggestion of the TA does not work. Using that approach one will accept $\{\; a^n b^i c^k d^\ell \mid 5n = i+j+\ell \;\}$. We can force the PDA to make $i$ and $j$ even, but that will not help much.
Of course this does not prove that there is no PDA for the language $K = \{\;a^nb^{2n}c^{2n}d^n... |
I'm currently studying virtualization and while looking at hipervisors I realized that bare metal hipervisors are quite similar to operating systems.
So while from an application standpoint they are different, can an operating system theoretically be viewed as bare metal hipervisor? |
Difference between bare metal hipervisor and operating system |
|operating-systems| |
The [Kind programming language](https://github.com/Kindelia/Kind) has a sufficiently powerful type system to support proving theorems like in Lean, Coq, Idris, or Agda. I've seen it said that Kind has an *even more* powerful type system that goes beyond what these other languages support. Since Kind is a work-in-progr... |
What types can be written in Kind but not Lean? |
|type-theory|dependent-types| |
I think the commenters are gracious for not having down-voted my question. It seemed I was lazy. But I was lazy no more. The last two days I have put my head into this matter and I just finished the implementation and verified it against the textbook example.
Of all the texts and presentations I could find I found t... |
**Problem statement**
We're given a directed **simple** **acyclic** graph with weighted vertices. Find an edge $e$ such that reversing it would create a strongly connected component (SCC) whose *price* is maximal. The *price* of an SCC is defined to be the sum of the weights of its vertices.
In the example below,... |
Reverse one edge to make the most expansive strongly connected component |
|algorithms|graphs|dag|connected-components| |
What problems belong in NSPACE(n^2) and DSPACE(n^2) class? Examples? |
NSPACE(n^2) and DSPACE(n^2) class problems |
|complexity-theory|space-complexity| |
**Problem statement**
We're given a directed **simple** **acyclic** graph with weighted vertices. Find an edge $e$ such that reversing it would create a strongly connected component (SCC) whose *price* is maximal. The *price* of an SCC is defined to be the sum of the weights of its vertices.
In the example below,... |
As I understand, all modern CPUs perform register renaming: given a sequence of instructions to interpret, they check which registers these instructions use, detect patterns where a register's previous value is overwritten, and then map the instruction sequence so that each instruction's "architectural" register is map... |
How efficient is register renaming? |
|computer-architecture|cpu|cpu-pipelines| |
The empty problem $\emptyset$ (the problem whose answer is always *false*) is in both $\mathsf{NSPACE}(n^2)$ and $\mathsf{DSPACE}(n^2)$.
(If you are unsatisfied with this answer, then you should be more precise in your question). |
Remapping registers costs zero time. It can be done easily while moving an instruction into the dispatch queue, so whatever time it takes is hidden. For example "R3 = R7 + R11", we lookup that R7 is currently held in RR65, R11 is currently held in RR43, RR113 is free so from now on RR113 will hold R3, and the instructi... |
I'm interested in testing some Traveling Salesperson (TSP) greedy approximation algorithms for finding the shortest Hamiltonian path for very large graphs. Assume I can construct whatever graph I choose; how could I build a graph with a known shortest Hamiltonian path in polynomial time _with edge distances that satis... |
The dependency `C, D -> B` does not hold in `R2` since the three attributes are not present in it and that dependency cannot be derived by taking the closure of the union of the the projection of the dependencies over `R1` and `R2`.
So the decomposition is in 3NF (actually it is in BCNF), but the dependency `C, D ->... |
I'm interested in testing some Traveling Salesperson (TSP) greedy approximation algorithms for finding the shortest Hamiltonian path for very large graphs. Assume I can construct whatever graph I choose; how could I build a graph with a known shortest Hamiltonian path in polynomial time _with edge distances that satis... |
null |
null |
I think you're right to notice this strong connection. At a high level, there is a strong similarity between a hypervisor and a [microkernel](https://en.wikipedia.org/wiki/Microkernel) operating system.
There are also some differences. Hypervisors are specialized to supporting virtual machines. Conventional opera... |
null |
We have a set of people, and each person has a list of wished items (not unique, they could want multiple copies of each item). We have an inventory of items that we want to assign to the people. We want to maximize the number of people who receive all the items on their list. The inventory may not have enough items to... |
Assign items from inventory to people maxmizing the number of satisfied people |
|algorithms|graphs|matching|bipartite-matching|assignment-problem| |
In the special case where the inventory doesn't have multiple copies of any object, this is the [set packing problem](https://en.wikipedia.org/wiki/Set_packing). It is NP-hard, so you shouldn't expect any efficient solution. Since your problem is a generalization of a NP-hard problem, it too is NP-hard, so not solvab... |
null |
null |
null |
null |
I think the commenters are gracious for not having down-voted my question. It seemed I was lazy. But I was lazy no more. The last two days I have put my head into this matter and I just finished the implementation and verified it against the textbook example.
Of all the texts and presentations I could find I found t... |
null |
If you wanted a definition of an "operating system" it could be something like: a system of software that runs on a machine and manages its resources, providing an environment for other software to run within.
(Actual software packages that are marketed as operating systems would almost invariably contain a lot of a... |
null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.