instruction stringlengths 0 29.8k ⌀ |
|---|
A source provides a stream of items $x1, x2,...$ . At each step $n$ we want to save a random sample $S \subseteq \{ (x_i, i)|1 \le i \le n\}$ of size $k$, i.e. $S$ should be a uniformly chosen sample from all $\tbinom{n}{k}$ possible samples consisting of seen items. So at each step $n \ge k$ we must decide whether to ... |
Continuous uniform samples |
|algorithms|randomized-algorithms|probabilistic-algorithms|random| |
|algorithms|probability-theory|randomized-algorithms|randomness| |
How do I build a random source that outputs the bits 0 and 1 with $prob(0) = prob(1) = 0.5$. We have access to another random source $S$ that outputs $a$ or $b$ with independent probabilities $prob(a)$ and $prob(b) = 1 - prob(a)$ that are unknown to us.
How do I state an algorithm that does the job and that does not... |
|algorithms|probability-theory|randomized-algorithms| |
Questions about how much information has to be exchanged between independent agents who collaboratively solve an algorithmic problem. |
Questions about (typically randomized) algorithms that can produce no or an incorrect answer with a certain probability.
Popular examples include [Monte Carlo](https://en.wikipedia.org/wiki/Monte_Carlo_algorithm) and [Las Vegas](https://en.wikipedia.org/wiki/Las_Vegas_algorithm) algorithms. |
Questions about (typically randomized) algorithms that can produce no or an incorrect answer with a certain probability. |
An algorithm whose behaviour is determined by its input and a source of random numbers. |
An algorithm whose behaviour is determined by its input and a source of random numbers. |
Questions about different distance metrics on strings.
Popular examples include:
* [Hamming Distance](https://en.wikipedia.org/wiki/Hamming_distance)
* [Edit Distance](https://en.wikipedia.org/wiki/Edit_distance)
* [Levenshtein Distance](https://en.wikipedia.org/wiki/Levenshtein_distance)
* [Damerau–Levens... |
An algorithm whose behaviour is determined by its input and a source of random numbers.
Popular examples include variants of [Quicksort](https://en.wikipedia.org/wiki/Quicksort) that choose the pivot randomly, and probabilistic algorithms such as [Miller-Rabin primality test](https://en.wikipedia.org/wiki/Miller-Rab... |
|algorithms|probability-theory|randomized-algorithms|randomness|online-algorithms| |
Online generation of uniform samples |
Questions about algorithms that receive the input piecewise and have to make decisions, that is produce output, before having seen the whole input. |
A source provides a stream of items $x_1, x_2,\dots$ . At each step $n$ we want to save a random sample $S \subseteq \{ (x_i, i)|1 \le i \le n\}$ of size $k$, i.e. $S$ should be a uniformly chosen sample from all $\tbinom{n}{k}$ possible samples consisting of seen items. So at each step $n \ge k$ we must decide whether... |
Analysis
--------
**Insert**: $\mathcal{o}(n\ log\ log\ n)$
**Search**: $\mathcal{o}(log\ log\ n)$
**Delete**: $\mathcal{O}(1)$
**Space**: $\mathcal{O}(n)$
**Get-Min**: $\mathcal{O}(1)$
**Extract-Min**: $\mathcal{O}(1)$
Implementation
--------------
1. Form a list out of an arbitrary (constant)... |
Analysis
--------
**Insert**: $\mathcal{o}(n\ log\ log\ n)$
**Search**: $\mathcal{o}(log\ log\ n)$
**Delete**: $\mathcal{O}(1)$
**Space**: $\mathcal{O}(n)$
**Get-Min**: $\mathcal{O}(1)$
**Extract-Min**: $\mathcal{O}(1)$
Implementation
--------------
1. Form a list out of an arbitrary (constant)... |
Due to the dubious nature of the question, I only provide hints.
Have you tried the obvious? With probability $\frac{1}{n}$, add the new element to the sample. If it is added, choose one of the elements already in the sample uniformly at random and drop it. Sounds about fair, does it not?
For a proof, you will ha... |
A source provides a stream of items $x_1, x_2,\dots$ . At each step $n$ we want to save a random sample $S_n \subseteq \{ (x_i, i)|1 \le i \le n\}$ of size $k$, i.e. $S_n$ should be a uniformly chosen sample from all $\tbinom{n}{k}$ possible samples consisting of seen items. So at each step $n \ge k$ we must decide whe... |
Analysis
--------
**Insert**: $\mathcal{o}(n\ log\ log\ n)$
**Search**: $\mathcal{o}(log\ log\ n)$
**Delete**: $\mathcal{O}(1)$
**Space**: $\mathcal{O}(n)$
**Get-Min**: $\mathcal{O}(1)$
**Extract-Min**: $\mathcal{O}(1)$
Implementation
--------------
1. Form a list out of an arbitrary (constant)... |
In terms of references and their implementation on the heap and the stack, how is
equality testing for arrays different from that for integers?
This is to do with java programming, if you have a stack and a heap, would equality testing for example j=i be the same for arrays and for integers? I understand that arra... |
null |
The definition of "a set $P$ can be shattered by rectangles" is that for **every** subset of $P$, there is a rectangle that contains precisely that subset and excludes the rest of $P$. Equivalently, every labeling of the points as positive and negative is consistent with at least one hypothesis in $H$.
Now consider ... |
{"Voters":[{"Id":39,"DisplayName":"Gilles"}]} |
In terms of references and their implementation on the heap and the stack, how is
equality testing for arrays different from that for integers?
This is to do with Java programming, if you have a stack and a heap, would equality testing for example `j == i` be the same for arrays and for integers? I understand that... |
Equality testing of arrays and integers in a procedural language |
|programming-languages|arrays|semantics|equality|memory-management| |
This is the analysis of the expected numbers of elements used by [George B.'s answer](http://cs.stackexchange.com/a/1933/82), i.e.: get two elements $x_0$ and $x_1$ from $S$. If $x_0x_1$ is $aa$ or $bb$ then discard them. Otherwise return $0$ for $ab$ and $1$ for $ba$, events that occur with the same probability $p_ap_... |
Integers are stored in one word of memory and there is a primitive machine code instruction for testing their equality. Most programming languages lift this instruction to the syntax, as with `i == j` in Java (where `i` and `j` are of type `int`).
Arrays are stored in multiple contiguous words in memory. In order to... |
Consider this: get two elements $x_0$ and $x_1$ from $S$. If $x_0x_1$ is $aa$ or $bb$ then discard them and repeat. Otherwise return $0$ for $ab$ and $1$ for $ba$, events that occur with the same probability $p_ap_b$.
This will use $2n$ elements from $S$, $n$ the number of performed steps. The probability of stoppin... |
The definition of "a set $P$ can be [shattered](http://en.wikipedia.org/wiki/Shattering_%28machine_learning%29) by rectangles" is that for **every** subset of $P$, there is a rectangle that contains precisely that subset and excludes the rest of $P$. Equivalently, every labeling of the points as positive and negative i... |
null |
I'm looking for some relatively simple examples of when structural hazards occur in a pipelined architecture.
The only scenario I can think of is when memory needs to be accessed during different stages of the pipeline (ie, the initial instruction fetch stage and the later memory read/write stage).
I'm thinking t... |
When do structural hazards occur in pipelined architectures? |
|computer-architecture|cpu-pipelines| |
I'm looking for some relatively simple examples of when [structural hazards](http://en.wikipedia.org/wiki/Hazard_%28computer_architecture%29#Structural_hazards) occur in a pipelined architecture.
The only scenario I can think of is when memory needs to be accessed during different stages of the pipeline (ie, the ini... |
Generating functions are useful when you're designing counting algorithms. That is, not only when you're looking for the number of objects having a certain property, but also when you're looking for a way to enumerate these objects (and, perhaps, generate an algorithm to count the objects). There is a very good present... |
|algorithms|matrices| |
This is a special case of a [selection algorithm][2] that can find the $k$th smallest element of an array with $k$ is the half of the size of the array. There is an implementation that is linear in the worst case.
### Generic selection algorithm
First let's see an algorithm `find-kth` that finds the $k$th element... |
Deterministic and randomized communication complexity of set equality |
null |
An equivalent definition of NP is that it consists of all problems that are *decidable* (not just verifiable) in polynomial time by a non-deterministic Turing machine. NTMs are known to be no more powerful than TMs in the sense that the set of problems decidable by NTMs is identical to the set of problems decidable by ... |
I want to convert a user entered regular expression into an NFA so that I can then run the NFA against a string for matching purposes. What is the minimum machine that can be used to parse regular expresssions?
I assume it must be a push down automaton because the presense of brackets means the need to count and a ... |
Does a Regular Expression need a push down automata to parse it? |
|finite-automata|regular-expressions| |
The exercise is
>Given a set of point $S$ and a point $p$. Decide in $O(n)$ time if $p$ is a vertex of convex polygon formed from points of $S$.
The problem is I am a little bit confused with time complexity $O(n)$. The more naive solution would be to construct convex polygon in $O(nlogn)$ and test if $p$ is on... |
If a point is a vertex of convex hull |
|algorithms|computational-geometry| |
Hint: a point is a vertex of convex hall iff there are two half-lines from it such that all points fall inside the angle created by them.
The idea of the algorithm:
>! Design an algorithm with two variables for two points. The algorithm will go over the points and will update these two variable such that all points... |
|formal-languages|finite-automata|regular-expressions| |
null |
Since $k$ is constant, we can store the count of each element in the range $0..m$ for $0\leq m \lt n$ in $0..n$ in $O(nk) = O(n)$ time and space. The primary observation is that you can make a two-dimensional array `count[pos][elem] = occurences of 'elem' in the indices 0..pos` in $O(nk)$ time, then query ranges by fi... |
Does the language of Regular Expressions need a push down automata to parse it? |
You are correct. It is easy to show that the syntax of regular expressions is not regular using [standard techniques](http://cs.stackexchange.com/questions/1031/how-to-prove-that-a-language-is-not-regular).
One possibility is to use a homomorphism to get rid of all symbols but the parentheses, which leaves you with ... |
You are correct. It is easy to show that the syntax of regular expressions is not regular using [standard techniques](http://cs.stackexchange.com/questions/1031/how-to-prove-that-a-language-is-not-regular).
One possibility is to use a homomorphism to get rid of all symbols but the parentheses, which leaves you with ... |
You are correct. It is easy to show that the syntax of regular expressions is not regular using [standard techniques](http://cs.stackexchange.com/questions/1031/how-to-prove-that-a-language-is-not-regular).
One possibility is to use a homomorphism (which $\mathrm{REG}$ is closed against) to get rid of all symbols bu... |
You are correct. It is easy to show that the syntax of regular expressions is not regular using [standard techniques](http://cs.stackexchange.com/questions/1031/how-to-prove-that-a-language-is-not-regular).
One possibility is to use a homomorphism (which $\mathrm{REG}$ is closed against) to get rid of all symbols bu... |
null |
This is partly a matter of terminology, and as such, only requires that you and the person you're talking to clarify it beforehand. However, there are different topics that are more strongly associated with [parallelism](http://en.wikipedia.org/wiki/Parallel_computing), [concurrency](http://en.wikipedia.org/wiki/Concur... |
null |
|formal-languages|parsers|regular-expressions|pushdown-automata| |
What closure properties can i use to transform this languages?
$L_a := \{ a^*cw : w \in \{a,b \}^* and \ |w|_a = |w|_b \} \subseteq \{a, b, c\}^*$
$L_a' := \{ \{a,d\}^*cw : w \in \{a,b,d \}^* and \ |w|_a + |w|_d = |w|_b \} \subseteq \{a, b, c,d\}^*$ union?
$L_a'' := \{ d^*cw : w \in \{a,b \}^* and \ |w|_a ... |
Use closure properties to transform languages to $L := \{ a^nb^n : n\in \mathbb N \}$ |
|regular-languages|closure-properties| |
The exercise is
>Given a set of point $S$ and a point $p$. Decide in $O(n)$ time if $p$ is a vertex of convex polygon formed from points of $S$.
The problem is I am a little bit confused with time complexity $O(n)$. The more naive solution would be to construct convex polygon in $O(n\log n)$ and test if $p$ is ... |
What closure properties can i use to transform this languages to $L := \{ a^nb^n : n\in \mathbb N \}$?
(1) $L_a := \{ a^*cw : w \in \{a,b \}^* and \ |w|_a = |w|_b \} \subseteq \{a, b, c\}^*$
(2) $L_a' := \{ \{a,d\}^*cw : w \in \{a,b,d \}^* and \ |w|_a + |w|_d = |w|_b \} \subseteq \{a, b, c,d\}^*$ union?
(3... |
What closure properties can i use to transform these languages to $L := \{ a^nb^n : n\in \mathbb N \}$?
1. $L_a = \{ a^*cw ∣ w \in \{a,b \}^* ∧ \ |w|_a = |w|_b \}$
2. $L_a' = \{ \{a,d\}^*cw ∣ w \in \{a,b,d \}^* ∧\ |w|_a + |w|_d = |w|_b \}$ (union?)
3. $L_a'' = \{ d^*cw ∣ w \in \{a,b \}^* ∧ \ |w|_a = |w|_b... |
|formal-languages|context-free|closure-properties| |
What closure properties can i use to transform this languages
$1. \ L_a = \{ a^*cw ∣ w \in \{a,b \}^* ∧ \ |w|_a = |w|_b \}$
$2. \ L_b = \{ab^{i_1}ab^{i_2}...ab^{i_n} ∣ i_j∈ℕ ∧ \exists j∈⟦1,n⟧ ~~ \ i_j \not= j \}$
to $L := \{ a^nb^n : n\in \mathbb N \}$?
I tried:
1. $L_a = \{ a^*cw ∣ w \in \{a,b \}^*... |
Consider [scheduling](https://en.wikipedia.org/wiki/Single-machine_scheduling), the task of assigning jobs with certain durations and deadlines to machines. We assume discrete time. Many such problems are NP(O)-hard.
In particular, this answer will talk about $1 \mid r_i \mid L_\max$, that is we schedule
* on on... |
Hint: for $L_a$ you can use stability with intersection from $L_a'''$. |
What closure properties can i use to transform the languages
1. $L_a = \{ a^*cw ∣ w \in \{a,b \}^* ∧ \ |w|_a = |w|_b \}$ and
2. $L_b = \{ab^{i_1}ab^{i_2}...ab^{i_n} ∣ i_j∈ℕ ∧ \exists j∈⟦1,n⟧ ~~ \ i_j \not= j \}$
to $L := \{ a^nb^n : n\in \mathbb N \}$, respectively?
I tried:
1. $L_a = \{ a^*cw ∣ w \... |
Regular languages are closed against intersection. This often allows to cut away all parts of a language that are not needed to show non-regularity.
>! For $L_a$, the part right of $c$ is sufficient; try to intersect with a regular expression that lets you keep all words $ca^nb^n$ and work from there. For $L_b$, try... |
I suggest you to read the Jukka's nice answer to the question "[Matching regular expressions using regular expressions][1]" on cstheory, too. An excerpt:
...<br>
For example, we can modify the standard notation as follows to obtain *"compressed" regular expressions*:
* You are allowed to remove any prefix that c... |
What closure properties can i use to transform the languages
1. $L_a = \{ a^*cw \mid w \in \{a,b \}^* \land |w|_a = |w|_b \}$ and
2. $L_b = \{ab^{i_1}ab^{i_2}\ldots ab^{i_n} \mid i_j∈\mathbb N \land \exists j∈[1,n] \ i_j \not= j \}$
to $L := \{ a^nb^n \mid n\in \mathbb N \}$, respectively?
I tried:
... |
Regular languages are closed under intersection. This often allows to cut away all parts of a language that are not needed to show non-regularity.
>! For $L_a$, the part right of $c$ is sufficient; try to intersect with a regular expression that lets you keep all words $ca^nb^n$ and work from there. For $L_b$, try t... |
Hint: the point $p$ is a vertex of the convex hall iff there are two half-lines from it such that all points fall inside the angle created by them.
The idea of the algorithm:
>! Design an algorithm with two variables (for points). The algorithm will go over the points and will update these two variable such that al... |
Hint: the point $p$ is a vertex of the convex hall iff there are two half-lines from it such that all points fall inside the angle created by them.
The idea of the algorithm:
>! Design an algorithm with two variables $q$ and $r$ (input points). The algorithm will examine each of the input points and will update $q$... |
Hint: the point $p$ is a vertex of the convex hall iff there are two half-lines from it such that all points fall inside the angle created by them.
Here is an idea for an algorithm based on this hint:
>! Design an algorithm with two variables $q$ and $r$ (input points). The algorithm will examine each of the input ... |
As a university-level CS educator, the issue of which programming language to teach in the first programming course often comes up for discussion. There are thousands of languages to choose between, and lots of religious fever (or fevour) supporting one language camp over another. All of this subjective bias surroundin... |
Criteria for selecting language for first programming course |
|programming-languages|education| |
null |
My main concern is _universality_, in the sense that learning _this_ programming language should make the student able to handle most programming languages.
As much as I regret it, this criterion excludes pure functional languages. It also applies to the course that should not use exotic features of the language.
... |
I think simplicity and ease of learning is one of the main criteria. In an introductory course on programming we would like to avoid unnecessary programming hurdles and focus as much as possible on principles of programming and algorithmic problem solving. The first year students often lack the ability to think algorit... |
Given the following recursive equation
$$ T(n) = 2T(\frac{n}{2})+n\log n$$ we apply the Master theorem and obtain
$$ n^{\log_2(2)} = n.$$
Now we check the first two cases for $\varepsilon > 0$:
$n\log n \in O(n^{1-\varepsilon})$
$n\log n \in \Theta(n)$
The two cases are not satisfied. So we have to ch... |
Master theorem not applicable? |
|complexity-theory| |
I think simplicity and ease of learning is one of the main criteria. In an introductory course on programming we would like to avoid unnecessary programming hurdles and focus as much as possible on the principles of programming and algorithmic problem solving. The first year students often lack the ability to think alg... |
I'm reading "An Introduction to Formal Languages and Automata" written by "Peter Linz" and after reading 5 first chapters I face with below problem
simple grammars and regular grammars (specially right linear) are very similar to each other.
I wanna know what is relation can be find between these?
and what is diff... |
relation between simple grammars and regular grammars |
|regular-languages|context-free|regular-expressions| |
I have an algorithm, shown below, that I need to analyze. Because it's recursive in nature I set up a recurrence relation.
GraphComplete(A[1..n, 1..n])
//Input: Adjacency matrix A[1..n, 1..n]) of an undirected graph G
//Output: 1 (true) if G is complete and 0 (false) otherwise
if n = 1 ret... |
How to go from a recurrence relation to a final complexity |
|time-complexity| |
I am reading "An Introduction to Formal Languages and Automata" written by Peter Linz and after reading the first five chapters I face below problem with
simple and regular (especially right linear) grammars which are very similar to each other.
What relation exists between these? What is the difference?
Can you c... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.