instruction stringlengths 0 29.8k ⌀ |
|---|
To pop an element off of a priority queue, the worst-case complexity is:
O(logN) where N is the number of elements.
Now if you do K pop operations on the priority queue, the number of elements decreases.
So the cost of these K operations would be:
O(logN) + O(log(N-1)) + O(log(N-2)) + O(log(N-3))...... |
Big-O doesn't care about a factor 0.5, for example. Now log sqrt(N) = 1/2 log N. So if you take away enough elements to change the size of the queue from N to sqrt(N), you have multiplied the time by 0.5, which doesn't affect O(N). And there are now only sqrt(N) elements remaining, removing them even if you could do it... |
I'm currently working on an exercise that has made me ponder for a bit. I can only credit my Data Structures professor for the content of the task I'm rephrasing, since they
didn't provide any source, but basically:
> Suppose you have a file *D*, for which you want to create an inverted file, *L*, so that for ever... |
Would this be the correct time complexity? |
|time-complexity|data-structures|filesystems| |
I'm currently working on an exercise that has made me ponder for a bit. I can only credit my Data Structures professor for the content of the task I'm rephrasing, since they
didn't provide any source, but basically:
> Suppose you have a file *D*, for which you want to create an inverted file, *L*, so that for ever... |
given CFG G = {V1, Σ1, R1, S1} in its CNF form,
I have to define the next language:
{ x ∈ L(G) | |x| ∈ ℕeven }
i . e .
L5 = all even length words in L(G)
How can I do it?
[1]: https://i.stack.imgur.com/5xVrE.png |
How to create all even length words from a given CNF grammar |
|formal-grammars| |
given CFG G = {V1, Σ1, R1, S1} in its CNF form,
I have to define (via {V5, Σ5, R5, S5}) the next language:
{ x ∈ L(G) | |x| ∈ ℕeven }
i . e .
L5 = all even length words in L(G)
How can I do it?
[1]: https://i.stack.imgur.com/5xVrE.png |
given CFG G = {V1, Σ1, R1, S1} in its CNF form,
I have to define (via {V5, Σ5, R5, S5}) the grammar that constructs the next language:
L5 = { x ∈ L(G) | |x| ∈ ℕeven }
i . e .
L5 = all even length words in L(G)
How can I do it?
[1]: https://i.stack.imgur.com/5xVrE.png |
given CFG G = {V1, Σ1, R1, S1} in its CNF form,
I have to define (via {V5, Σ5, R5, S5}) G5 grammar that constructs L(G5):
while L(G5) = { x ∈ L(G) | |x| ∈ ℕeven }
i . e .
L5 = all even length words in L(G)
How can I do it?
[1]: https://i.stack.imgur.com/5xVrE.png |
given CFG G = {V1, Σ1, R1, S1} in its CNF form,
I have to define (via {V5, Σ5, R5, S5}) G5 grammar that constructs L(G5):
while L(G5) = { x ∈ L(G) | |x| ∈ ℕeven }
i . e .
L5 composed of all even length words in L(G)
How can I do it?
[1]: https://i.stack.imgur.com/5xVrE.png |
given CFG G1 = {V1, Σ1, R1, S1} in its CNF form,
I have to define (via {V5, Σ5, R5, S5}) G5 grammar that constructs L(G5):
while L(G5) = { x ∈ L(G1) | |x| ∈ ℕeven }
i . e .
L5 composed of all even length words in L(G1)
How can I do it?
[1]: https://i.stack.imgur.com/5xVrE.png |
given CFG *G1 = {V1, Σ1, R1, S1}* in its CNF form,
I have to define (via {V5, Σ5, R5, S5}) *G5* grammar that constructs *L(G5)*:
while *L(G5)* = { x ∈ L(G1) | |x| ∈ ℕeven }
i . e .
*L(G5)* composed of all even length words in *L(G1)*
How can I do it?
[1]: https://i.stack.imgur.com/5xVrE.png |
[![enter image description here][1]][1]
Let's assume I have graph above with spanning tree pointed out by blue edges.
But the only thing in the input is (up,down,left,right) description of each vertex.
So it would be (0,1,0,0) for vertex at (1,1), (1,0,1,1) for vertex at (2,2), etc. (1,1,1,1) is also possible.... |
Recreate a spanning tree in a grid graph given vertex descriptions |
|algorithms|enumeration|spanning-trees|planar-graphs|square-grid| |
|context-free| |
given CFG *G1 = {V1, Σ1, R1, S1}* in its CNF form,
I have to define (via {V5, Σ5, R5, S5}) a new *G5* grammar that constructs *L(G5)*:
while *L(G5)* = { x ∈ L(G1) | |x| ∈ ℕeven }
i . e .
*L(G5)* composed of all even length words in *L(G1)*
How can I do it?
[1]: https://i.stack.imgur.com/5xVrE.p... |
null |
null |
given CFG *G1 = {V1, Σ1, R1, S1}* in its CNF form,
I have to define a new *G5* grammar that constructs *L(G5)* using {V1, Σ1, R1, S1}:
while *L(G5)* = { x ∈ L(G1) | |x| is even }
i . e .
*L(G5)* composed of all even length words in *L(G1)*
How can I do it?
[1]: https://i.stack.imgur.com/5xVrE.pn... |
Let $G$ be a flow network, where $c(e)$ is the capacity of an edge, and the source is $s$ and sink $t$. Define a node $v$ to be "source-like" if every min-cut of $G$ contains $v$. Find an efficient algorithm to determine the source-like nodes.
I was thinking that since Ford-Fulkerson is efficient, we can go ahea... |
Finding source-like nodes in a flow notework |
|network-flow|ford-fulkerson| |
null |
If I may elaborate on @Optidad 's comment.
Input:
root
|
a
/ \
b c
/\ /\
d e d e
_"Building the list of all possible tuplets"_ means in other words enumerating all max length paths, namely:
0 1 2
-----
a b d
a b e
... |
If I may elaborate on @Optidad 's comment.
Input:
root
|
a
/ \
b c
/\ /\
d e d e
_"Building the list of all possible tuplets"_ means, in other words, enumerating all max length paths, namely:
0 1 2
-----
a b d
a b e
... |
If I may elaborate on @Optidad 's comment.
Input:
root
|
a
/ \
b c
/\ /\
d e d e
_"Building the list of all possible tuplets"_ means, in other words, enumerating all max length paths, namely:
0 1 2
-----
a b d
a b e
... |
[![enter image description here][1]][1]
Let's assume I have graph above with spanning tree pointed out by blue edges.
Vertex at position (1,1) (row 1, column 1) is connected to the bottom index and has degree 1.
Vertex at position (4,2) (row 4, column 2) is connected to the up, left and right vertex and has de... |
I have a square 2x2 matrix of integers. The number of columns is equal to the number of rows.
Each column and row are sorted from the lowest to heights numbers. For example:
[![enter image description here][1]][1]
Another example:
[![enter image description here][2]][2]
I need an algorithm to find whether ... |
Whether a number is in a sorted matrix |
|matrices| |
[![enter image description here][1]][1]
Let's assume I have graph above with spanning tree pointed out by blue edges.
Vertex at position (1,1) (row 1, column 1) is connected to the bottom vertex and has degree 1.
Vertex at position (4,2) (row 4, column 2) is connected to the up, left and right vertex and has d... |
This is a specific application of the fact that context-free languages are closed under under intersection with a regular languages. The usual proof is to use the fact that we can find a pushdown automaton and a finite state automaton, and then for the intersection simulate the pair in parallel. This is called the prod... |
I have a square n-by-n matrix of integers. The number of columns is equal to the number of rows.
Each column and row are sorted from the lowest to heights numbers. For example:
[![enter image description here][1]][1]
Another example:
[![enter image description here][2]][2]
I need an algorithm to find wheth... |
[![enter image description here][1]][1]
Let's assume I have graph above with spanning tree pointed out by blue edges.
Vertex at position (1,1) (row 1, column 1) is connected to the bottom vertex and has degree 1.
Vertex at position (4,2) (row 4, column 2) is connected to the up, left and right vertex and has d... |
I have a square n-by-n matrix of integers. The number of columns is equal to the number of rows.
Each column and row are sorted from the lowest to highest numbers. For example:
[![enter image description here][1]][1]
Another example:
[![enter image description here][2]][2]
I need an algorithm to find wheth... |
null |
The solution is in fact easy. See https://www.geeksforgeeks.org/search-in-row-wise-and-column-wise-sorted-matrix/
You start from the top-right element.
- if smaller than the target, you can strike-out the row to the left;
- if larger than the target, you can strike-out the column to the bottom;
- repeat wit... |
Since you have $n$ word, the `put(k,v)` operation needs to be done at least $n$ times. Let's say you have an algorithm that process $D$ in $o(n)$. The algorithm is not considering some words, hence it's not working properly. That's because words have not an ordering or a property that can let any algorithm "skip" some ... |
I would write a function to fill a new tree one record at a time, each record being percolated down by levels. (There will be as many such functions as different orderings that you want to handle.)
Then traverse the existing tree to extract all records and feed them to the filling function.
You said nothing about... |
Let $G$ be a flow network, where $c(e)$ is the capacity of an edge, and the source is $s$ and sink $t$. Define a node $v$ to be "source-like" if for every min-cut $(S,T)$ of $G$ where $S$ contains $s$, $S$ contains $v$. Find an efficient algorithm to determine the source-like nodes.
I was thinking that since For... |
|algorithms|network-flow|ford-fulkerson| |
I would write a function to fill a new tree one record at a time, each record being percolated down by levels. (There will be as many such functions as different orderings that you want to handle.)
Then traverse the existing tree to extract all records and feed them to the filling function.
E.g., if you retrieve ... |
The example given in the question suggests that we want to find the min-cut that is "nearest" to the source $s$.
The answer is "the first" min-cut yielded by a max-flow. More specifically, find a max-flow $f$ of $G$, which can be done efficiently by Ford-Fulkerson algorithm or other algorithms. Let $G_f$ be the resi... |
$L=\{ w \in \{ 0,1 \} \}$ **where $w$ contains at least three ones**
Here is one solution for the productions:
$S \to A1A1A1A$
$A \to 1A | 0A | \epsilon$
However, now I have a question. Could I modify the second rule to be as follows:
$A \to A1 | A0 | \epsilon$
What I did was just switch the places ... |
Design a CFG for $L=\{ w \in \{ 0,1 \}^* \}$, where $w$ contains at least three ones |
|formal-languages|finite-automata|context-free|formal-grammars| |
null |
Yes, you can safely modify the rules for $A$. In this particular case, the order ($A1$ vs. $1A$) makes no difference in the language generated by your grammar. |
Yes, you can safely modify the rules for $A$. In this particular case, the order ($A1$ vs. $1A$) makes no difference in the language generated by your grammar.
The difference is in the way how words are generated (derived) using your grammar.
When the rules for $A$ are the former ($A \to 1A \mid 0A \mid \varepsil... |
That would be
$$\sum_{a\in p}\sum_{b\in p}\delta_{ab}$$
if we assume that you want to count the number of duplicate elements in $p$, using the Kronecker delta notation.
This works for $p$ being a set. In case of a sequence $p_k$ of length $n$,
$$\sum_{i=0}^{n-1}\sum_{j=0}^{n-1}\delta_{p_ip_j}$$ |
The main idea is to sort it from the largest element that basically will appear $n/2$ times, the second largest will appear $n/4$ and continues on until the smallest.
For example after sorting this array $[8,3,2,8,8,8,3]$ it will look like that $[2,3,3,8,8,8,8]$ (where k=3). In order to take out the all appearances ... |
The main idea is to sort it from the largest element that basically will appear $n/2$ times, the second largest will appear $n/4$ and continues on until the smallest.
For example after sorting this array $[8,3,2,8,8,8,3]$ it will look like that $[2,3,3,8,8,8,8]$ (where k=3). In order to take out the all appearances ... |
null |
I suggest you need to understand very carefully Chomsky Hierarchy for $Type-0, Type-1, Type-2, Type-3$ grammar. Then you perceive all the grammar and production rules, restrictions for respective $type.$
Alone the grammar $A \rightarrow 1A|0A|\epsilon$ is under $Type-3$ grammar which is known as Right-Linear-Gramma... |
In his book *The Emperor's New Mind*, Roger Penrose gives an overview of Turing machines in Chapter 2. In his definition of what a Turing machine is he is very minimalist. There is a single linear tape infinite in both directions composed of cells, each of which is either blank or contains a single mark. He represents ... |
How could Penrose's universal Turing machine with a binary alphabet work? |
|turing-machines| |
I suggest you need to understand very carefully Chomsky Hierarchy for $Type-0, Type-1, Type-2, Type-3$ grammar. Then you perceive all the grammar and production rules, restrictions for respective $type.$
Alone the grammar $A \rightarrow 1A|0A|\epsilon$ is under $Type-3$ grammar which is known as Right-Linear-Gramma... |
I suggest you need to understand very carefully Chomsky Hierarchy for $Type-0, Type-1, Type-2, Type-3$ grammar. Then you perceive all the grammar and production rules, restrictions for respective $type.$
Alone the grammar $A \rightarrow 1A|0A|\epsilon$ is under $Type-3$ grammar which is known as Right-Linear-Gramma... |
> It can't overwrite the specification of $T_n$ itself
why wouldn't it? Part of that specification could include tape space for pseudo registers, instruction pointers or other scratch memory space that the turing machine needs to function.
But there is a simpler solution to writing to the left of $m$ (or right of... |
I'm currently working on an exercise that has made me ponder for a bit. I can only credit my Data Structures professor for the content of the task I'm rephrasing, since they
didn't provide any source, but basically:
> Suppose you have a file *D*, for which you want to create an inverted file, *L*, so that for ever... |
I suggest you need to understand very carefully Chomsky Hierarchy for
$Type-0,Type-1,Type-2,Type-3$ grammar. Then you perceive all the grammar and production rules, restrictions for respective $type.$
Alone the grammar $A \rightarrow 1A|0A|\epsilon$ is under $Type-3$ grammar which is known as Right-Linear-Grammar... |
I found [this solution][1] of exercise C-8.28 from Data Structures and Algorithms in Java (6th Edition), but I'm having trouble understanding how the for loop condition works here. The exercise from the book is:
> The **path length** if a tree *T* is the sum of the depths of all positions in *T*. Describe a linear-t... |
What does this condition in the for loop mean? |
|data-structures|loops|java| |
I found [this solution][1] of exercise C-8.28 from Data Structures and Algorithms in Java (6th Edition), but I'm having trouble understanding how the for loop condition works here. The exercise from the book is:
> The **path length** if a tree *T* is the sum of the depths of all positions in *T*. Describe a linear-t... |
I'm currently working on an exercise that has made me ponder for a bit. The following exercise is from the 6th Edition of Data Structures and Algorithms in Java:
> An **inverted file** is a critical data structure for implementing applications such an index of a book or a search engine. Given a document *D*, which c... |
One can overcome the limitations of binary characters by adding new states and treating binary characters as bounded-size groups – rather similarly to how physical computers combine zeroes and ones into bytes, words and beyond.
Suppose you have "all the symbols you'll need" in your alphabet, to implement a Turing ma... |
A complete $k$-CNF formula is a $k$-CNF formula which contains all clauses of size $k$ or lower it implies. Deciding the satisfiability of a complete $k$-CNF formula is clearly a tractable problem since a $k$-CNF formula is satisfiable as long as it does not contain the empty clause.
Given $F$, a complete 3-CNF form... |
Complete-CNF formula and partial assignment |
|complexity-theory|np-complete|satisfiability|decision-problem|complexity-classes| |
null |
I suggest you need to understand very carefully Chomsky Hierarchy for
$Type-0,Type-1,Type-2,Type-3$ grammar. Then you perceive all the grammar and production rules, restrictions for respective $Type.$
Alone the grammar $A \rightarrow 1A|0A|\epsilon$ is under $Type-3$ grammar which is known as Right-Linear-Grammar... |
We have a Turing Machine that cannot write the same symbol it has read in a transition , meaning it should always alter the symbol when passing it , how can we prove that such a machine has equal processing power compared with the standard Turing Machine |
Prove or disprove the equilevancy of a modified Turing Machine |
|turing-machines|automata| |
I found the solution of exercise C-8.28 from Data Structures and Algorithms in Java (6th Edition) on QuizletPlus (a paid site), but I'm having trouble understanding how the for loop condition works here. The exercise from the book is:
> The **path length** if a tree *T* is the sum of the depths of all positions in *... |
I found a solution of exercise C-8.28 from Data Structures and Algorithms in Java (6th Edition), but I'm having trouble understanding how the for loop condition works here.
```
for(Position<E> c : T.children(p))
```
I'm having trouble understanding what the condition in the for loop means. From what I've learn... |
null |
This is called a For-each loop. in your example: `for(Position<E> c : T.children(p))` the **c** is a variable of type **Position\<E>** and it takes it's value in each iterate of the for from a **list** or an **array** or whatever container of type **Position\<E>**, meaning the **T.children(p)** must be a container of t... |
We have a Turing Machine that cannot write the same symbol it has read in a transition, meaning it should always alter the symbol when passing it. How can we prove that such machines have equal processing power compared with the standard Turing Machines? |
Prove the equivalence of the modified Turing Machines and the standard Turing Machines |
|turing-machines|automata|simulation| |
null |
It's not possible. There isn't enough information in the input, even if you had unlimited computing time.
The order of the input is irrelevant. So, we could equivalently specify the input as follows. Each node can be assigned to one of 16 different descriptions (for instance, a node that is connected to one above... |
It is very hard in general [(EXPSPACE-complete][1]) to decide whether the set of reachable markings is finite, even for standard Place/Transition nets without any added features.
What I'd probably do is generate a list of reachable markings with an option for the user to generate more.
[1]: https://www.research... |
Definitely, but you may need something stronger than a standard Place/Transition net.
You could try a tool for colored Petri nets, such as [CPN Tools][1].
[1]: https://cpntools.org/ |
Why can't you find a live and safe marking?
Number the transitions from left to right $t_1,t_2,t_3,t_4,t_5$ and the places from left to right $p_1, \ldots, p_{12}$,
We need to find a firing sequence that is possible, fires all transitions at least once, has net effect zero, and never produces an unsafe marking.
... |
Since a modified Turing machine is a special kind of the standard Turing machine, the power of modified Turing machines is at most that of standard Turing machines.
Now suppose $S$ is a stand Turing machine with $\Gamma$ as its alphabet on tape.
<!-- $\langle Q,\Gamma ,b,\Sigma ,\delta ,q_{0},F\rangle$ -->
Let $... |
Since a modified Turing machine is a special kind of the standard Turing machine, the power of modified Turing machines is at most that of standard Turing machines.
Now suppose $S$ is a stand Turing machine with $\Gamma$ as its alphabet on tape.
<!-- $\langle Q,\Gamma ,b,\Sigma ,\delta ,q_{0},F\rangle$ -->
Let $... |
null |
{"Voters":[{"Id":150715,"DisplayName":"user19121278"}]} |
{"Voters":[{"Id":150715,"DisplayName":"user19121278"}]} |
[![enter image description here][1]][1]
Let's assume I have graph above with spanning tree pointed out by blue edges.
Vertex at position (1,1) (row 1, column 1) is connected to the bottom vertex and has degree 1.
Vertex at position (4,2) (row 4, column 2) is connected to the up, left and right vertex and has d... |
Say you have the finite alphabet {a,b,c,d,e,f,g} and an enumeration of finite strings over it, with the first being the empty string.
What's the most efficient way to get a string from that set by its index number?
Basically, I'm looking for a fast function that takes an integer *x* and returns the *x*th string ... |
Given an ordered list of strings enumerated over a finite alphabet, what's the most efficient way to get a string by its index number? |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.