instruction
stringlengths
0
29.8k
⌀
|dynamic-programming|sorting|greedy-algorithms|
null
Consider an algorithm with the following recursion $$ T(n) \leq T(n/3) + T(2n/3) + \mathcal O(n)$$ for its running time. I understand that $T(n) = \mathcal O(n \log n)$ by drawing the recursion tree and seeing that every level takes time $n$, and that the depth of the tree is $\log_{3/2} n$. But, why is this upper boun...
Understanding why this upper bound is tight
|algorithm-analysis|asymptotics|big-o-notation|
Suppose there exist such $w_1, ..., w_n$ (without loss of generality all words have length more than $0$). There exist such $k$, that $2^k>k^n$. There are $2^k$ words of length $k$ in language $\{0,1\}$ and not more than $k^n$ words of length $k$ in language represented by given regular expression.
null
What you write is tight in the sense that if you have no additional information than the recurrence you wrote, then you cannot hope to prove any better asymptotic upper bound. To see this consider: $$ T'(n) = T'(n/3) + T'(2n/3 ) + n, $$ and notice that this could be the case in your recurrence. The associate ...
What you write is tight in the sense that if you have no additional information than the recurrence you wrote, then you cannot hope to prove any better asymptotic upper bound. To see this consider: $$ T'(n) = T'(n/3) + T'(2n/3 ) + n, $$ and notice that this could be the case in your recurrence. The associate ...
null
null
null
I am studying term rewriting using Baader and Nipkow's book "Term Rewriting and All That". I am trying to solve the following exercise about word problems: > **4.1** Give a trivial example of a finite set of identities $E$ such that the ground word problem for $E$ is decidable, but the word problem is not. My i...
Give a finite set of identities $E$ such that the ground word problem is decidable, but the word problem is not
|term-rewriting|
null
null
There is a class exercise question asking about global sink in a directed graph. Finding normal sink is not difficult but the conditions of the question have made me stuck on this question. The question wants an algorithm that runs linearly. Can you please provide a hint. Thank you [![enter image description...
gragh Global Sink Algorithm
|graphs|depth-first-search|
There is a path from every vertex $u$ to some vertex $v$ in graph $G$ if and only if there is a path from $v$ to all vertices $u$ in the reversed graph $G^{R}$.
null
Remember that the heuristic is always _under-estimating_ the cost from a node to the target, which means that a higher cost (closer to the true value) is always a more accurate cost. For example, suppose that your landscape is a grid (like Manhattan) with some potential road-blocks. Then you can let the heuristic f...
**1) Take the **"Stair Case" Problem** for instance:** If I was given a problem like this on a test after mastering "Fibbionacci Series" and "Factorial Implementation", I would not be able to solve it, despite the fact that "Stair Case" problem boils down to "Fibbionacci Series". I wouldn't know that it is essentially ...
What is the standerd procedure when approaching a competative coding problem?
|algorithms|
What is the proper way to approach a competative coding problem?
What is the proper way to approach a competitive coding problem?
**1) Take the **"Stair Case" Problem** for instance:** If I was given a problem like this on a test after mastering "Fibbionacci Series" and "Factorial Implementation", I would not be able to solve it, despite the fact that "Stair Case" problem boils down to "Fibbionacci Series"; I wouldn't know that it is essentially ...
**1) Take the **"Stair Case" Problem** for instance:** If I was given a problem like this on a test after mastering "Fibbionacci Series" and "Factorial Implementation", I would not be able to solve it, despite the fact that "Stair Case" problem boils down to "Fibbionacci Series"; I wouldn't know that it is essentially ...
null
**1) Take the **"Stair Case" Problem** for instance:** If I was given a problem like this on a test after mastering "Fibbionacci Series" and "Factorial Implementation", I would not be able to solve it, despite the fact that "Stair Case" problem boils down to "Fibbionacci Series"; I would not know that it resembles the ...
**1) Take the **"Stair Case" Problem** for instance:** If I was given a problem like this on a test after mastering "Fibbionacci Series" and "Factorial Implementation", I would not be able to solve it, despite the fact that "Stair Case" problem boils down to "Fibbionacci Series"; I would not know that it resembles the ...
**1) Take the **"Stair Case" Problem** for instance:** If I was given a problem like this on a test after mastering "Fibbionacci Series" and "Factorial Implementation", I would not be able to solve it, despite the fact that "Stair Case" problem boils down to "Fibbionacci Series"; I would not know that it resembles the ...
Some sources state that an algorithm that solves the SAT problem not only needs to decide whether a given existentially-quantified formula is satisfiable or not, but, additionally, in the case where the formula is satisfiable, it does need to provide a satisfying assignment. Is this true or not? I am bit confused, ...
null
|algorithms|data-structures|dynamic-programming|
**1) Take the **"Climbing Stairs" Problem** for instance:** If I was given a problem like this on a test after mastering "Fibbionacci Series" and "Factorial Implementation", I would not be able to solve it, despite the fact that "Climbing Stairs" problem boils down to "Fibbionacci Series"; I would not know that it rese...
> 1. How do you deal with situations where you are given a problem which you have never seen before? You sit down with a pen and a paper and draw out examples and counter-examples. Then you recognize patterns. There are many algorithmic techniques that you can use or try first. Does greedy work? Does the problem...
Your problem isn’t calculating gcd’s, your problem is the number of pairs you need to examine. If your algorithm isn’t clever then given some x, you’ll have to examine all y whether they are connected. This will take O(n) for each x. Throw out all x > n and x <= g first. If one of your numbers is less than g then t...
We receive a stream of $n$ integer numbers: $x_1, x_2,\dots, x_n$. Assume that each $x_i$ is a constant and can be stored with $O(1)$ bits. Whenever a new number $x_i, i \geq 2$ is inputted, we need to evaluate and output the sum: $$ S_i := \sum_{j=1}^{i-1} |x_i - x_j|$$ After outputting it we receive $x_{i+1}$ etc...
Compute sum of moduli for a stream of integer numbers
|streaming-algorithm|summation|metrics|
I'm working on a game where there are several different entities represented by nodes. Each node has a starting balance, and directed edges show where money is owed from one account to another. One problem I'm trying to figure out is how to figure out which order to process transactions in, take this example below: ...
Directed graph of bank balances and transactions, how to process transactions?
|algorithms|graphs|directed-graphs|
We receive a stream of $n$ integer numbers: $x_1, x_2,\dots, x_n$. Assume that each $x_i$ is a constant and can be stored with $O(1)$ bits. Whenever a new number $x_i, i \geq 2$ is inputted, we need to evaluate and output the sum: $$ S_i := \sum_{j=1}^{i-1} |x_i - x_j|$$ After outputting it we receive $x_{i+1}$ etc...
I'm working on a game where there are several different entities represented by nodes. Each node has a starting balance, and directed edges show where money is owed from one account to another. One problem I'm trying to figure out is which order to process transactions in, take this example below: [![Initial bala...
I am a research scholar working in parameterized algorithms. For more information on parameterized complexity please refer to <a href="https://en.wikipedia.org/wiki/Parameterized_complexity"> this</a>. Recently, I have come across a problem which is known to be NP-complete on split graphs. Now, it has come to my attent...
Query on distance to parameter in parameterized complexity
|np-hard|parameterized-complexity|
This feels like homework, so I'll just give a hint. Let $G$ be a split graph. What is the value of your parameter $d$ then? What is then the meaning of $f(d) \cdot n^{O(1)}$?
It is a common way to prove that a problem is para-NP-hard for some parameter by proving it is NP-hard on a class with constant value of the parameter. Indeed an $O(f(k)n^c)$ algorithm would imply an $O(f(c’)n^c)$ algorithm for this problem on the given class which is impossible assuming NP not equal P. An example w...
Depending on your rules, here's a greedy algorithm: Maintain a priority queue of all nodes where the value in the queue is _how many debts they are able to pay down_. Let the debt for each player be sorted by value. Pop off a player $X$. If $X$ can pay, pop off the first debt. Then update the recipient's balan...
The function $$\sum(x_i-x)^2$$ is quadratic in $x$ and can be represented by a constant number of parameters. It has $3$ degrees of freedom. But the function $$\sum|x_i-x|$$ is piecewise linear and requires the knowledge of all $x_i$'s. It has $n$ degrees of freedom. So the answer is negative. IMO, this is...
It is a common way to prove that a problem is para-NP-hard for some parameter by proving it is NP-hard on a class with constant value of the parameter. Indeed an $O(f(k)n^c)$ algorithm would imply an $O(f(c’)n^c)$ algorithm for this problem on the given class which is impossible assuming NP not equal P. An example w...
The function $$\sum(x_i-x)^2$$ is quadratic in $x$ and can be represented by a constant number of parameters. It has $3$ degrees of freedom. But the function $$\sum|x_i-x|$$ is piecewise linear and requires the knowledge of all $x_i$'s. It has $n$ degrees of freedom. So the answer is negative.
*\*\*\*Climbing Stairs Problem: https://leetcode.com/problems/climbing-stairs/* **1) Take the **"\*\*\*Climbing Stairs" Problem** for instance:** If I was given a problem like this on a test after mastering "Fibbionacci Series" and "Factorial Implementation", I would not be able to solve it, despite the fact that "C...
In [this paper][1], the author discusses colourings of the plane, or in other words, of the underlying graph. Although I think I understand what a finite colouring is (being a colouring using at most $k$ colours for some natural number $k$), what do countable and measurable colourings mean? Does the former perhaps mean...
What are the definitions of countable and measurable colourings of a graph?
|graphs|counting|colorings|uncountability|
null
I suppose those are mathematics terms (since the considered graph is infinite). [Countable](https://en.wikipedia.org/wiki/Countable_set) means you can count those colorings with integers (there is a bijection with $\mathbb{N}$). [Measurable](https://en.wikipedia.org/wiki/Measure_(mathematics)#Definition) means yo...
null
In [this paper][1], the author discusses colourings of the plane, or in other words, of the underlying graph. Although I think I understand what a finite colouring is (being a colouring using at most $k$ colours for some natural number $k$), what do countable and measurable colourings mean? Does the former perhaps mean...
As mentioned in a comment, this program is a variant on [Zeller's congruence][1]. Here are the steps: 0. It's good to know that the Gregorian calendar (which is what we are using) repeats every 400 years. In the 400 year cycle, every fourth year is a leap year except for the centuries other than the one at the st...
In [this paper][1], the author discusses colourings of the plane, or in other words, of the underlying graph. I suppose a finite colouring is a colouring using at most $k$ colours for some natural number $k$. However, what do countable and measurable colourings mean? Does the former perhaps mean that any vertex of the ...
A countable colouring of the plane $\mathbb{R}^2$ is just a function $c : \mathbb{R}^2 \to \mathbb{N}$, meaning we have countably many distinct colours available to us. The notion of measurable colouring is a bit ambiguous, it could mean either Borel-measurable or Lebesgue-measurable. A colouring $c : \mathbb{R}^2 \...
By using limits, show that log n! ∈ Θ(n logn). Using Stirling's approximation for n! I get the limit: $$\lim_{n \to ∞} \frac{log({\sqrt{2πn}}*(\frac{n}{e})^n)}{nlogn} = constant > 0$$ When I break this down separately: $$\lim_{n \to ∞} \frac{\sqrt{2πn}}{n^n} * \lim_{n \to ∞} (\frac{n}{e})^n = constant > 0$$ ...
Using limits to determine asymptotic bound
|asymptotics|
You are indeed right that you cannot rewrite the limit like that. Let $f(n)$ and $g(n)$ be two functions. Then $$\lim_{n \to \infty} f(n)g(n) = \lim_{n \to \infty} f(n) \cdot \lim_{n \to \infty} f(n)$$ only holds if $\lim_{n \to \infty} f(n)$ and $\lim_{n \to \infty} f(n)$ exist and are either both finite, or one ...
$$\log\left(\sqrt{2\pi n}\left(\dfrac ne\right)^n\right)=\log\sqrt{2\pi}+\frac12\log n +n\log n-n.$$ Celarly, this expression is dominated by the term $n\log n$ and your limit is $1$.
You have some algebra mistake but, in general, you are right that you cannot always rewrite a limit of products as the products of limits. Let $f(n)$ and $g(n)$ be two functions. Then $$\lim_{n \to \infty} f(n)g(n) = \lim_{n \to \infty} f(n) \cdot \lim_{n \to \infty} f(n)$$ only holds if $\lim_{n \to \infty} f(n)$...
$$\log\left(\sqrt{2\pi n}\left(\dfrac ne\right)^n\right)=\log\sqrt{2\pi}+\frac12\log n +n\log n-n.$$ Clearly, this expression is dominated by the term $n\log n$ and your limit is $1$.
A countable colouring of the plane $\mathbb{R}^2$ is just a function $c : \mathbb{R}^2 \to \mathbb{N}$, meaning we have countably many distinct colours available to us. The notion of measurable colouring is a bit ambiguous, it could mean either Borel-measurable or Lebesgue-measurable. A colouring $c : \mathbb{R}^2 \...
You broke this down, but in a very unpractical way. $\log {(n/e)^n} = n \log (n /e) = n (\log n - 1)$ is much more helpful.
I read that if $\alpha$ is the fraction of the code that cannot be made parallel then it is desirable that $\alpha < \frac 1 p$ where $p$ is the number of processors. Why is it the case?
Desirable fraction of non-parallelizable code in Amdahl's law
|parallel-computing|
I read that if $\alpha$ is the fraction of the code that cannot be made parallel then it is desirable that $\alpha < \frac 1 p$ where $p$ is the number of processors. Why is it the case? The speed-up is $S(p) = \frac{T_1}{T_p} = \frac{p}{1+(p-1)\alpha}$
null
I am stuck at the following exercise: > Consider a directed graph $G = (V, A)$ with start vertex $s ∈ V$, target vertex $t ∈ V$ and weights $w_{ij} \in \mathbb{R}$ for each arc $(i, j)$. For any $i \in V$ let further be $\pi_i \in \mathbb{R}$ be the so-called **potential** of $i$. The potential difference $\tau_{ij}...
The length of the shortest $s$-$t$ path equals the maximum tenstion between $s$ and $t$
|graphs|optimization|shortest-path|
null
In the following algorithm $A[1..n]$ denotes an array $A$ of size $n$, of $n$ distinct integers. Func1() and Func2() are functions that run in $\mathcal O(\log n)$ and $\mathcal O(n)$ time, respectively. Foo(A[1..n]) if n == 1: return while (True) { Func1() ...
What is the expected time complexity of this algorithm?
|algorithm-analysis|runtime-analysis|randomized-algorithms|
In the following algorithm $A[1..n]$ denotes an array $A$ of size $n$, of $n$ distinct integers. Func1() and Func2() are functions that run in $\mathcal O(\log n)$ and $\mathcal O(n)$ time, respectively. Foo(A[1..n]) if n == 1: return while (True) { Func1() ...
null
When $\alpha=\dfrac1p$, the speedup is $$\dfrac{p^2}{2p-1}\sim50\%\,p$$ so the processors are well utilized.
I want to sort the list of parameters (p1, p2, p3, p4, ..., pn) according to the importance. All parameters have to be compared with each other at best once, but not less than once. Person will be asked to select the winner of the comparison, so every compare there is only 1 winner. The workflow should be simila...
Compare list of parameters with each other and sort them from most to least selected
|algorithms|sorting|comparison|
How do we write an unrestricted grammar for $$L = \{a^n \ | \ n \ \text{is prime}\}$$ I know that $L$ is neither regular, nor context-free. Also, I know how to build a Turing Machine for $L$. The idea is to use two tapes, one having $n$ ones, and the other having $m$ ones. The TM checks if $m$ divides $n$. If it...
Grammar for prime length strings
|formal-languages|formal-grammars|
null
The statement in the exercise, "If $P^\ast$ is a path for which the maximum in $\mathcal{P}$ is achieved, the value $\sum_{(i,j) \in P^\ast} \tau_{ij}$ is referred to as **maximum tension** between $s$ and $t$." is indeed quite confusing. As you have pointed out, given $i\to\pi_i$ for all $i\in V$ and $\tau_{ij}=\p...