instruction
stringlengths
0
29.8k
⌀
I am trying to create the regular expression for the automaton named "full closure" in the following diagram using the arden's theorem: [![enter image description here][1]][1] Since, we have 3 accepting states, we would find 3 different regular expression and then just union them up. I was able to find regular expr...
Suppose I start with a directed graph, and remove any leaf nodes, and then repeatedly remove leaf nodes from the now-modified graph until there are no more leaves. Then I repeatedly remove root nodes as well. What is the remaining graph when there are no more roots or leaves? (Assuming it's not empty.) I have an ide...
What remains after removing leaves and roots from a directed graph?
|graphs|
I am trying to create the regular expression for the automaton named "full closure" in the following diagram using the arden's theorem: [![enter image description here][1]][1] Since, we have 3 accepting states, we would find 3 different regular expression and then just union them up. I was able to find regular expr...
I don't think there is a particular name for this. Indeed, each cycle is contained in this graph, but there also could be some vertices which are not in any cycle, so I am not so sure about the "loopy" name. For example, consider the following graph. No vertex is removed using your transformation, but the vertex $4$...
It should be possible to solve the problem in O(NlogN+M) time. I don't currently have a functional algorithm, but here's an outline of my first thoughts that may help. What I thought of was a mix of DFS and a sweeping line algorithm, starting at a leaf node. A key observation seems to be that starting on all nodes on t...
It should be possible to solve the problem in O(NlogN+M) time. I don't currently have a functional algorithm, but here's an outline of my first thoughts that may help. What I thought of was a mix of DFS and a sweeping line algorithm, starting at a leaf node. A key observation seems to be that starting on all nodes on t...
Let $P = \{P_0, …, P_{n-1}\}$ be the set of pairs returned by your algorithm and $P' = \{P_0', …, P_{n-1}'\}$ be an other set of pairs. Denote $f(P) = \min\limits_{i=1}^n(a_{i,0} + a_{i,1})$ where $P_i = \{a_{i,0}, a_{i,1}\} = \{a_i, a_{2n-i-1}\}$ (I got rid of the $\frac{\cdot}2$ part, because it does not change th...
null
As [Dmitry](https://cs.stackexchange.com/users/141796/dmitry) noticed there is very little possible states of the game, so it's relevant to search for solution using [BFS traversal](https://en.wikipedia.org/wiki/Breadth-first_search). But let's start from some numbers. ### Staring positions In terms of possible sta...
As [Dmitry](https://cs.stackexchange.com/users/141796/dmitry) noticed there is very little possible states of the game, so it's relevant to search for solution using [BFS traversal](https://en.wikipedia.org/wiki/Breadth-first_search). But let's start from some numbers. ### Staring positions In terms of possible sta...
As [Dmitry](https://cs.stackexchange.com/users/141796/dmitry) noticed there is very little possible states of the game, so it's relevant to search for solution using [BFS traversal](https://en.wikipedia.org/wiki/Breadth-first_search). But let's start from some numbers. ### Staring positions In terms of possible sta...
null
Here is the induction step that shows $Sol_k\subset$ some optimal solution. By induction assumption, there is an optimal solution $O_k$ that contains the same pairs as $Sol_k$ except possibly the last pair, $(a[k],a[2n-1-k])$. - If $(a[k],a[2n-1-k])\in O_k$, we are done. - Otherwise, $(a[k],a[2n-1-k])\notin O_k...
Here is the induction step that shows $Sol_k\subset$ some optimal solution. By induction assumption, there is an optimal solution $O_k$ that contains the same pairs as $Sol_k$ except possibly the last pair, $(a[k],a[2n-1-k])$. - If $(a[k],a[2n-1-k])\in O_k$, we are done. - Otherwise, $(a[k],a[2n-1-k])\notin O_k...
null
null
_(Disclaimer: I'm not a computer scientist. I wish more people would address this interesting question.)_ There are quite a few options out there. A number of texts have titles in the lines of _"Introduction to Computer Science"_, _"Fundamentals of Computing"_, etc. For example, I enjoyed reading _CS for All: An ...
_(Disclaimer: I'm not a computer scientist. I wish more people would address this interesting question.)_ There are quite a few options out there. A number of texts have titles in the lines of _"Introduction to Computer Science"_, _"Fundamentals of Computing"_, etc. For example, I enjoyed reading _CS for All: An ...
_(Disclaimer: I'm not a computer scientist. I wish more people would address this interesting question.)_ There are quite a few options out there. A number of texts have titles in the lines of _"Introduction to Computer Science"_, _"Fundamentals of Computing"_, etc. For example, I enjoyed reading _CS for All: An ...
_(Disclaimer: I'm not a computer scientist. I wish more people would address this interesting question.)_ There are many options out there. A few of them have titles in the lines of _"Introduction to Computer Science"_, _"Fundamentals of Computing"_, etc. For example, I enjoyed reading _CS for All: An Introductio...
_(Disclaimer: I'm not a computer scientist. I wish more people would address this interesting question.)_ There are many options out there. A few of them have titles in the lines of _"Introduction to Computer Science"_, _"Fundamentals of Computing"_, etc. For example, I enjoyed reading _CS for All: An Introductio...
_(Disclaimer: I'm not a computer scientist. I wish more people would address this interesting question.)_ There are many options out there. A few of them have titles in the lines of _"Introduction to Computer Science"_, _"Fundamentals of Computing"_, etc. For example, I enjoyed reading _CS for All: An Introductio...
_(Disclaimer: I'm not a computer scientist and have not read most of these books. I wish more people would address this interesting question.)_ There are many options out there. A few of them have titles in the lines of _"Introduction to Computer Science"_, _"Fundamentals of Computing"_, etc. For example, I enjoy...
_(Disclaimer: I'm not a computer scientist and have not read most of these books. I wish more people would address this interesting question.)_ There are many options out there. A few of them have titles in the lines of _"Introduction to Computer Science"_, _"Fundamentals of Computing"_, etc. For example, I enjoy...
null
_(Disclaimer: I'm not a computer scientist and have not read most of these books. I wish more people would address this interesting question.)_ There are many options out there. A few of them have titles in the lines of _"Introduction to Computer Science"_, _"Fundamentals of Computing"_, etc. For example, I enjoy...
As $a^{*}bc^{*}$ and $b^{*}c^{*}$ are subsets of $a^{*}b^{*}c^{*}$ we can write the regular expression as $a^{*}b^{*}c^{*}$.
I think your "inflated polyline" can be correctly defined as a *union* of "inflated line segments". Each such "inflated line segment" will be a rectangle with half-disks on its two opposite ends, describing all points $p \in \Bbb R^2$, such that their distance from the segment is not more than a (configurable) constant...
null
null
We have a simple equation: Number of insertions = number of removals + size of priority queue. If the number of insertions is n, then the heap will be faster as long as the number of removals is at least n / log n. And if the number of removals isn't that large, then your priority queue will grow in size very, very qui...
As [Dmitry](https://cs.stackexchange.com/users/141796/dmitry) noticed there is very little possible states of the game, so it's relevant to search for solution using [BFS traversal](https://en.wikipedia.org/wiki/Breadth-first_search). But let's start from some numbers. ### Staring positions In terms of possible sta...
On the Wikipedia article on Karatsuba algorithm (https://en.wikipedia.org/wiki/Karatsuba_algorithm#Time_complexity_analysis) it is stated: $T(n) = 3 T(\frac{n}{2}) + cn + d$ And then, by invocation of the "master theorem" it is deduced that $T(n) = O(n^{\log_2{3}})$. My question is, is there an easy way in thi...
Derive complexity from recurrence relation
|algorithms|time-complexity|big-o-notation|
Let $P = \{P_0, …, P_{n-1}\}$ be the set of pairs returned by your algorithm and $P' = \{P_0', …, P_{n-1}'\}$ be an other set of pairs. Denote $f(P) = \min\limits_{i=1}^n(a_{i,0} + a_{i,1})$ where $P_i = \{a_{i,0}, a_{i,1}\} = \{a_i, a_{2n-i-1}\}$ (I got rid of the $\frac{\cdot}2$ part, because it does not change th...
_(Disclaimer: I'm not a computer scientist and have not read most of these books. I wish more people would address this interesting question.)_ There are many options out there. A few of them have titles in the lines of _"Introduction to Computer Science"_, _"Fundamentals of Computing"_, etc. For example, I enjoy...
_(Disclaimer: I'm not a computer scientist and have not read most of these books. I wish more people would address this interesting question.)_ There are many options out there. A few of them have titles in the lines of _"Introduction to Computer Science"_, _"Fundamentals of Computing"_, etc. For example, I enjoy...
I have a very specific problem and Im desparate for help, I've been working part time on it for almost a year without almost any success, I'll do my best to describe it as thorough as I can Our input data is an array filled with objects who have properties time and type. From now on I'll refer to them as "events". ...
Distribution of items in ordered list with respect to constraints
|optimization|
I have a very specific problem and Im desparate for help, I've been working part time on it for almost a year without almost any success, I'll do my best to describe it as thorough as I can Our input data is an array filled with objects who have properties time and type. From now on I'll refer to them as "events". ...
Suppose we have a matrix $A$ of dimension $n \times n$ and two vectors $\vec{u}$ and $\vec{v}$ of dimension $n$. Then we have $A\vec{v} = \vec{x}$ with time complexity $O(n^2)$ and space complexity $O(n)$ with the naive algorithm (since the output is a vector of length $n$). (Forgive me if there is a better runti...
Can dot producting the result of vector-matrix multiplication speed up the runtime?
null
_(Disclaimer: I'm not a computer scientist and have not read most of these books. I wish more people would address this interesting question.)_ There are various options out there. Many have titles in the lines of _"Introduction to Computer Science"_, _"Fundamentals of Computing"_, etc. For example, I enjoyed rea...
It is usually up to the compiler what exactly to do, and an "inline" command is just a hint. Inlining is usually a trade between call overhead and the amount of code, and the compiler is in the best position to decide. In addition, the compiler may be able to optimise the code because it knows the parameters at call ti...
Here is a way to solve the recurrence without using the Master theorem and without substitution (which requires guessing the solution). I'll assume for simplicity that $n$ is a power of $2$ and that $T(1) \le c + d$. Consider the recursion tree. Each recursive call will halve the input size, therefore the height of ...
Here is a way to solve the recurrence without using the Master theorem and without substitution (which requires guessing the solution). I'll assume for simplicity that $n$ is a power of $2$ and that $T(1) \le c + d$ (otherwise you can just consider a larger value of $d$). Let's make some simplifications first. They ...
Here is a way to solve the recurrence without using the Master theorem and without substitution (which requires guessing the solution). I'll assume for simplicity that $n$ is a power of $2$ and that $T(1) \le c + d$ (otherwise you can just consider a larger value of $d$). Let's make some simplifications first. They ...
Here is a way to solve the recurrence without using the Master theorem and without substitution (which requires guessing the form of the solution). I'll assume for simplicity that $n$ is a power of $2$ and that $T(1) \le c + d$ (otherwise you can just consider a larger value of $d$). Let's make some simplifications ...
Set $n=2^m$. The recurrence now writes $$T(2^m)=3T(2^{m-1})+2^mc+d$$ or $$S(m)=3S(m-1)+2^mc+d.$$ A solution of the homogeneous recurrence ($S(m)=3S(m-1)$) is $S(m)=3^m$ and this makes us set, by variation of the constant $$S(m)=3^mR(m),$$ giving $$R(m)=R(m-1)+\frac{2^mc+d}{3^m}.$$ The solution is easi...
Set $n=2^m$. The recurrence now writes $$T(2^m)=3T(2^{m-1})+2^mc+d$$ or $$S(m)=3S(m-1)+2^mc+d.$$ A solution of the homogeneous recurrence ($S(m)=3S(m-1)$) is $S(m)=3^m$ and this makes us set, by variation of the constant $$S(m)=3^mR(m),$$ giving $$R(m)=R(m-1)+\frac{2^mc+d}{3^m}.$$ The solution is easi...
null
I can't seem to get my head around the formulas to use for size of binary tree. Depending on who I ask, what website, etc. <br>I see different similar answers. So if someone could explain simply either: the differences between these formulas, the cases to use one or another, or any other explanation. It would be gre...
Size and height of binary tree, different interpretations?
|algorithms|time-complexity|binary-trees|
For $h=1$, all three formulas give different sizes, so it suffices to build a tree of height $1$ and count the nodes. If no formula gives the correct answer, question the definitions of $h$ and $n$. ---------- The formula for the height is obtained by inversion. $n=f(h)\iff h=f^{-1}(n)$.
You need to define $h$ and $n$ first to use any of the formulas. Consider $h$ starting from $0$, i.e. root is at height $0$. $2^h$ gives the number of nodes for given height $h$ and $2^{h+1}-1$ gives the maximum number of nodes in the same binary tree(a complete binary tree of height $h$). And for the rest as you...
Of course, but let me show the process on simpler example and then just use same method for calculating final count. ### Small example We are given $2 \times 2$ square grid and two colors (black and white). We are trying to find out number of different coloring of this grid. Obviously, there are $2^4 = 16$ possib...
You need to define $h$ and $n$ first to use any of the formulas. Consider $h$ starting from $0$, i.e. root is at height $0$. $2^h$ gives the number of nodes at given height $h$ and $2^{h+1}-1$ gives the maximum number of nodes in the same binary tree(a complete binary tree of height $h$). And for the rest as you ...
You need to define $h$ and $n$ first to use any of the formulas. Consider $h$ starting from $0$, i.e. root is at height $0$. $2^h$ gives the maximum number of nodes at given height $h$ and $2^{h+1}-1$ gives the maximum number of nodes in the same binary tree(a complete binary tree of height $h$). And for the rest...
First, let us start with some definitions: - the size of a binary tree $T$, often denoted $|T|$, is the number of nodes. I believe it is what you called $n$ in your post. The size of a binary tree can be computed by induction using: - the size of the empty tree is $0$; - the size of a node $N(l, r)$ is $1 + |...
You need to define $h$ and $n$ first to use any of the formulas. Consider $h$ starting from $0$, i.e. root is at height $0$. $2^h$ gives the maximum number of nodes at given height $h$ and $2^{h+1}-1$ gives the maximum number of nodes in a complete binary tree of height $h$. And for the rest as you mentioned, tak...
First, let us start with some definitions: - the size of a binary tree $T$, often denoted $|T|$, is the number of nodes. I believe it is what you called $n$ in your post. The size of a binary tree can be computed by induction using: - the size of the empty tree is $0$; - the size of a node $N(l, r)$ is $1 + |...
_(Disclaimer: I'm not a computer scientist and have not read most of these books. I wish more people would address this interesting question.)_ There are various options out there. Many of them have titles in the lines of _"Introduction to Computer Science"_, _"Fundamentals of Computing"_, etc. For example, I enj...
DFAs can be minimized. The minimal DFA for a regular language is unique up to isomorphism. So you can compare them by walking both transition graphs in parallel, in the same order, e.g. depth-first. As soon as you find a mismatch, the DFAs aren't isomorphic; once you've visited all states and transitions without any mi...
null
null
DFAs can be minimized. The minimal DFA for a regular language is unique up to isomorphism. So you can compare them by walking both transition graphs in parallel, in the same order, e.g. depth-first. As soon as you find a mismatch, the DFAs aren't isomorphic; once you've visited all states and transitions without any mi...
_(Disclaimer: I'm not a computer scientist and have not read most of these books. I wish more people would address this interesting question.)_ There are various options out there. Many of them have titles in the lines of _"Introduction to Computer Science"_, _"Fundamentals of Computing"_, etc. For example, I enj...
I am reading about Kruskal and analysing it’s time complexity. Let’s say there are E edges and V vertices. Kruskal algorithm has two important time complexity equations , 1. Sort edges- Elog(E) 2. For whether edge from v1->v2 , apply find(v1) and find(v2). If cycle exist don’t connect. Other wise connect them. ...
Does it make sense to apply path compression to kruskal algorithm?
|time-complexity|minimum-spanning-tree|union-find|disjoint-sets|
You can apply path compression, as the structure Union-Find does not change the structure of the graph at all (with or without path compression). The structure is only there to check efficiently if two vertices are in the same connected component, but the "edges" in the tree representation of the structure union fin...
_(Disclaimer: I'm not a computer scientist and have not read most of these books. I wish more people would address this interesting question.)_ There are various options out there. Many of them have titles in the lines of _"Introduction to Computer Science"_, _"Fundamentals of Computing"_, etc. For example, I enj...
I want to split the main part(like people) in optical flow from the background, but I don't konw how to start. I think one way is to use some kind of clustering algorithm, first splite the optical flow image into small patches, define the distance function and use clustering algorithm to aggregate them. But I don't ...
What might be a suitable clustering algorithm to split different parts in dense optical flow?
|algorithms|computer-vision|clustering|
I want to split the main part(like people) in optical flow from the background, but I don't konw how to start. I think one way is to use some kind of clustering algorithm, first split the optical flow image into small patches, define the distance function and use clustering algorithm to aggregate them. But I don't k...
I want to split the main part(like people) in optical flow from the background, but I don't konw how to start. I think one way is to use some kind of clustering algorithm, first split the optical flow image into small patches, define the distance function and use clustering algorithm to aggregate them. But I don't k...
I want to split the main part(like people) in optical flow from the background, but I don't konw how to start. I think one way is to use some kind of clustering algorithm, first split the optical flow image into small patches, define the distance function and use clustering algorithm to aggregate them. But I don't k...
Of course, but let me show the process on simpler example and then just use same method for calculating final count. ### Small example We are given $2 \times 2$ square grid and two colors (black and white). We are trying to find out number of different coloring of this grid. Obviously, there are $2^4 = 16$ possib...
null
the following question came up in a problem I am working on: Suppose you have two graphs $G_1=(V_1, E_1), G_2=(V_2,E_2)$ that have features attached to them, i.e. to every $v\in V_1$ or $v\in V_2$ there is a vector $w_v\in\mathbb R^n$ with fixed $n$ of features mapped to, and similarly for all edges. We call two of ...
Largest isomorphic subgraphs of two graphs with features
|graphs|graph-isomorphism|features|subgraphs|
null
This isn't what you asked, but let me start by saying that I suspect the answer they're looking for in the question you link is (D), "A LR(0) parser can parse any regular grammar". That statement is clearly false; an LR(0) grammar can only parse languages with the "prefix property", which holds if no sentence in the...
This isn't what you asked, but let me start by saying that I suspect the answer they're looking for in the question you link is (D), "A LR(0) parser can parse any regular grammar". That statement is clearly false; an LR(0) grammar can only parse languages with the "prefix property", which holds if no sentence in the...
Besides the recursive calls, the function `recursive_insert` does not require local variables, hence no extra space. The arguments are `nums`, `left`, `right`, and two situations could arise: - the whole of `nums` is copied on every call, causing $n$ elements to be stored on the stack, for a total of $n\log n$ ex...
Answer: `Y.νZ.[](Y | pZ)`, which corresponds to CTL formula `AFAG p`. **Long answer to 1st question**<br/> For this answer I use the def of alternation depth taken from Handbook on Model Checking, Chapter 26. For instance, the formula `Y.(<>Y | νZ.(<>(Zp)))` has alternation depths ad(Y)=ad(Z)=1, so the AD of the ...
# Problem Description Given $a, b, n \in \mathbb{N}$ with $a < b < n$. Let $M$ be the set of all possible bit strings of length $n$ which begin and end with one and have at least $a$ and at most $b$ zeros between two successive ones: $$ AZ_s(x, y) :\equiv s_{x} = s_{x+1} = \ldots = s_{y} = 0 \\ M := \left\{s \...
Algorithm to select a random bit string with constraints
|algorithms|probability-theory|randomized-algorithms|probabilistic-algorithms|
Here's a simple solution that runs in O(nk) time. The basic idea is to go through every possible value of x and use DP to calculate the longest increasing subsequence up to each a_i that conforms to the conditions. For each i, there are 3 states: 1. We haven't come across a value of a_i for which a_i != b_i and thus ...
null
I think this can be done using a bit of dynamic programming. First, let us try to solve a different problem, which is computing $|M|$ given $n$, $a$ and $b$. Denote $f(n, a, b)$ this number. Note that a string in $M$ is composed of a $1$, followed by a sequence of substrings of the form $0^k1$, with $k\in \{a, a+1, ...