instruction stringlengths 0 29.8k ⌀ |
|---|
How proof of Huffman algorithm greedy property starts with optimal tree T? |
null |
Optimal tree means it has the minimum bit length. Huffman trees are an example of Optimal trees (in fact Huffman can produce different optimal trees using tie breaking rules) but there are also optimal trees that are non Huffman where the least frequency nodes are not at the deepest depth and yet end up having the same... |
null |
Questions about algorithms that deals with changing input data. Given a class of input objects, find efficient algorithms and data structures to answer a certain query about a set of input objects each time the input data is modified, i.e., objects are inserted or deleted. |
null |
I read some references in order to answer your question.
- **Transition function:** takes as arguments a state and an input symbol and returns a state, denoted by $\delta$.
- **_Extended_ transition function:** Describes what happens when we start in any state and follow any sequence of inputs. It is a function... |
null |
marks the set of numbers $$P=\{P_1,P_2,P_3, \ldots ,P_n\}$$
need to find number $X$:
$|P_1-X|+|P_2-X|+\ldots+|P_n-X|=D$, which minimizes $D$.
the fact that X is the median can be shown using induction on the number of numbers n in $P$.
Base: $n=1$: trivial to see that the median is $P_1$ and $|P_1-P_1|=D=0$... |
null |
Say i have an 2d array A of nxn size, int values already given for each item.these values can be the same or different.
There's gonna be another nxn array B being input.
I can only interchange one row from B with another row from B, or one col from B with another col from B. (Exchanging a row with a col is not a thin... |
null |
If I have a [deterministic finite automaton][1] (DFA) with a language $W$, and I need to create another DFA that returns all the strings that are a concatenation of an even number of strings in $W$, how would I solve this?
I was considering an approach where I alternate between accepted even multiples of the DFA and... |
DFA for even concatenation of strings from a language |
null |
I searched for linear solver libraries and found out about PETSc library which is considered to be a powerful and useful library. PETSc consists of implementations of various iterative methods with preconditioners and sparse matrix storing methods. All the methods are realized sequentially and in parallel using MPI.
... |
null |
There are data structures that allow you to do this in less than linear time, even for worst-case inputs. See https://www.microsoft.com/en-us/research/wp-content/uploads/2011/01/p255-DingKoenig.pdf (and the papers references in there).
If your two sets S and T have a large intersection and you have a dictionary for ... |
null |
Let $ G(V, E, w)$ be a graph with no negative weights.
Describe an algorithm that returns the shortest cycle containing a node $ v $.
I came across this algorithm https://courses.engr.illinois.edu/cs374/sp2017/labs/solutions/lab10-sol.pdf
I can't convince myself it is true, because $ d(s,v)+w(s,v)$ might not ... |
null |
Let $ G(V, E, w)$ be a graph with no negative weights.
Describe an algorithm that returns the shortest cycle containing a node $ v $.
I came across this algorithm https://courses.engr.illinois.edu/cs374/sp2017/labs/solutions/lab10-sol.pdf
I can't convince myself it is true, because $ d(s,v)+w(s,v)$ might not ... |
There are three elevators in a building that has twelve floors. Find an algorithm that needs to find the best possible way for the elevators to stop at any particular floor considering the traffic waiting for the lift on that floor. Consider the following constraints:
1. there can be any number of people that need t... |
The three elevator problem |
null |
I am trying to decide whether the following language is context free:
$$L = \{ a^nb^{3n}c^n \, | \, n \geq 0 \} $$
Assume $L$ is context-free.
Let $p$ be the pumping length given by the Pumping Lemma.
Choose string $s = a^pb^{3p}c^p ∈ L$. Then, $|s| ≥ p$.
Take an arbitrary decomposition $s = uvxyz$ where $|vxy... |
null |
What is the difference between transition function delta ($\delta$) and extended transition function delta hat ($\hat{\delta}$) in finite automata?
Both of them, when started at a state $q$ for a string $w$, will lead to the same state $p$. So what is the difference?
See, for example, page 15 of the third edition... |
What is the difference between transition function (delta) and extended transition function (delta hat) in finite automata? |
null |
After reading of the [google deepmind achievements on Atari's games][1], I am trying to understand the q-learning and q-networks, but I am little bit confused. The confusion arise in the concept of the discount factor.
Brief summary of what I understand.
A deep convolutional neural network is used to estimate the va... |
null |
I agree with @jmite that the best resources on continuations are likely to come from the Scheme community. Here's a brief tutorial that looks very good: [Jeremy H Brown, _Advanced Scheme_](http://people.csail.mit.edu/jhbrown/scheme/). The tutorial also discusses Scheme's hygienic macros which might also interest you ... |
null |
I've had the following question on a test and I answered: 'False', my answer was incorrect and I'm trying to understand why.
$VC = \{<G,k> |\ G =$ undirected graph with a vertex cover of size $k\}$
$IS = \{<G,k>|\ G =$ undirected graph with an independent set of size $k\}$
**Ture or False:**
**Assuming ther... |
What are the necessary requirements for proving NP is closed under complement? |
null |
Suppose I have this c++ code:
```
for(int i=0; i<n*n*n; i++) {
for(int j=0; j<n*n; j++) {
if(i>n && j<n) {
for(int k=0; k<n*n*n*n; k++) s++;
}
}
}
```
I need to find its time complexity.
What I tried doing is: I tried determining the times the i... |
null |
I wondered if, for a fixed integer $k ≥ 3$, how can I construct a circuit for each $n ∈ N$, that takes as input an n-bit integer $x$ and outputs whether $\dfrac3k=0$?
Considering an n-bit integer as input:
e.g. $\ldots10101110$, where $a_0$ is the rightmost bit and $a_N$ the leftmost bit, $\bmod 3$ has a cycle of $... |
$n \pmod k$ circuit |
null |
I wondered if, for a fixed integer $k ≥ 3$, how can I construct a circuit for each $n \in \mathbb{N}$, that takes as input an n-bit integer $x$ and outputs whether 3 divides $k$?
Considering an n-bit integer as input:
e.g. $\ldots10101110$, where $a_0$ is the rightmost bit and $a_N$ the leftmost bit, $\bmod 3$ has ... |
This is my implementation of a list structure.
It is not dynamically allocated, and all allocations are done when it is constructed.
- Iteration is at worst case O(n), n being the max size of the list
- Insert is O(1)
- Remove is O(1), except if using sort optimization(tradeoff: slows remove but potentially hel... |
null |
I think the answer itself is wrong (please correct me if not) because first choose 0 from (0+10)* and 11 from (11+ε) so we get 011 and from the final (0+10)* if we choose 10 the final string becomes 01110 where we get 2 consecutive 1 pairs.
This may work: (0+10)* (11+ε)<!-- (11+ε+1) --> (0+0... |
null |
Is Determining the Number of distinct Prime Factors Polynomial? |
null |
For more info: [Dynamic Algorithms](https://en.wikipedia.org/wiki/Dynamic_problem_(algorithms)). |
null |
Assume the following hypothetic scenario:
> You know the values $v_1^0, \ldots, v_n^0$ of $n$ cryptocurrencies. You know the values this currencies will have for the following $m$ days; this is, $v_0^1, \ldots, v_n^1$ up to $v_1^m, \ldots, v_n^m$. In general, $v_{i}^j$ is the value
of the $i$th currency in $j$ days... |
Greedy algorithm for trading cryptocurrencies with perfect price information |
null |
I am presented with the following problem: In an array of $n$ sorted numbers and $f(n)$ unsorted numbers where $f(n)=O(\log n)$, find an algorithm to sort the entire array in $O(n)$ time.
What I am getting from this is that I should find an algorithm to sort $n + O(\log n)$ numbers in $O(n)$ time. I think the first... |
null |
Given an array of length n, how to determine if all the continuous subsequence of this array contains at least one unique element.
Any subarray `array[start, end]` with `0 <= start <= end < n` will have a unique element. The algorithm will return :
- `True` for `array = [1, 3, 5, 3, 1]`
- `False` for `array... |
Determine if all the continuous subsequences of an array contain at least one unique element in O(n lgn) |
|algorithms|complexity-theory|recurrence-relation|hash|divide-and-conquer| |
Given an isothetic polygon (sides parallel to the x-axis or y-axis) and 2 points (start and end) on the boundary of the polygon,
find a path traveling only in the direction of the x or y axis (up, right, down, left), such that the entire polygon is visible by the time a point travels from the `start` point to the `en... |
Given an isothetic polygon (sides parallel to the x-axis or y-axis) and 2 points (start and end) on the boundary of the polygon,
find the shortest path traveling only in the direction of the x or y axis (up, right, down, left), such that the entire polygon is visible by the time a point travels from the `start` point... |
null |
The question asks to write an algorithm using Dijkstra's algorithm with time complexity of
$\Theta(|E| \log |V|)$ that find the second shortest path between s∈V and t∈V.
The farthest I managed to get is:
1.Run Dijkstra's algorithm and find the path from $s$ to $t$. Mark this path as $P_{(s,t)}$.
2.Remove o... |
The second shortest path on a directed graph |
|algorithms|graphs|shortest-path| |
null |
Pivot is unique in the whole array, therefore every sub array containing pivot contains a unique item. Subarrays not containing pivot are the subarrays of the array from start to pivot-1 and the subarrays of the array from pivot+1 to end.
In case you have more than one unique item, say at pivot1, pivot2 and pivot3,... |
null |
null |
:)
I am trying to implement an algorithm that fairly distributes people into groups, given their ranking of those groups, while also taking into account their preference for partners.
I have modeled this as a directed graph with upper and lower bounds and costs on edges representing their ratings. Finding a solu... |
Max flow, min cost with upper and lower bounds |
|network-flow| |
It’s easy to find small prime factors. Pollard-rho can find a factor p in $O(\sqrt p)$ which finds many prime factors. And for large n with no known small prime factors we can do a primality test which finds there is one factor only.
The problem is when n is so large that we cannot prove there are no factors up to ... |
null |
{"Voters":[{"Id":102070,"DisplayName":"Jorayen"}],"DeleteType":1} |
{"Voters":[{"Id":102070,"DisplayName":"Jorayen"}]} |
**Edited Version**
Consider the following decision problem:
Given $([b_1, \cdots, b_n],t)$, where $[b_1, \cdots b_n]$ is an array of natural numbers each less than $n^c$ and $t$ is a target natural number, do there exists natural numbers $f_1, \cdots f_n$ such that
1) $f_i \le b_i$ for all $1 \le i \le n$
2) $... |
I'm trying to understand reaching definitions and I'm having hard problem wrapping it around my head with the following definition (taken from the the following [paper][1] page 114):
* $B_i\;\text{be a basic block}$
* $ReachIn(B_i)\;\text{be the set of registers that reach the entrance to}\;B_i$
* $ReachOut(B_i)\;... |
null |
If I understand correctly, your problem can be formulated as a [minimum cost flow problem](https://en.wikipedia.org/wiki/Minimum-cost_flow_problem), but with lower bounds (demands) on the flow through each edge.
For details how to handle the lower bounds, see https://cs.stackexchange.com/q/125331/755 or the correspo... |
null |
#define N 2
#define TRUE 1
#define FALSE 0
int flag[N]={FALSE}
int turn;
void process(int i)
{
int j=NOT(i);
while(1)
{
a) NON-Critical Section();
b) flag[i]=TRUE;
c) turn=i;
d) while(flag[j]==TR... |
What is a real life analogy of busy waiting by process "i" when "turn=i"? |
|operating-systems|synchronization| |
null |
If you go to the JSON spec page : https://www.json.org/json-en.html, then you'll see the language represented by some diagrams showing graphically what the language looks like. I wondered, does this kind of diagram has a name ? |
What is the name of the diagram used in JSON spec for representing a context-free language? |
|context-free| |
It's called a "syntax diagram", "syntax chart", or "railroad diagram".
Of these three, "syntax diagram" is the most common term. They're sometimes called "Pascal syntax diagrams" because the first time that most people saw them was in the [1973 Pascal report][1].
I can't find a definitive source to back this up, ... |
I'm a first year BCA student. Can you help me with flowgarithm of the common child problem (LCS) without pointers |
Flowgarithm for common child program for a beginner (without pointers) |
|arrays|strings|longest-common-substring| |
I'm given a rectangular plane with `width`, `height` and a set of rectangles defined by `left`, `top`, `width`, `height`, where left and top define left upper corner of the rectangle. My task is to find the largest rectangle that can fit among the other rectangles without overlapping.
It should be possible using Sw... |
Find maximum sized rectangle on a plane |
|algorithms|optimization|computational-geometry| |
Now, I have assumed the unary number to be 1.
and my doubts are
1. Do you design this machine similar to normal unary multiplication assuming that the constant 2 (11) is always present in the input tape?
Or
2. the tape only one unary number is present in the tape?
This confusion may be because of my poor under... |
Designing a Turing machine (TM) to multiply a unary number by 2 |
|turing-machines| |
I'm given a rectangular plane with `width`, `height` and a set of rectangles defined by `left`, `top`, `width`, `height`, where left and top define left upper corner of the rectangle. My task is to find the largest rectangle that can fit among the other rectangles without overlapping.
It should be possible using Sw... |
null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.