Tuesday, August 9, 2022
AtCoder shananigans
Thursday, August 4, 2022
Programming again
Saturday, July 23, 2022
More programming problems
- number of '(' = number of ')',
- for every prefix: number of '(' $\geq$ number of ')'.
Saturday, July 16, 2022
Reviewing codeforces 808
Wednesday, July 13, 2022
Wrapping my head around network sharding
Tuesday, July 5, 2022
Codeforces: The third problem
Saturday, July 2, 2022
Codeforces: Permutation Graph
Wednesday, June 29, 2022
Happy days + learning cryptography
- $G(1^k)$ outputs a secret key of length $k$.
- $E(sk, m)$ takes a secret key and a message and outputs ciphertext.
- $D(sk, m')$ takes a secret key and a ciphertext and outputs plaintext.
- $G(1^k)$ outputs a random string from $\{0,1\}^k$.
- $E(sk, m)$ outputs $m \oplus sk$.
- $D(sk, m')$ outputs $m' \oplus sk$.
Friday, June 17, 2022
Some codeforces problem + a little puzzle
We are given some array $a$ of length $n$ which is initially populated with only $0$'s. We also have a pointer which starts pointed at the first element of $a$. Given the pointer is at position $i$, we can make the following moves:
- add $1$ to $a[i]$ and move the pointer one to the right, or
- subtract $1$ to $a[i]$ and move the pointer one to the left.
- number the glasses from $1$ to $n$.
- for every $g=1$ to $n$, flip all glasses except for glass $g$.
- What about $n>1$ odd? (Conjecture, it is not possible)
- Is our algorithm for even $n$ optimal. (Conjecture, yes)
Line Empire Codeforces
- Move the capital at $x_i$ to any conquered city at $x_j$ for a price of $a\cdot |x_i-x_j|$,
- Conquer an unconquered city at position $x_j$ where our capital is at $x_i$ for a price of $b\cdot |x_i-x_j|$ so long as all cities on path between capital and unconquered city are conquered already.
- We are forced to conquer the cities in the order $x_1, x_2, ..., x_N$ because of the condition that all cities on the path from the capital to the unconquered city must be already conquered.
- The first move must be to conquer $x_1$.
- We never want to move the capital left.
Tuesday, June 14, 2022
String equality
- if we see 'ab' we can change it to 'ba',
- if we see 'bc' we can change it to 'cb'.
Saturday, May 28, 2022
Kickstart: Ants on a stick
This is a twist of the well known ant problem, whereby we can view ants as walking through each other when they meet. In this case, we do not seek the latest time for an ant to fall off the stick, instead we want the order by which they fall off.
The first thing I noticed was that one of the leftmost or rightmost ants, $l$ and $r$ respectively, will fall off first. This is because they will either walk straight off, or they will walk into some ant and then walk towards the end of the stick. Now we just need to decide which of the two falls off first.
Since, we can view the ants as walking past each other when meeting, we know that the $n$ ants fall off the stick at times $t(1),t(2),...,t(n)$, where $t(i)$ is the time that the $i$th ant falls off the stick when it is alone on the stick. Then the first ant will fall off at time $\min_{i}\{t(i)\}$. Let $x$ be the ant which has this minimum value of $t(x)$. If $x$ and $l$ are facing each other, then $l$ will fall off first since $x$ and $l$ will meet at some time, forcing $l$ to fall off the stick first. There are other cases to examine, but we have now made the main observations.
Tuesday, May 17, 2022
Binary string
The problem link is here: https://codeforces.com/contest/1680/problem/C.
My approach and thoughts:
Let b start with $x$ zeros. We simplify the problem to only have deletions from the left side.
Let $s[i]$ denote the number of $1'$s in positions $[0,i)$. We want to delete prefix $[0,i)$ which minimises $\max\{x-(i-s[i]), s[i]\}$.
Monday, February 14, 2022
Generalized analysis of distributed random walk algorithm
We previously described a distributed algorithm for constructing random walks of length $l$ in dynamic graphs which runs in time $\tilde{O}(\sqrt{lD})$, where $D$ is the dynamic diameter. The author's Atish Das Sarma, Anisur Rahaman Molla and Gopal Pandurangan prove their algorithm is correct in the $\mathsf{CONGEST}(\log^2{n})$ model. The reason being that w.h.p the per-round congestion through any edge is $O(\log^2{n})$ bits. Therefore, w.h.p there will be no congestion when constructing the random walks meaning that every round all random walks increase their length by one.
Now suppose we generalise the distributed model the algorithm operates in to the $\mathsf{CONGEST}(B)$ model. Can we adapt their algorithm to work correctly at the cost of $\mathsf{polylog}(n)$ overhead?
First we observe that for $B\in \Omega(\log^2{n})$, the algorithm provided will work as is, because if we have $B\in\Omega(\log^2{n})$ bits of bandwidth per edge and we only need $O(\log^2{n})$ bits with high probability, then there will be no congestion.
If we have $B<c\log^2{n}$ for every constant $c$, then w.h.p we have $O(\frac{\log^2{n}}{B})$ additional rounds due to congestion.
proof. Each edge has bandwidth $B$ bits. We have previously established that w.h.p $\log^2{n}$ bits pass through an edge in each round. Thus $\frac{\log^2{n}}{B}$ additional rounds will be needed w.h.p to account for congestion.
Therefore, for their algorithm to work in the $\mathsf{CONGEST}(B)$ model, we just need to run the first phase of the algorithm for $2\lambda\log^2{n}/B$ rounds, where we give each random walk $\log^2{n}/B$ rounds to extend its length by one edge to account for congestion.
Monday, January 31, 2022
Hitting time analysis on smoothed dynamic graphs
Sunday, January 30, 2022
Distributed random walk algorithm
- connected (otherwise the random walk will never converge to the invariant distribution),
- $d$-regular (ensures invariant distribution remains the same for each $G_t\in \mathcal{G}$, it will remain the uniform distribution),
- non-bipartite (ensures the random walk is aperiodic and therefore converges to the invariant distribution)
Saturday, January 29, 2022
What is the mixing time of a random walk?
We already know that a random walk is a Markov chain with the vertices as its states, and we know that an ergodic Markov chain converges to its invariant distribution. But we do not know how fast. The mixing time is a measure of how quickly it converges. We now formally define this concept.
Def 1: The variation distance between two distributions $D_1$ and $D_2$ on a countable state space $S$ is given by $$||D_1-D_2|| = \frac{1}{2}\sum_{x\in S}{|D_1(x) - D_2(x)|}$$
The factor of one half ensures that the variation distance remains between $0$ and $1$.
Def 2: Let $\pi$ be the invariant distribution of an ergodic Markov chain with state space $S$. Let $p_{x}^t$ represent the distribution of the state of the chain starting at state $x$ after $t$ steps. We define $$\Delta_x(t) = ||p^t_x-\pi||$$ and $$\Delta(t) = \max_{x\in S}{\Delta_x(t)}$$
So $\Delta_x(t)$ is the variation distance between the invariant distribution and $p^t_x$, and $\Delta(t)$ is the maximum of these. Now we can define the mixing time.
Def 3: Similarly we defined $$\tau_x(\epsilon) = \min\{t: \Delta_x(t)\leq \epsilon \}$$ and $$\tau(\epsilon)=\max_{x\in S}{\tau_x(\epsilon)}$$ where $\tau_x(\epsilon)$ is the first time when the variation distance between $p^t_x$ and the invariant distribution is $\leq \epsilon$ and $\tau(\epsilon)$ is the maximum of these. $\tau(\epsilon)$ is called the mixing time.
We say that a Markov chain is rapidly mixing if $\tau(\epsilon)$ is polynomial in $\log(1/\epsilon)$ and the size of the problem.
Monday, January 24, 2022
Random walks against adaptive dynamic graphs
Project Goal
- hitting time of a random walk in a dynamic graph.
- cover time of a random walk in a dynamic graph.
- mixing time of a random walk in a dynamic graph.
- smoothed versions of these.
- computing hitting, cover and mixing times on various dynamic graphs by simulation.
- application of distributed random walks to solve $k$-gossip.
- other applications of distributed random walks.
Thursday, January 20, 2022
Random walks on graphs
- the chain has a unique invariant distribution $\pi=(\pi_0,\pi_1, ..., \pi_n)$
- for all $i$ and $j$, in the limit $\lim_{t\to\inf}{P^{t}_{j,i}}$ exists and it is independent of $j$
- $\pi_i=\lim_{t\to\inf}{P^{t}_{j,i}}=1/h_{i,i}$, where $h_{i,j}$ is the expected time for the Markov chain to go from state $i$ to $j$.
AtCoder shananigans
Here is the problem , and below is the raw transcript of my thoughts. Obs: It is always optimal to use all $K$ moves. intuitive proof. While...
-
We are given $N$ cities on an integer number line at positions $0<x_1<x_2<...<x_N$, where our capital is initially at position 0...
-
The problem is essentially, given $2\leq n\leq 10^5$ people, where the $i^{\text{th}}$ person has a skill level of $b_i$ in billiards and $p...
-
We are given a permutation of $1,2,...,n$, $a_1, a_2, ..., a_n$. Construct the undirected graph with vertex set $1, 2, ..., n$ and $(i, j)$ ...
