instruction stringlengths 0 29.8k ⌀ |
|---|
import numpy as np
import networkx as nx
from scipy.spatial import Voronoi,voronoi_plot_2d
import matplotlib.pyplot as plt
def voronoi_to_networkx(points):
# Calcular el diagrama de Voronoi
vor = Voronoi(points)
G = nx.Graph()
# Agregamos una arista para cada borde que co... |
import numpy as np
import networkx as nx
from scipy.spatial import Voronoi,voronoi_plot_2d
import matplotlib.pyplot as plt
def voronoi_to_networkx(points):
# Calcular el diagrama de Voronoi
vor = Voronoi(points)
G = nx.Graph()
# Agregamos una arista para cada borde qu... |
In a personal project of mine, I have been faced with the following problem. I have an $n \times n$ matrix $T$ where an entry $t_{ij} \geq 0$ denotes an arbitrary metric between two points $i$ and $j$ in the 2D Euclidean space.
What I would like to do is create a graph $G=(V,A)$ which can approximate matrix $T$ wher... |
null |
The algorithm consists of converting a Voronoi diagram, which is a partitioning of a plane into regions based on the distance to points in a specific subset of the plane, into a weighted graph represented by a networkx object in Python.
The input to the algorithm is a list of points in two dimensions. The Voronoi di... |
I don't understand what "merge all $\log n + 1$ arrays together, simultaneously" means.
The trivial algorithm that iteratively checks all the minima $m_1, m_2, \dots$ of the sub-arrays to find $j = \arg_{i=1, \dots, \log n +1} \min m_i$, adds $m_j$ to the final sorted array, and deletes $m_j$ from the $j$-th sub-arra... |
**Does the Linz Ĥ applied to ⟨Ĥ⟩ correctly transition to its final reject state?**
A Simulating Halt Decider (SHD) computes the mapping from its input to its own accept or reject state based on whether or not the pure simulation of its simulated input could reach its own final state in a finite number of simulated s... |
Your algorithm works. The main concept here are tree and cycle.
#### it is possible iff no cycles or one cycle
**Claim**: Let $G$ be an undirected connected graph. $G$ can be turned into a directed graph with in-degree at most $1$ <!-- iff $G$ is a tree or a tree plus one edge --> iff $G$ has no cycles or exactl... |
I was thinking what if you just started with the node with lowest non-zero degree $u$ (only count undirected edges) and picked random edge that is connected to that and direct that inwards. EX: undirected edge $uv \to (v,u)$. Then repeat, ignoring nodes that have reached the at-most-one limit. At the end, you check to ... |
|algorithms|graphs|directed-graphs| |
If you write a banking system, you will have entities representing users, accounts, transactions, balances, money, … If you write a game, you will have entities representing players, levels, maps, enemies, NPCs, weapons, vehicles, … If you write a media player, you will have entities representing albums, tracks, artist... |
Your algorithm works. The main concept here are tree and cycle.
#### it is possible iff no cycles or one cycle
**Claim**: Let $G$ be an undirected connected graph. $G$ can be turned into a directed graph with in-degree at most $1$ <!-- iff $G$ is a tree or a tree plus one edge --> iff $G$ has no cycles or exactl... |
Suppose you have to use a data type multiple times in multiple functions ,one way is to use the primitive data types again and again ,Other way is to use type synonyms to gove the desirred name to the primitive type.That's ehere the idea of custom type comes in to give a name to a data type composed of multiple primit... |
The exact version of your problem, where the distances are known exactly and the goal is to exactly match those distances, is known as the [distance geometry](https://en.wikipedia.org/wiki/Distance_geometry) problem. The approximate version, as you formulate it, seems similar to the [multidimensional scaling](https://... |
null |
Let's suppose we are given the following inequalities:
```
3x + 7y <= 71
4x + 9y <= 21
...
```
and so on, in the above format. The coefficients and the value generated (71,21 ...) would be positive, and x and y would also be positive. The input would be inputted as follows:
```
3 7 71
4 3 18
...
```
a... |
Linear Optimization With Two Variables, given starting Values |
|optimization| |
Apart from their more complex structure, [Y-fast](https://en.wikipedia.org/wiki/Y-fast_trie) and [X-fast](https://en.wikipedia.org/wiki/X-fast_trie) trie assumes that data to be stored are integers, while balanced [BSTs](https://en.wikipedia.org/wiki/Binary_search_tree) only assumes that data be from some ordered unive... |
null |
This variant of #Positive 2-SAT is defined as follows :
We are given a set of variables :
**(a,b,c,d,e)**
we can form our 2-literal clauses from these set of variables but we want the input in this variant such that for example if we are given a clause (a,e) then this input must contain every possible 2-liter... |
Is this variant of #Positive 2-SAT #P-complete? |
|complexity-theory|counting| |
|complexity-theory| |
This variant of #Positive 2-SAT is defined as follows :
We are given a set of variables :
**(a,b,c,d,e)**
we can form our 2-literal clauses from these set of variables but we want the input in this variant such that for example if we are given a clause (a,e) then this input must contain every possible 2-liter... |
Consider a set of $N$ vectors (each of Length $L$) with positive integer as elements. Given a target vector $T$ of length $L$.
Objective: Using the given set of vectors (by addition or subtraction) reduce $T$ to the form $T'$ such that:
1. all entries in $T'$ are either 0 or 1.
2. the first entry of $T'$ is 0.
... |
How do we approach this variant of Gaussian Elimination problem |
|algorithms| |
I know that finding the optimal solution to One Way TSP (TSP but the salesman does not have to return to his original city) is NP-Hard, but is it NP-Complete? I ask this because I recently found a solution to Open TSP but can't find a good resource to tell me whether or not Open TSP is NP-Complete. |
I know that finding the optimal solution to One Way TSP (TSP but the salesman does not have to return to his original city) is NP-Hard, but is it NP-Complete? I ask this because I recently found a solution to Open TSP but can't find a good resource to tell me whether or not One Way TSP is NP-Complete. |
For the number of a's to be unequal to the number of b's, either they are more a's or b's. I drew a PDA that reflects this:
[![PDA that checks numbers of a's != number of b's][1]][1]
[1]: https://i.stack.imgur.com/NSiFw.png
Eg for abbab:
Step 1) Starting at S0: read in no input, pop nothing from the sta... |
For the number of a's to be unequal to the number of b's, either they are more a's or b's. |
null |
I am trying to solve a problem to show equivalence between two regular expressions, and simplifying one of them I got $R.L^* + L^*$ in the end which I am not sure how to simplify further.
I want to equate it to $R + L^*$. Is this equivalence correct or is there a way to derive it? |
Is it true that $R.L^* + L^* = R + L^*$? |
|regular-languages|regular-expressions| |
Regardless of whether we can use each vector more than once, we can always create an instance in which all solutions use each vector at most once and only subtractions are possible.
Indeed, we can append $N$ additional entries $x_1, \dots, x_N$ to each vector. The generic $i$-th input vector has all these entries se... |
Regardless of whether we can use each vector more than once, we can always restrict the solutions of an arbitrary instance to those that use each vector at most once and perform only subtractions.
Indeed, we can append $N$ additional entries $x_1, \dots, x_N$ to each vector. The generic $i$-th input vector has all t... |
That's false in general. Pick $R = a$ and $L=b$. The word $ab$ is in the language defined by $RL^* + L$ but not the language of $R+L^*$.
It might be true for your specific choice of $R$ and $L$. |
Regardless of whether we can use each vector more than once, we can always restrict the solutions of an arbitrary instance to those that use each vector at most once and perform only subtractions.
Indeed, we can append $N$ additional entries $x_1, \dots, x_N$ to each vector. The generic $i$-th input vector has all t... |
Given string P with length n, and a function A on P [n] --> [n] that does the following:
For every 1 <= k <= n
A on P [k] = { the maximum index i such that P[1...i] = P[k...k+i-1]
Write an algorithm that's optimal as possible that given string P calculates the value of A on P [k] for every 1<= k <= n
|
Pattern Matching Variant Problem |
|matching| |
null |
Ask yourself this: what do you mean by *the same state*? In particular, why do your two $B$ states need to be the *same* state and what value does that give you over treating them as two separate states?
For a more thorough answer: consider the formal definition of the DFA, which includes the transition function $\d... |
You can turn a lot of consensus algorithms that utilize a "leader" into one that takes only O(n) message complexity in the optimistic case, by sending every message in that iteration to the leader, who then broadcasts your message to everyone. (PBFT should fall into this category, except for the view change). Assuming ... |
null |
That's false in general. Pick $R = a$ and $L=b$. The word $ab$ is in the language defined by $RL^* + L$ but not in the language of $R+L^*$.
It might be true for your specific choice of $R$ and $L$. |
while solving some questions about network flow I was wondering about the following statement:
> Given a network flow (a graph $G=(V,E)$ with a source $s \in V$ and sink $t \neq s \in V$) > and an arbitrary vertex $v \in V$, how can we find if the vertex $v$ belongs to any minimum cut ?
My attempt first was: tryi... |
Network flow - properties of a vertex that belong to any minimal cut |
|network-flow|minimum-cuts|ford-fulkerson| |
Let's assume, I have a grayscale image that every pixel represented with 8 bits. I want to quantize (decrease [color depth][1]) the image into 2 bits. Hence, I need a function as $f:A\rightarrow B$ where $A\in \left[0,255\right]$ and $B \in \left[0,3\right]$. Simplest way to define function $f$ is
$$
f(x) =
\begi... |
Best function to preserve information after decreasing color depth? |
|information-theory|colorings| |
while solving some questions about network flow I was wondering about the following statement:
> Given a network flow (a graph $G=(V,E)$ with a source $s \in V$ and sink $t \neq s \in V$) > and an arbitrary vertex $v \in V$, how can we find if the vertex $v$ belongs to the group S in any minimum cut S-T ?
My atte... |
null |
I am figuring out separation logic and trying to run simple examples in CVC5 smt solver. I am missing some core understanding of how pointers and values are treated there and I don't know where to look for more information.
I am sorry for the long snippets, but they are very simple.
## First query
```lisp
... |
What is the difference in heap configurations? Separation logic with CVC5 SMT solver |
|logic|smt-solvers| |
I recently learnt that a subset of a regular set may not be regular. This is causing me confusion as I imagined if a set is regular then every string longer than $p$ can be pumped in the language. So does a non-regular subset have strings only length $<p$? But if they have length $<p$, can't they be trivially pumped? |
Does pumping lemma not apply for every 'long enough' string in the language? |
|computability|regular-languages|finite-automata|pumping-lemma| |
Being a subset of a regular language does not have to be based on the length of the strings. It is about how the subset is constructed e.g., properties of the strings. I assume that by now you already know that the language $L_1$ containing strings with equal numbers of 1 and 0 is not regular. Notice that this is a sub... |
null |
Being a subset of a regular language does not have to be based on the length of the strings. It can constructed based on other properties of the strings.
I assume that by now you already know that the language $L_1$ containing strings with equal numbers of 1 and 0 is not regular. Notice that this is a subset of the... |
Consider this language:
$w=\{xy \mid x=\{a,b\}^*, y=x^R \text{ or } y=x\}$
I know that these languages are non-regular separately:
$w=\{xy \mid x=\{a,b\}^*, y=x^R\}$
$w=\{xy \mid x=\{a,b\}^*, y=x\}$
But what about their union? |
Regularity or irregularity of union of two languages |
|regular-languages| |
Regularity or non-regularity of union of two languages |
Suppose we have a metric space $(X,d)$ and we call $r$ to be a root vertex and then there are $n$ clients(i.e. $n$ vertices/nodes) who need packages delivered to them from $r$. The $i$th client demands a package of weight $w_i$ and is $d(r,i)$ distance away. Two clients $i,j$ are $d(i,j)$ distance away. Initially, all ... |
Designing Shortest Route |
|algorithms|optimization|combinatorics|approximation|linear-programming| |
It can be solved in polynomial time, and thus is unlikely to be #P-complete. Every such formula has the form
$$\varphi = \bigwedge_{j=1}^{k} \bigwedge_{i=1}^{a_j-1} (x_i \lor x_{a_j})$$
where $a_1,\dots,a_k$ is some sequence of variable indices and the variables are $x_1,\dots,x_n$. Let's assume (without loss o... |
Is pumping lemma not applicable for every 'long enough' string in the language? |
null |
Being a subset of a regular language does not have to be based on the length of the strings. It can be constructed based on other properties of the strings.
I assume that by now you already know that the language $L_1$ containing strings with equal numbers of 1 and 0 is not regular. Notice that this is a subset of ... |
Suppose towards a contradiction that $w$ is regular, let $p$ be its pumping length, and consider the word: $a^pba^pb \in w$.
By the pumping lemma, there is some $k \ge 1$ such that $a^{p + ik}b a^p b \in w$ for all choices of an integer $i \ge -1$. Choosing $i=-1$ we obtain $a^{p-k}b a^p b \in w$. This is a contradi... |
Consider this language:
$K=\{xy \mid x=\{a,b\}^*, y=x^R \text{ or } y=x\}$
I know that these languages are non-regular separately:
$K_1=\{xy \mid x=\{a,b\}^*, y=x^R\}$
$K_2=\{xy \mid x=\{a,b\}^*, y=x\}$
But what about their union? |
null |
In [this][2] youtube video, the instructor explained some basic code in RISC-V assembly, but i didn't understand why in the first line, he is shifting i by 3. Why do we have to multiply it by 8??
I feel like it has something to do with the fact that LOAD IMMEDIATE operations can load values up to 12 bits only, b... |
Why do we shift by three in RISC-V loops? |
|assembly| |
null |
There exist an O(n^2) solution for the given problem. Let prefixlen be an n×n array and result be stored in an array res of length n.
res[k]=0 implies that there is no longest prefix
that matches the substring p[k]..p[k+i-1].
Here p is taken as zero indexed.
```
for k from 0 to n-1
res[k]=0
for i from 0 t... |
There exist an **O**(n<sup>2</sup>) solution for the given problem. Let prefixlen be an n×n array and result be stored in an array res of length n.
res[k]=0 implies that there is no longest prefix
that matches the substring p[k]..p[k+i-1].
Here p is taken as zero indexed.
```
for k from 0 to n-1
res[k]=0
... |
I am figuring out separation logic and trying to run simple examples in CVC5 smt solver. I am missing some core understanding of how pointers and values are treated there and I don't know where to look for more information.
I am sorry for the long snippets, but they are very simple.
## First query
```lisp
... |
while solving some questions about network flow I was wondering about the following statement:
> Given a network flow (a graph $G=(V,E)$ with a source $s \in V$ and sink $t \neq s \in V$) > and an arbitrary vertex $v \in V$, how can we find if the vertex $v$ belongs to any minimum cut?
My attempt first was: tryin... |
Since you haven't provided any context of the code, we can just make assumptions.
**Assumption:** *save* is an 8-byte(or 64-bit) integer array.
**address of save[i] in memory** is equivalent to writing **base_address(save) + i * size_of_unit_element_of(save)**
Hence, to compute the effective address of save[i]... |
while solving some questions about network flow I was wondering about the following statement:
> Given a network flow (a graph $G=(V,E)$ with a source $s \in V$ and sink $t \neq s \in V$) > and an arbitrary vertex $v \in V$, how can we find if the vertex $v$ belongs to any minimum cut?
My attempt first was: tryin... |
null |
How to design Push Down Automata for the language that has equal number of as and b's where n>=1
I got how to do it for n>=O, not able to get it for n>=1 |
PDA for equal number of as and b's where n>=1 |
|untagged| |
null |
The intersection of a context-free language and a regular language is also context-free, and this can be shown using the same Cartesian-product-machine construction used to show the intersection of two regular languages is also regular. This construction gives you a way of finding the PDA for the intersection of a cont... |
Take your "one way" problem. Add another city X, make the distance from start to X = 0, make the distance from X to any other city d which is longer than the sum of all other distances, then solve the original TSP for this instance.
In the solution, X obviously must have two neighbours. One neighbour must be the st... |
I was reading this question on CS stack exchange called [How important is initial state for local search optimisation?][1]
I would like to extend it with the following example:
I have been reading about optimisation techniques and noticed that if a random initial state is provided to a genetic algorithm, it may s... |
Is there an optimisation algorithm that does not require a good initial solution? |
|optimization|heuristics| |
Obviously you could pick the smallest number from the k arrays and remove it from its array, which is trivial to do in k steps, multiplied by the number of array elements.
Instead you split the array into pairs of two arrays, and find the smaller of each group, then you split the groups into pairs, each including 4... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.