instruction stringlengths 0 29.8k ⌀ |
|---|
a formulation on an example:
let's have on a grid:
- a position of a bee queen **Q** (source node),
- a set of positions of free cells to lay an egg **E** (destination nodes),
- and a set of positions with worker bees **W** (moveable obstacles).
the queen and workers can move to 4 orthogonally neighboring ce... |
This remains a reachability problem, but now with a larger statespace.
The state of the system is the location of the queen and of all the workers. You have a transition from state $s$ to state $t$ if $t$ can be reached from $s$ in a single step (i.e., the queen moves one step, or one worker moves one step). The ... |
null |
find shortest path from single source to multiple destinations with obstacles which you can move |
null |
Here is a problem inspired by the game [Across the Obelisk](https://store.steampowered.com/app/1385380/Across_the_Obelisk/).
4 players have decks of cards. Each card has an integer value between 0-9 on it. The decks can be any size, and there's no other restriction on the card values - each possible card-value can ... |
Calculate odds that cards drawn from deck sum to at least some number ("Across the Obelisk" problem) |
|algorithms|computer-games| |
Here's a solution I came up with that's $O(PD + PV\log{P})$, where
* $D$ = The size of the largest deck
* $P$ = The number of players _(4 in the original problem)_
* $V$ = The max card-value _(9 in the original problem)_
---
The main ideas of this algorithm are:
* We can treat any deck, no matter how la... |
null |
I recently was constructing boolean logic for all sorts of examples from Morris Mano's "Digital Logic and Circuit Design".
I noticed that it is possible to construct a boolean logic wrt the inputs which depends on the current state. My question is that is it possible to construct a boolean logic which depend on the pr... |
Boolean Logic when one component switches from 0 to 1 |
|logic|boolean-algebra| |
null |
If we want to build a circuit that depends on previous states, the way we do that is to keep a copy of the previous state. That way, it is part of the current state. Indeed, the circuit can only depend on the input and current state; it can't depend on past information that hasn't been stored in the current state. T... |
Designing pure functions (i.e. output depends only on input) is called *combinational logic*, and designing stateful logic (i.e. a finite state machine) is called *sequential logic*. If you're working your way through Mano's book, I promise you will get to it.
The traditional way to design a basic sequential circuit... |
Designing pure functions (i.e. output depends only on input) is called *combinational logic*, and designing stateful logic (i.e. a finite state machine) is called *sequential logic*. If you're working your way through Mano's book, I promise you will get to it.
The traditional way to design a basic sequential circuit... |
Problem is to decide if it is possible to partition a given array **nums** into **k** partitions. I've written a brute force backtracking algorithm. How do we analyse this algorithm to calculate average runtime (average over all possible inputs -input may be such that it ends up "back-tracking" multiple times or possib... |
How to find average time complexity of backtracking algorithm? |
|time-complexity|backtracking| |
Problem is to decide if it is possible to partition a given array **nums** into **k** partitions. I've written a brute force backtracking algorithm. How do we analyse this algorithm to calculate average runtime (average over all possible inputs -input may be such that it ends up "back-tracking" multiple times or possib... |
Problem is to decide if it is possible to partition a given array **nums** into **k** partitions. I've written a brute force backtracking algorithm. How do we analyse this algorithm to calculate average runtime (average over all possible inputs -input may be such that it ends up "back-tracking" multiple times or possib... |
null |
First run your algorithm, count the iterations. Check how it varies with different inputs. Get some idea about the runtime.
Unless you have a good counter argument, backtracking tends to be exponential. However, backtracking will also tend to exclude huge numbers of cases if done right and the actual execution time... |
null |
I have system of two polynomial two variables, second order; monomials are {${1,x,y,x^2,xy,y^2}$}
I want find special systems of polynomials: two or more roots in specified range, two root close to each other, roots on boundary search range, etc.<br>
I can set one root to specified position by setting first term of p... |
Hill climbing method searching special polynomial equations |
|algorithms|optimization|search-algorithms|numerical-algorithms| |
null |
If I understand correctly, you want to build two quadratic bivariate polynomials such that the roots of the system they form fulfill some predefined conditions.
Geometrically, this corresponds to the intersection of two conics, which generally come in fours. Consider four arbitrary point P, Q, R, S. They define two ... |
If I understand correctly, the language is $\{0,1\}^* . \{010\} . \{0,1\}^*$ (where $.$ is concatenation of languages). Then the first regular expression, i.e., $(0+1)^*(010)(0+1)^*$, is correct.
The second one describes different language. The iteration of the expression (i.e., the outer parentheses) would match th... |
The "standard" example that shows that the NFA to DFA construction is exponential in size also works for reversal.
The DFA for $\{0,1\}^*1\{0,1\}^n$, the $n+1$-st symbol from the right is $1$, must have an exponential number of states as it has to recall all positions with $1$, whereas its reversal $\{0,1\}^n 1\{0,1... |
If I understand correctly, you want to build two quadratic bivariate polynomials such that the roots of the system they form fulfill some predefined conditions.
Geometrically, this corresponds to the intersection of two conics, which generally come in fours. Consider four arbitrary point P, Q, R, S. They define two ... |
Seems mimimal to me.
You can actually prove that the DFA is minimal by applying the [Myhill-Nerode][1] theorem. Two states $p$ and $q$ can not be merged if they can be "distinguished" in the sense that there is a string $w$ such that from exactly one on the two states $w$ leads to a final state. Here you can easily ... |
If I understand correctly, you want to build two quadratic bivariate polynomials such that the roots of the system they form fulfill some predefined conditions.
Geometrically, this corresponds to the intersection of two conics, which generally come in fours. Consider four arbitrary point P, Q, R, S. They define two ... |
For a simple solution, take the difference between pairs of successive frames. There will be a significant difference where there is motion.
When the person is moving, motion will be detected essentially in the middle of the screen. When the camera is moving, the whole frame will be affected.
[ would be of linear order O(M×N). |
If there are N numbers, M is the number of bits in the longest number, and you have enough memory available to hold 2 copies of the data, a [radix sort](https://en.wikipedia.org/wiki/Radix_sort) would be of linear order O(M×N). |
null |
It's not enough yet, because you haven't described how to sort in $o(n \log n)$ time -- in particular, you haven't described how to do the swaps in $o(n \log n)$ time. But yes, if you could figure out how to do that, then that *would* be enough. |
Let $P$ be a indexable set(array) of points in $\mathbb{R}^3$ s.t. $P = \{p_0,p_1,p_2,...,p_n\}, p_i \in\mathbb{R}^3$.
I want to sort $P$ so that every 4 consecutive points forms a non-coplanar tetrahedra/3D-simplex/triangular pyramid (whatever you personally call it), I know there will be left over points, so I wa... |
Sort array of 3D points to maximize number of tetrahedra in the array |
|algorithms|computational-geometry|simplex| |
Let $P$ be a indexable set(array) of points in $\mathbb{R}^3$ s.t. $P = \{p_0,p_1,p_2,...,p_n\}, p_i \in\mathbb{R}^3$.
I want to sort $P$ so that every 4 consecutive points forms a non-coplanar tetrahedra/3D-simplex/triangular pyramid (whatever you personally call it), I know there will be left over points, so I wa... |
Let $P$ be a indexable set(array) of points in $\mathbb{R}^3$ s.t. $P = \{p_0,p_1,p_2,...,p_n\}, p_i \in\mathbb{R}^3$.
I want to sort $P$ so that every 4 consecutive points forms a non-coplanar tetrahedra/3D-simplex/triangular pyramid (whatever you personally call it), I know there will be left over points, so I wa... |
null |
**Hint:**
The naive method will not work. Assume four points forming a non-degenerate tetrahedron plus four coplanar points and no other alignment. Grouping the first four results in a single tetrahedron, while two are otherwise possible. |
I am reading an algorithm book.
Any comparison sort must make $\Omega(n\log(n))$ comparisons in the worst case to sort $n$ elements.
Can we create a decision tree for any comparison sorting algorithm even if it is very complicated for $n$? |
Can we create a decision tree for any comparison sorting algorithm even if it is very complicated? |
|time-complexity|sorting|comparison|decision-tree| |
**Hint:**
The naive method will not work. Assume four points forming a non-degenerate tetrahedron plus four coplanar points and no other alignment. Grouping the first four results in a single tetrahedron, while two are otherwise possible.
A heuristic is to first form all possible groups of coplanar points (four o... |
There are 2 options,
Zip archive format style, each file is compressed separately. There is a index at the end of the file (can also be at the start) that lists the metadata for each file and where the compressed block for each file exists.
The other option is the tarball style, first the set of files are combin... |
I have a list of values: `[value1, value2, value3]` and I am trying to generate all combinations of replacements with some default value (`DEFAULT`).
Basically result like this
[value1, value2, value3]
[DEFAULT, value2, value3]
[value1, DEFAULT, value3]
[value1, value2, DEFAULT]
[DEFAULT, ... |
Computing combinations of replaced values while keeping order of the list |
|algorithms|combinatorics| |
In general, a decision tree would enumerate all possible permutations $(N!)$ for given input of $N$ elements, out of which only $1$ would be desirable.
A sorting algorithm doesn't generate all possible permutations, it follows a set of predefined steps to reach the desired output. This would be equivalent to taking... |
I have a list of values: `[value1, value2, value3]`, and I am trying to generate all combinations of replacements with some default value (`DEFAULT`).
Basically, result like this.
[value1, value2, value3]
[DEFAULT, value2, value3]
[value1, DEFAULT, value3]
[value1, value2, DEFAULT]
[DEFAUL... |
null |
In theory, yes you should be able to create a decision tree for every comparison based sorting algorithm. You can write a program that will do so (for a fixed comparison-based sorting algorithm of your choice, say quicskort). Do keep in mind that decision trees have n! leaves so (roughly) beyond input sizes of say 11 y... |
According to this, a weighted schedule is considered NP-complete (not solve-able in polynomial time) if it has groups of 3 or more intervals:
https://en.wikipedia.org/wiki/Interval_scheduling#NP-complete_when_some_groups_contain_3_or_more_intervals
But I don't understand the explanation at all. Why are 3 grouped... |
Weighted interval scheduling, exponential time/ NP-complete? |
|np-complete|np-hard|intervals| |
I'd like to know if there's a non-recursively computable language that can be accepted by the Turing machine.
From the following definition of the recursively enumerable language:
[![There is a partial computable function f such that:
{\displaystyle f(x)={\begin{cases}1&{\mbox{if}}\ x\in S\\{\mbox{undefined/does not... |
acceptance of non-recursively enumerable language by the Turing machine |
|turing-machines|recursively-enumerable| |
I'd like to know if there's a non-recursively computable language that can be accepted by the Turing machine.
From the following definition of the recursively enumerable language:
[![\[1\]: https://i.stack.imgur.com/IoVYC.png][1]][1]
and from the fact that recursively enumerable = Turing recognizable (from wiki)... |
The procedure below can be used to explicitly build the decision tree of any comparison-based algorithm:
- generate all permutations of the array $[1, 2, \cdots n]$.
- for every permutation, run the algorithm and note the outcomes of every comparison.
- merge the traces so obtained, in the form of a tree. |
null |
The procedure below can be used to explicitly build the decision tree of any comparison-based algorithm:
- generate all permutations of the array $[1, 2, \cdots n]$.
- for every permutation, run the algorithm and note the outcomes of every comparison, together with the involved element indexes.
- merge the tra... |
The procedure below can be used to explicitly build the decision tree of any comparison-based algorithm:
- generate all permutations of the array $[1, 2, \cdots n]$.
- for every permutation, run the algorithm and note the outcomes of every comparison, together with the involved element indexes.
- merge the tra... |
null |
null |
[Directed Graph Hashing (Helbling 2020)](https://arxiv.org/abs/2002.06653) described a method of stashing cyclic directed graphs.
If I understand it correctly, first it reduces the graph to the condensation graph in which cycles are collapsed into single nodes. The condensation graph is acyclic and hence is easy to ... |
null |
In the ideal world, systems are designed using immutable data structures. However, when you dive deeper into lower levels of abstractions, you realize that at some point a library written in C is being used to performs some tricks that merge the unmutable with the mutable.
Now, I am not intrested in whether or not I... |
How to merge both, mutable and immutable worlds? |
|c| |
In the ideal world, systems are designed using immutable data structures. However, when you dive deeper into lower levels of abstractions, you realize that at some point a library written in C is being used to performs some tricks that merge the unmutable with the mutable.
Now, I am not intrested in whether or not I... |
In the ideal world, systems are designed using immutable data structures. However, when you dive deeper into lower levels of abstractions, you realize that at some point a library written in C is being used to performs some tricks that merge the unmutable with the mutable.
Now, I am not intrested in whether or not I... |
In the ideal world, systems are designed using immutable data structures. However, when you dive deeper into lower levels of abstractions, you realize that at some point a library written in C is being used to performs some tricks that merge the unmutable with the mutable.
Now, I am not intrested in whether or not I... |
There is an $O(n)$ solution, using a nice trick:
Keep track of the different values you have already seen in an auxiliary hashmap, called $seen$.
Now, loop over the elemnts of the array (the original array, you don't have to add the negations), and for each $x_i$ do the following:
1. If either $s-x_i\in seen$ ... |
An alternative to rejection sampling (as described in [FrankW's answer](https://cs.stackexchange.com/a/29205/9550)) is to use a scaling algorithm, that takes into account an answer of [7,8] as if it was another coin flipping.
There is a very detailed explanation at [mathforum.org][1], including the algorithm (its `N... |
null |
It is known that the complexity class P is equivalent to the class of problems decided by polynomial-time uniform familiy of circuits. When stating the complexity of algorithms as this family of circuits, this complexity is usually stated in terms of the depth and size of the circuit. What I have not understood well is... |
Time complexity when implementing uniform family of circuits |
|complexity-theory|circuits| |
In the comparison sort model of sorting, the fastest possible algorithm is order $n \log(n)$, where $n$ is the number of input numbers. What is the time complexity of sorting a list of natural numbers, each represented as a string of ones and zeros, and separated by commas. For example, the input $11,1,10$ would be sor... |
Someone who was explaining to me the master theorem said that for the case 1, we compare the $n^{log_b(a)}$ and $f(n)$. If the growth rate of $n^{log_b(a)}$ is greater than the growth rate of $f(n)$ then we subtract an epsilon to have this equality:
$$f(n) = O(n^{(log_ba) - \epsilon})$$
My question is, doesn't the ... |
Understanding Master Theorem |
|big-o-notation|master-theorem| |
What is the time complexity of the best-known algorithm to search for the largest complete bipartite subgraph (not induced subgraph since it is allowed to remove edges) in a given graph?
A complete bipartite graph $G = (V, E)$ can be partitioned into two subsets $V_1$ and $V_2$ such that each vertex of $V_1$ is co... |
null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.