instruction
stringlengths
0
29.8k
⌀
|terminology|programming-languages|
null
null
null
This is an algorithm I came up with, so I'm not sure that is was known before. It is essentially a modification of the walk-based filling method that you mentioned. I'll give a high-level description, with possibly more details to come later. --- The idea is that we will possibly divide the original region to f...
null
This is an algorithm I came up with, so I'm not sure that is was known before. It is essentially a modification of the walk-based filling method that you mentioned. I'll give a high-level description, with possibly more details to come later. **EDIT...Please see the edit below** --- The idea is that we will ...
null
null
null
null
null
Given vectors $A, B \in \mathbb{R}^{n}$, $w \in [0,1]$ and $x \in \mathbb{R}$, let $$ Rank(A,B,w,x)=\sum_{i=1}^{n} \boldsymbol 1 \{w A_{i} +(1-w) B_{i} < x\} $$ denote the number of elements in the $w$-weighted convex combination of $A$ and $B$ that are smaller than $x$. I would like to compute $Rank(A,B,w,x)$...
Rank in a Convex Combination
|algorithms|time-complexity|data-structures|probability-theory|
I have been trying to solve questions like this before but I have stumbled in difficulty to track the the space of the cache. so there is an example of a question like this: Given the code: int A[1024,1024],B[1024,1024],C[1024,1024] for(int i=0;i<1024;i++){ for(int j=0;j<1024;j++){ ...
I have been trying to solve questions like this before but I have stumbled in difficulty to track the the space of the cache. so there is an example of a question like this: Given the code: int A[1024,1024],B[1024,1024],C[1024,1024] for(int i=0;i<1024;i++){ for(int j=0;j<1024;j++){ ...
Your cache has 512 cache lines (512 x 64Byte cache line size = 32Kilobyte cache size). In the innermost loop, each value k accesses a different row of the array, with each row being 1024 x 4 = 4,096, so each k accesses a different cache line. You therefore access 1024 different cache lines, your processor only has ...
null
Given two players $A, B$ and some natural number $n \ge 2$, let $\#(A,B,n)$ denote the following algorithm: > $A$ thinks of some number $a \in \{1,\ldots,n\}$ > > Until the game ends: > > > $B$ thinks of some number $b \in \{1,\ldots,n\}$ > > > > $B$ tells $b$ to $A$ > > > > If $a = b$ then the game ends ...
Create a Turing machine for this interactive game
|algorithms|turing-machines|computation-models|
The complete question is as follows: > An edge of a flow network is called critical if decreasing the > capacity of this edge results in a decrease in the maximum flow. Give > an efficient algorithm that finds a critical edge in a network. I believe some variation of Ford-Fulkerson would have to be used over he...
How to find a crticial edge in a flow network?
|algorithms|ford-fulkerson|
|algorithms|graphs|network-flow|ford-fulkerson|
null
By the [max-flow min-cut theorem](https://en.wikipedia.org/wiki/Max-flow_min-cut_theorem) the (maximum) flow $f$ between two vertices $s$ and $t$ in the network is equal to the overall weight of the edges in a minimum $s$-$t$-cut $C$. The means that it suffices to find a minimum $s$-$t$-cut $C$ and return any edge $...
I would go with the following program to achieve what you're looking for: ```java import java.util.*; class Applicant { public String name = ""; public List<String> titles = new ArrayList<>(); public Applicant(String name, String... titles) { this.name = name; this.titles = Array...
{"Voters":[{"Id":150483,"DisplayName":"Metropola Official"}]}
{"Voters":[{"Id":150483,"DisplayName":"Metropola Official"}]}
I have searched around for some time but couldn't find a similar example to my problem. It looks common enough that I would expect it to be solved. It lies between search and optimization/regression. Assume we have a matrix with Yi and corresponding set of features Xi (say around 40). Number of samples relativel...
Combinatorial search/optimization of matrix with features with custom constrains on the set
|optimization|combinatorics|search|
I have one LP problem (LP1) to solve, where a term in a constraint is to be substituted after solving another LP problem (LP2) (with a different variable vector). Sippose I call the dimension of the variable vector in LP1 as $n$ and in LP2 as $m$. I know that the complexity of solving an LP problem is $O(n^3L)$ ($L$ is...
How about induction on languages? **Proof**. Assume that for every subset of $A$ the statement holds. Then there are two cases to consider: 1. Suppose $A = \varnothing$. Then $|A \bullet B| = |\varnothing \bullet B| = |\varnothing| = 0 \leq |\varnothing| \cdot |B| = 0$. 2. Suppose $A = S \cup T$, for any two d...
null
null
null
null
Suppose that you were writing down the syntax rules for something like **C++** as a [context-free grammar][1] in [Backus–Naur Normal Form][2] How can you distinguish between the pipe character as symbol in **C++** or as a Backus–Naur symbol? Equivalently, how would you tell whether the `|` character represented a...
How can we escape the pipe character in Backus–Naur Normal Form?
|formal-languages|context-free|formal-grammars|compilers|parsers|
null
Suppose that you were reading some production rules for a [context-free grammar][1] in [Backus–Naur Normal Form][2] What does the asterisk (`*`) mean? In the example below, what is the difference between `<fun-def*>` and `<fun-def>`? ```lang-none <program> ::= <fun-def*> int main(void) { <block> } <blo...
What role does an asterisk serve in Backus–Naur Normal Form?
|formal-languages|context-free|formal-grammars|parsers|syntax|
null
null
You can answer each query in $O(\log n)$ time, using a [sweepline algorithm](https://en.wikipedia.org/wiki/Sweep_line_algorithm) combined with a [persistent](https://en.wikipedia.org/wiki/Persistent_data_structure) [self-balancing binary tree](https://en.wikipedia.org/wiki/Self-balancing_binary_search_tree). Since $...
You can answer each query in $O(\log n)$ time, using a [sweepline algorithm](https://en.wikipedia.org/wiki/Sweep_line_algorithm) combined with a [persistent](https://en.wikipedia.org/wiki/Persistent_data_structure) [self-balancing binary tree](https://en.wikipedia.org/wiki/Self-balancing_binary_search_tree). Since $...
I have never seen this syntax before, but most likely, `<var-def*>` is a typo for (or unusual way of writing) `<var-def>*`. A common extension of BN is to use the `*` operator from regular expressions. In other words, `<var-def>*` represents 0 or more instances of `<var-def>`. This does not increase the expressive...
I suggest you read up on BNF. For instance, you could start with the Wikipedia article: https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form. Often, we put literal characters in quotes, so `"|"` represents a `|` pipe symbol in the C++ program (i.e., a terminal to be matched during grammar parsing), and `|` represen...
null
I'm really having rough time understanding the time complexities of nested loops. So, please help me out in this code. The code is on sliding window with changing length: ``` def smallest_subarray_sum(s, arr): window_sum = 0 min_length = math.inf window_start = 0 for window_end in range(0, len...
what is the time complexity of this while loop nested in a for loop?
|big-o-notation|
Let $k,n \in \mathbb{N} $ and non empty sets $X_1, X_2, \dots, X_n \subseteq \{1,2,\dots,k\}$. Define the change counting cost function $f: X_1 \times X_2 \times \dots \times X_n \to \mathbb{N}$ by $f(x_1, x_2, \dots, x_n) = \sum_{i=2}^n\delta(i)$ where $\delta(i) = 1$ if $x_i \neq x_{i-1}$ and otherwise $0$ ...
Given a sequence of sets, choose one element from each to get the lowest number of changes
|assignment-problem|
I have searched around for some time but couldn't find a similar example to my problem. It looks common enough that I would expect it to be solved. It lies between search and optimization/regression. Assume we have a matrix with Yi and corresponding set of features Xi (say around 40). Number of samples relativel...
I have searched around for some time but couldn't find a similar example to my problem. It looks common enough that I would expect it to be solved. It lies between search and optimization/regression. Assume we have a matrix with Yi and corresponding set of features Xi (say around 40). Number of samples relativel...
For every I = 1 to n, and for every x in xi, calculate the cheapest sequence for the first I sets ending in x. For I = 1 it is trivial, every sequence has cost 0. To find the cheapest sequence for I+1 sets ending in x, the cost is either the cheapest sequence for I sets ending in x or the cost of any sequence f...
I'm asked to find all equivalence classes of the language $$L = \{0^n1^n: n \in \mathbb{N}_0 \}$$ where $\mathbb N_0$ is the set of natural numbers including $0$, i.e., $0, 1, 2, \cdots.$ We have the following definition: $$(xR_Ly)\Leftrightarrow (\forall w\in \Sigma^* xw\in L \Leftrightarrow yw\in L)$$ As...
Find Myhill–Nerode equivalence classes of language $\{0^n1^n: n \in \mathbb{N}_0 \}$
For string $s$, call a string $e$ an extender of $s$ (with respect to $L$) if $es$ in $L$. $x$ and $y$ are in the same equivalence class iff (a string is an extender of $x$ iff it is an extender of $y$). Let us describe some sets. - Let $O_{k}=\{0^k\}, \ \text{ where } k \in \mathbb N_0$. For any strin...
null
null
In any given year,a male automobile insurance policyholder make a claim with probability $p_m$ and a female automobile insurance policy holder will make a claim with a probability $p_f$ where $p_f \not= p_m$. The fraction of the automobile insurance policyholders that are male is $\alpha, 0 < \alpha < 1. $ A autom...
Conditional probability of making claim by insurance policyholder
|probability-theory|
Given an optimization problem $P$, if we know that this optimization problem is NP-hard, is it necessary to check the complexity of the corresponding feasibility problem, i.e. the complexity of checking if the problem admits a feasible solution? Because in the case of $P$ the problem is not always feasible.
Complexity of the feasibility and optimization problems
|complexity-theory|np-complete|np-hard|
In any given year,a male automobile insurance policyholder make a claim with probability $p_m$ and a female automobile insurance policy holder will make a claim with a probability $p_f$ where $p_f \not= p_m$. The fraction of the automobile insurance policyholders that are male is $\alpha, 0 < \alpha < 1. $ A autom...
I have searched around for some time but couldn't find a similar example to my problem. It looks common enough that I would expect it to be solved. It lies between search and optimization/regression. Assume we have a matrix with Yi and corresponding set of features Xi (say around 40). Number of samples relativel...
I believe that something like the [KITTI dataset][1] is what you are looking for. It is a large dataset made for Autonomous Vehicle Research. You can download after providing your email. You can also try looking at the raw [KITTI data][2]. <br> <br> The [bdd100k][3] dataset from [Berkley][4] is another good...
Assuming we are observing an algorithm.I am confused as to how one needs to proof correctness. What exactly the correctness represent for a given algorithm? And why do we have to proof correctness, in case, correctness itself describes or points out that the algorithm does exactly what we want it to do. Basically...
Correctness vs Proof of Correctness
|algorithms|correctness-proof|
Say that a programming language is **general-purpose** if all computable tasks can be programmed in it. It is worthwhile having such langauges, for the same reason that it is worthwhile having a universal computing machine. Every general-purpose programming language is Turing complete, because by design it can expre...
I claim that this algorithm returns the integer square root of any integer in the range 1 to 1000: Sqrt(int X) { return 0 } Is it correct ? How can you convince me that it is correct (or incorrect) ? What about Sqrt(int X) { int Y= 1, Z= 0; while Y != Z: ...
I claim that this algorithm returns the integer square root of any integer in the range 1 to 1000: Sqrt(int X) return 0 Is it correct ? How can you convince me that it is correct (or incorrect) ? What about Sqrt(int X) int Y= 1, Z= 0; while Y != Z: Z= Y; Y= (X ...
null
You can just greedily take the element of the first set that appears in the most consecutive sets (decide equals randomly). That's the first element of your solution. Then do the same for the next set after those consecutive sets.
[![enter image description here][1]][1] [1]: https://i.stack.imgur.com/Y3syD.png (from 'An Introduction to Formal Languages and Automata' by Peter Linz) What I do not understand, is why we have done our best to make sure that the condition (8.2) holds. Why is this restriction important/useful?
Pumping lemma for context-free languages: Importance of length restriction
|formal-languages|automata|context-free|
Suppose given two $n$ bits numbers $A$ and $B$. Also suppose there is a machine that compute multiply two $\sqrt{n}$ bits numbers in $O(1)$. What is time complexity of multiplying two $n$ bits number in a such case? I think we can use divide and conquer [Karatsuba algorithm ][1] such that our recursion tree will ...
Recurrence relation of multiply two $n$ bit numbers
|algorithms|
null
null
The complexity in terms of the number of logarithm evaluations is expressed by the *iterated logarithm* function. There is no better expression. Note the following values: $$[0,1]\to0\\(1,2]\to1\\(2,4]\to2\\(4,16]\to3\\(16,65536]\to4\\(65536,2.003529930406\cdots\times10^{19728}]\to5\\\cdots$$
null
The author did not say $$x+2x+\cdots+nx=n^2x.$$ He said $$x+2x+\cdots+nx=\frac{n(n+1)}2x$$ so that $$x+2x+\cdots+nx=O(n^2x).$$ If you don't know the meaning of the asymptotic notation $O$, read https://en.wikipedia.org/wiki/Big_O_notation. Notice that $1+2=\dfrac{2\cdot(2+1)}2$ is quite right.
You could refer to the following video, as it discusses the questions that David Hilbert asked and resolved by Gödel and Turing. https://www.youtube.com/watch?v=HeQX2HjkcNo
null
The restriction is definitely useful. It provides you with an additional guarantee on the structure of the decomposition of $w$, which you can exploit in your proofs. For example the language $L = \{a^n b^k c^n d^k \mid n, k \ge 0\}$ is not context-free and a possible proof using the pumping lemma is as follows: sup...
null