instruction
stringlengths
0
29.8k
⌀
null
In a bridge game, a deck of 52 cards (13 spades , 13 clubs, 13 diamonds, 13 spades) are dealt to 4 players (13 cards each) then game starts.Game session ends after 13 tricks each having 4 cards.There are 28561 possible non repeated 4 card groups. What is the best method of generating and storing all possible trick c...
Data structures and algorithms for bridge game play?
|algorithms|data-structures|combinatorics|
I have to solve system of linear algebraic equations $AX=B$, where $A$ is a two-dimensional matrix with all elements of main diagonal equal to zero. How to solve this problem? Iterational methods are not applied in this case. One way is [LU Decomposition][1] method with reordering rows of $A$ to get entries in th...
null
One subarray will have $0$ or $1$ element while the other will have $(n-1)$ elements; hence it is $O(n^2)$: $$t(n)=t(n-1)+t(0)+O(n)= O(n^2)$$
null
This is a [bipartite matching][1] problem, which has several known algorithms. As a bonus, you get a combinatorial criterion for when it is even possible (namely, Hall's theorem). Construct a bipartite graph with $n$ vertices on each side $x_i,y_j$. Connect $x_i$ to $y_j$ if $A_{ij} \neq 0$. A maximum matching in th...
I am interested in the stateless k-armed bandit problem, where an agent repeatedly chooses one of k independent arms, each with a different distribution of rewards, and tries to maximize its total reward. I read many papers about this subject, but I am still confused, as there are two types of solutions: A. It ha...
I am interested in the stateless k-armed bandit problem, where an agent repeatedly chooses one of k independent arms, each with a different distribution of rewards, and tries to maximize its total reward. I read many papers about this subject, but I am still confused, as there are two types of solutions: A. It ha...
null
The reasons for using the IO monad appear to be described in Braßel and Huch and Hanus, 2004, but I cannot find a clear reason given for using a list instead of a set. I guess it is so the list can be elaborated lazily. It seems that the approach described in the 2007 paper was unsatisfactory for some reason (I don'...
null
if the data is really a tree graph, the maybe Prüfer code?
null
I have following problem : given an integer array (maximum size 50000) i have to find the maximum X such that, X = a[p] ^ a[p+1] ^ ... ... ^ a[q] for some p,q (p<=q) Also i have to find the minimum value of X. I have tried this process , sum[i] = a[0] ^ a[1] ^ ... ... ^ a[i] for some i . i pre-calculated it i...
Finding Max/Min Consecutive XOR value
|algorithms|data-structures|algorithm-analysis|performance|
null
In general, the answer is no. If we put XOR-like restrictions on the out-going edges of a vertex, we can prove that finding a min-cut-max-flow is NP-Hard. The technique is to reduce 3-SAT to it. Let's assume there are $n$ variables $x_1, x_2, ..., x_n$ in the 3-SAT and $m$ clauses $c_1, c_2, ..., c_m$. We create a g...
In general, the answer is no. If we put XOR-like restrictions on the out-going edges of a vertex, we can prove that finding a min-cut-max-flow is NP-Hard. The technique is to reduce 3-SAT to it. Let's assume there are $n$ variables $x_1, x_2, ..., x_n$ in the 3-SAT and $m$ clauses $c_1, c_2, ..., c_m$. We create a g...
null
|recursion|functional-programming|
I saw in [this][1] video that computing clustering coefficient of a star graph using the following algorithm is $\theta(n^2)$ and for a clique it is $\theta(n^3)$. is that correct? def clustering_coefficient(G,v): neighbors = G[v].keys() if len(neighbors) == 1: return 0.0 links = 0.0 ...
computing clustring coefficient
|time-complexity|algorithm-analysis|
I saw in [this][1] video that computing clustering coefficient of central node in a star graph using the following algorithm is $\theta(n^2)$ and for a clique it is $\theta(n^3)$. is that correct? def clustering_coefficient(G,v): neighbors = G[v].keys() if len(neighbors) == 1: return 0.0 ...
null
I saw in [this][1] video that computing clustering coefficient of central node of a star graph using the following algorithm is $\theta(n^2)$ and for a clique it is $\theta(n^3)$. is that correct? def clustering_coefficient(G,v): neighbors = G[v].keys() if len(neighbors) == 1: return 0.0 ...
I saw in [this][1] video that computing clustering coefficient of central node of a star graph using the following algorithm is $\Theta(n^2)$ and for a clique it is $\Theta(n^3)$. is that correct? def clustering_coefficient(G,v): neighbors = G[v].keys() if len(neighbors) == 1: return 0.0 ...
Computing the clustering coefficient
|graphs|algorithm-analysis|runtime-analysis|
null
Using the Shortest-Seek-Time-First (SSTF) disk scheduling algorithm (where we select a request with a minimum seek time from the current head position), what happens if the requests in both directions from the current head position are equal? For example, if the head position is at 25, and the nearest positions are...
SSTF disk scheduling algorithm? What if lowest seek times are equal in either direction?
|algorithms|operating-systems|storage|
Well, those complexities depend on the data structure being used for storing the graph $G$. If an adjacency list is used, where for every vertex $v$ in the graph, its neighbors are stored in an array/linked list, then the above complexities are valid. Here's how: For the central node of the star graph, there are $n-...
Short answer: Depends on implementation. Long answer: Ties could be broken randomly, or some fixed direction might be preferred. A more common idea could be to select that position first which does not require the head to change direction (since changing direction could take more time). So suppose that the head has ...
my assumption:<br/> - we have an undirected graph with only positive edges<br/> - the edges are sorted alphabetically: <br/> &nbsp;&nbsp;&nbsp;&nbsp;fe. A-B, A-C, B-D <br/> &nbsp;&nbsp;&nbsp;&nbsp;and f.e. not C-A, D-B, A-B I do not understand, why we need the first loop (line 1) here. I executed the algorithm...
Bellman-Ford: shortest path
|shortest-path|
When we say that in random graph we add an edge with a certain fixed probability, what do we actually mean? For example if probability is 0.5, does that mean that we can just add two edges in a graph because 0.5+0.5=1.
Random graph model
|graphs|
In the random $G(n,p)$ model, each of the $\binom{n}{2}$ edges is added to the graph with probability $p$ *independently*. That means that if you consider any two edges, then both are in the graph with probability $p^2$, not $2p$.
my assumption:<br/> - we have an undirected graph with only positive edges<br/> - the edges are sorted alphabetically: <br/> &nbsp;&nbsp;&nbsp;&nbsp;e.g A-B, A-C, B-D <br/> &nbsp;&nbsp;&nbsp;&nbsp;and e.g not C-A, D-B, A-B I do not understand, why we need the first loop (line 1) here. I executed the algorithm ...
You're correct that there is always an ordering of the vertices for which this algorithm will converge in one iteration, namely the topological ordering given by the shortest-path spanning tree. However, in general the vertices won't be given to us in that order. Consider for example a path $(C,A),(A,B)$, where $C$ ...
my assumption:<br/> - we have an undirected graph with only positive edges<br/> - the edges are sorted alphabetically: <br/> &nbsp;&nbsp;&nbsp;&nbsp;e.g A-B, A-C, B-D <br/> &nbsp;&nbsp;&nbsp;&nbsp;and e.g not C-A, D-B, A-B I do not understand, why we need the first loop (line 1) here. I executed the algorithm ...
Here is why Strilanc's suggestion works for $\min$. Consider your array $\mathrm{sum}$, and suppose the minimum is achieved by $a_p,a_q$, where $p<q$. Either $a_p = a_q$ (in which case $a_p = a_{p+1}$), or $a_p = x0y$, $a_q = x1z$ for some $x,y,z$. Suppose $q > p+1$, and let $a_{p+1} = xbw$. If $b = 0$ then $a_p \oplus...
Suppose you wish to compute the random graph $G(n,p)$ that is the graph with $n$ vertices where each edge is added with probability $p.$ Suppose you have a coin that gives tails with probability $p$ and heads with probability $1-p.$ Then what you do you take $\{1,...,n\}$ to be the vertex set of your graph and f...
Your coin flips form a one-dimensional random walk $X_0,X_1,\ldots$ starting at $X_0 = 0$, with $X_{i+1} = X_i \pm 1$, each of the options with probability $1/2$. Now $H_i = |X_i|$ and so $H_i^2 = X_i^2$. It is easy to calculate $E[X_i^2] = i$ (this is just the variance), and so $E[H_i] \leq \sqrt{E[H_i^2]} = \sqrt{i}$...
null
**Edit:** My answer was based on assuming the code given as a pseudo-code, rather than a concrete Python example. For Python, the data structure is a dictionary (hash map) and so finding neighbors (the `in`) operation will in fact be $O(1)$ on average, giving $\Theta(n^2)$ overall complexity on *average* for both graph...
Short answer: Depends on implementation. Long answer: Ties could be broken randomly, or some fixed direction might be preferred. A popular strategy is to select that position first which does not require the head to change direction (since changing direction could take more time). So suppose that the head has moved ...
Sorting helps with $\max$ too. A little bit, at least. Clearly, maximum would be reached by $x \oplus \neg x$. So for each $x$ in `sum` do a binary search for $\neg x$. That's $O(n \log n)$ time, same as sorting, so that remains to be the complexity of the whole procedure.
Sorting helps with $\max$ too. A little bit, at least. Clearly, maximum would be reached by $x \oplus \neg x$. So for each $x = \text{sum}_i$ do a binary search for $\neg x$. That's $O(n \log n)$ time, same as sorting, so that remains to be the complexity of the whole procedure.
null
I have following problem : given an integer array (maximum size 50000) I have to find the maximum $X$ such that, $X = a_p \oplus a_{p+1} \oplus \dots \oplus a_q$ for some $p$, $q$ with $p \leq q$. Also I have to find the minimum value of $X$. I have tried this process, $\text{sum}_i = a_0 \oplus a_1 \oplus \dots ...
null
Given an integer array (maximum size 50000), I have to find the minimum and maximum $X$ such that $X = a_p \oplus a_{p+1} \oplus \dots \oplus a_q$ for some $p$, $q$ with $p \leq q$. I have tried this process: $\text{sum}_i = a_0 \oplus a_1 \oplus \dots \oplus a_i$ for all $i$. I pre-calculated it in $O(n)$ and then...
Finding maximum and minimum of consecutive XOR values
|algorithms|algorithm-analysis|performance|binary-arithmetic|arithmetic|
|algorithms|graphs|shortest-path|
|graphs|probability-theory|
my question is simple. Is it possible to use plants as a medium to store data? My opinion is: Possible, but we need to solve, how to distinguish 2 states. Duplication and CRC of stored DATA is quiet simple. Growing new plants is easiest possibility, but we need to create unit, which will take care about raid and ...
Is it possible to use plants as a medium to store data? By what data structure?
|data-structures|graphs|
In addition to what is said, which is correct, you can build a random graph $G(n,p)$ for $0 \leq p \leq 1$ as follows: Assume you have a set of vertices $V$ and empty edges $E$. For each $v$ in $V$: For each $u$ in $V$ (where $u > v$ with respect to some total order among the nodes of $V$): generate a uniform ...
What you propose sounds like it would be quite error laden, as plants are not necessarily independent, and those grown in the same area of the same species might share a common root system, so what you might consider redundancy is not a guarantee that your data will be preserved. I would also venture to say that it's ...
null
null
If $k$ is the bitsize of the integers, then you can compute the Max in $O(n k)$ time. Basically, the problem is, given $n$, $k$-bit integers $S_i$, find $i,j$ such that $S_i \oplus S_j$ is maximum. You treat each $S_i$ as a binary string (looking at the binary representation), and create a trie out of those strin...
null
I'm trying to practice myself with random algorithms. Lets call a CNF formula over n variables simple if it is either unsatisable or it has at least $\frac{2^n}{n^{10}}$ satisfying assignments. I would like your help with show a randomized algorithm for checking the satisfiability of simple formulas, that outpu...
randomized algorithm for checking the satisfiability of simple formulas, that outputs the correct answer with probability at least $\frac{2}{3}$
|complexity-theory|time-complexity|randomized-algorithms|
null
Your suggestion doesn't work. When the formula is unsatisfiable, your algorithm outputs the correct answer with probability $1/3$ only. Hint: If a formula has $2^n/n^{10}$ satisfying assignments, what's the probability that a random assignment is satisfying?
null
In an unweighted, undirected graph, where 2V>E, what is the fastest way to find all shortest paths in a graph? Can it be done in faster than Floyd-Warshall which is O(V<sup>3</sup>) but very fast per iteration?
What is the fastest algorithm for finding all shortest paths in a sparse graph?
|algorithms|graphs|shortest-path|
In an unweighted, undirected graph with $V$ vertices and $E$ edges such that $2V \gt E$, what is the fastest way to find all shortest paths in a graph? Can it be done in faster than Floyd-Warshall which is $O(V^3)$ but very fast per iteration?
There is [Johnson's algorithm][1], whose running time is $O(V^2\log V + VE)$. [1]: http://en.wikipedia.org/wiki/Johnson%27s_algorithm
As Yuval pointed out, there is the Johnson's algorithm (you need to assign a weight of 1 for each edge in the graph). But since this is an unweighted graph, you can do better in terms of time complexity. You could run a [Breadth First Search][1] (BFS) from every vertex $v$ in the graph. Each run of BFS gives you the...
Since this is an unweighted graph, you could run a [Breadth First Search][1] (BFS) from every vertex $v$ in the graph. Each run of BFS gives you the shortest distances (and paths) from the starting vertex to every other vertex. Time complexity for one BFS is $O(V + E) = O(V)$ since $E = O(V)$ in your sparse graph. Runn...
In an unweighted, undirected graph with $V$ vertices and $E$ edges such that $2V \gt E$, what is the fastest way to find all shortest paths in a graph? Can it be done in faster than Floyd-Warshall which is $O(V^3)$ but very fast per iteration? EDIT: How about if the graph is weighted?
Since this is an unweighted graph, you could run a [Breadth First Search][1] (BFS) from every vertex $v$ in the graph. Each run of BFS gives you the shortest distances (and paths) from the starting vertex to every other vertex. Time complexity for one BFS is $O(V + E) = O(V)$ since $E = O(V)$ in your sparse graph. Runn...
null
> Computer Networking: A Top Down Approach Featuring the Internet, Jim Kurose, Keith Ross Addison-Wesley 4nd edition , page -223. Also [here][1] slide 60 . RDT2.1 (Reliable data transfer) - Sender(s): state=ready; i=0; On rdt_send(d,m): if state=ready then { p=<s,d,...
RDT2.1 - does the Sender listener to "ack" even though state=ready?
|computer-networks|
From the code above, Yes. Regarding your second note. A sender will go to the busy state if it sends a message and there it will wait for an ACK. I can imagine that the reciver would send multiple ACK's only if there is some fault. Usually, such faults are not considered in the basic protocol description, but are...
null
INPUT: "an undirected, weighted graph (negative weights allowed)" Could someone give an example for an undirected graph with negative edges where Dijkstra's algorithm doesn't work? As far as i understood it only fails by directed graphs in case of negative edges.<br/> Am i right ?
Dijkstra's algorithm for undirected graphs with negative edges
|shortest-path|
Think about a "triangle"(3-clique): a graph $G(V,E)$ with three vertices $a,b,c$ and edges $(a,b),(b,c),(c,a)$. Assign cost $w_{a,b} = 1$, $w_{b,c} = 100$, $w_{c,a} = -100$. If we want to find the shortest path from $a$ to $b$, Dijikstra greedily chooses $c$ via edge $(a,c)$, which has cost one. However, the shortest p...
> Computer Networking: A Top Down Approach Featuring the Internet, Jim Kurose, Keith Ross Addison-Wesley 4nd edition , page -223. Also [here][1] slide 60 . RDT2.1 (Reliable data transfer) - Sender(s): state=ready; i=0; On rdt_send(d,m): if state=ready then { p=<s,d,...