From c98e56b17450ce45def511b7af50650cb8bbc0b1 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Mon, 18 Aug 2025 11:32:58 -0500 Subject: [PATCH] other post --- src/content/posts/algorithms/proofs.mdx | 46 +++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/content/posts/algorithms/proofs.mdx b/src/content/posts/algorithms/proofs.mdx index 17a8160..32c5a89 100644 --- a/src/content/posts/algorithms/proofs.mdx +++ b/src/content/posts/algorithms/proofs.mdx @@ -45,6 +45,52 @@ $\blacksquare$ --- +## G + +Maximize-F(s): + +1. Compute the prefix sum of zeroes $Z$ and ones $O$ in $s$ +2. Concatenate and sort $Z$ and $O$ into array $S$ +3. Let $first:=\sum_{1\leq i\leq n}i\cdot(n-i+1)$, computed in $O(|s|)$ time +4. Let $second:=\sum_{1\leq i\leq n}S_i\cdot (2\cdot i-n)$, computed in $O(|s|)$ time +5. Return $\frac{first+second}{2}$ + +--- + +*Proof.* + +Let $X$ and $Y$ be the number of occurrences of zeroes and ones in the substring $p$ of $s$. Then, $f(p)=max(X, Y)=\frac{X+Y+|X-Y|}{2}$. The goal is to compute: + +$$ +\begin{align*} +\sum_{1\leq r\leq n}\sum_{1\leq li}$, $|S_{j>i}-S_i|=S_{j>i}-S_i$--the sum is unchanged. Rewriting the second term: + +$$ +\begin{align*} +\sum_{1\leq r\leq n}\sum_{1\leq l