Found problems: 63
2017 CMIMC Computer Science, 8
We have a collection of $1720$ balls, half of which are black and half of which are white, aligned in a straight line. Our task is to make the balls alternating in color along the line. The following greedy algorithm accomplishes that task for $2n$ balls:
\begin{tabular}{l}
1: \textbf{FOR} $i$ \textbf{IN} $[2,3,\dots,2n]$ \\
2: $\quad$ \textbf{IF} balls $i-1$ and $i$ have the same color: \\
3: $\quad\quad$ $j\gets$ smallest index greater than $i$ for which balls $i-1$ and $j$ have different colors \\
4: $\quad\quad$ swap balls $i$ and $j$
\end{tabular}
Given a configuration $C$ of our $1720$ balls, let $\hat{\sigma}(C)$ denote the number of swaps the greedy algorithm takes, and let $\sigma(C)$ denote the minimum number of swaps actually necessary to perform the task. Find the maximum value over all configurations $C$ of $\hat{\sigma}(C)-\sigma(C)$.
2018 CMIMC CS, 7
I give you a function $\textbf{rand}$ that returns a number chosen uniformly at random from $[0,T]$ for some number $T$ that you don't know. Your task is to approximate $T$. You do this by calling $\textbf{rand}$ $100$ times, recording the results as $X_1,X_2,\dots,X_{100}$, and guessing \[\hat{T}=\alpha\cdot\max\{X_1,X_2,\dots,X_{100}\}\] for some $\alpha$. Which value of $\alpha$ ensures that $\mathbb{E}[\hat{T}]=T$?
2018 CMIMC CS, 2
Consider the natural implementation of computing Fibonacci numbers:
\begin{tabular}{l}
1: \textbf{FUNCTION} $\text{FIB}(n)$: \\
2:$\qquad$ \textbf{IF} $n = 0$ \textbf{OR} $n = 1$ \textbf{RETURN} 1 \\
3:$\qquad$ \textbf{RETURN} $\text{FIB}(n-1) + \text{FIB}(n-2)$
\end{tabular}
When $\text{FIB}(10)$ is evaluated, how many recursive calls to $\text{FIB}$ occur?
2018 CMIMC CS, 6
For integer $n\geq 2$ and real $0\leq p\leq 1$, define $\mathcal{W}_{n,p}$ to be the complete weighted undirected random graph with vertex set $\{1,2,\ldots,n\}$: the edge $(i,j)$ will have weight $\min(i,j)$ with probability $p$ and weight $\max(i,j)$ otherwise. Let $\mathcal{L}_{n,p}$ denote the total weight of the minimum spanning tree of $\mathcal{W}_{n,p}$. Find the largest integer less than the expected value of $\mathcal{L}_{2018,1/2}$.
2020 Poland - Second Round, 2.
Let $n$ be a positive integer. Jadzia has to write all integers from $1$ to $2n-1$ on a board, and she writes each integer in blue or red color. We say that pair of numbers $i,j\in \{1,2,3,...,2n-1\}$, where $i\leqslant j$, is $\textit{good}$ if and only if number of blue numbers among $i,i+1,...,j$ is odd. Determine, in terms of $n$, maximal number of good pairs.
2016 CMIMC, 4
Given a list $A$, let $f(A) = [A[0] + A[1], A[0] - A[1]]$. Alef makes two programs to compute $f(f(...(f(A))))$, where the function is composed $n$ times:
\begin{tabular}{l|l}
1: \textbf{FUNCTION} $T_1(A, n)$ & 1: \textbf{FUNCTION} $T_2(A, n)$ \\
2: $\quad$ \textbf{IF} $n = 0$ & 2: $\quad$ \textbf{IF} $n = 0$ \\
3: $\quad$ $\quad$ \textbf{RETURN} $A$ & 3: $\quad$ $\quad$ \textbf{RETURN} $A$ \\
4: $\quad$ \textbf{ELSE} & 4: $\quad$ \textbf{ELSE} \\
5: $\quad$ $\quad$ \textbf{RETURN} $[T_1(A, n - 1)[0] + T_1(A, n - 1)[1],$ & 5: $\quad$ $\quad$ $B \leftarrow T_2(A, n - 1)$ \\
$\quad$ $\quad$ $\quad$ $T_1(A, n - 1)[0] - T_1(A, n - 1)[1]]$ & 6: $\quad$ $\quad$ \textbf{RETURN} $[B[0] + B[1], B[0] - B[1]]$ \\
\end{tabular}
Each time $T_1$ or $T_2$ is called, Alef has to pay one dollar. How much money does he save by calling $T_2([13, 37], 4)$ instead of $T_1([13, 37], 4)$?
2020 CMIMC Combinatorics & Computer Science, 9
Let $\Gamma = \{\varepsilon,0,00,\ldots\}$ be the set of all finite strings consisting of only zeroes. We consider $\textit{six-state unary DFAs}$ $D = (F,q_0,\delta)$ where $F$ is a subset of $Q = \{1,2,3,4,5,6\}$, not necessarily strict and possibly empty; $q_0\in Q$ is some $\textit{start state}$; and $\delta: Q\rightarrow Q$ is the $\textit{transition function}$.
For each such DFA $D$, we associate a set $F_D\subseteq\Gamma$ as the set of all strings $w\in\Gamma$ such that
\[\underbrace{\delta(\cdots(\delta(q_0))\cdots)}_{|w|\text{ applications}}\in F,\]
We say a set $\mathcal D$ of DFAs is $\textit{diverse}$ if for all $D_1,D_2\in\mathcal D$ we have $F_{D_1}\neq F_{D_2}$. What is the maximum size of a diverse set?
2020 CMIMC Combinatorics & Computer Science, 7
Consider a complete graph of $2020$ vertices. What is the least number of edges that need to be marked such that each triangle ($3$-vertex subgraph) has an odd number of marked edges?
2016 CMIMC, 5
We define the $\emph{weight}$ of a path to be the sum of the numbers written on each edge of the path. Find the minimum weight among all paths in the graph below that visit each vertex precisely once:
[center][img]http://i.imgur.com/V99Eg9j.png[/img][/center]
2017 CMIMC Individual Finals, 2
Define
\[f(h,t) =
\begin{cases}
8h & h = t \\
(h-t)^2 & h \neq t.
\end{cases}\]
Cody plays a game with a fair coin, where he begins by flipping it once. At each turn in the game, if he has flipped $h$ heads and $t$ tails and $h + t < 6$, he can choose either to stop and receive $f(h,t)$ dollars or he can flip the coin again; if $h + t = 6$ then the game ends and he receives $f(h,t)$ dollars. If Cody plays to maximize expectancy, how much money, in dollars, can he expect to win from this game?
2025 CMIMC Combo/CS, 8
Divide a regular $8960$-gon into non-overlapping parallelograms. Suppose that $R$ of these parallelograms are rectangles. What is the minimum possible value of $R$?
2016 CMIMC, 2
In concurrent computing, two processes may have their steps interwoven in an unknown order, as long as the steps of each process occur in order. Consider the following two processes:
\begin{tabular}{c|cc}
Process & $A$ & $B$\\
\hline
Step 1 & $x\leftarrow x-4$ & $x\leftarrow x-5$\\
Step 2 & $x\leftarrow x\cdot3$ & $x\leftarrow x\cdot4$\\
Step 3 & $x\leftarrow x-4$ & $x\leftarrow x-5$\\
Step 4 & $x\leftarrow x\cdot3$ & $x\leftarrow x\cdot4$
\end{tabular}
One such interweaving is $A1$, $B1$, $A2$, $B2$, $A3$, $B3$, $B4$, $A4$, but $A1$, $A3$, $A2$, $A4$, $B1$, $B2$, $B3$, $B4$ is not since the steps of $A$ do not occur in order. We run $A$ and $B$ concurrently with $x$ initially valued at $6$. Find the minimal possible value of $x$ among all interweavings.
2018 CMIMC CS, 9
Consider the following modified algorithm for binary search, which we will call $\textit{weighted binary search}$:
\begin{tabular}{l}
01: \textbf{FUNCTION} SEARCH($L$, value) \\
02:$\qquad$ hi $\leftarrow$ $\operatorname{len}(L) - 1$ \\
03:$\qquad$ lo $\leftarrow$ 0 \\
04:$\qquad$ \textbf{WHILE} hi $\geq$ lo \\
05:$\qquad\qquad$ guess $\leftarrow$ $\lfloor w \cdot\text{lo} + (1-w) \cdot \text{hi}\rfloor$ \\
06:$\qquad\qquad$ mid $\leftarrow$ $L[\text{guess}]$ \\
07:$\qquad\qquad$ \textbf{IF} mid $> \text{value}$ \\
08: $\qquad\qquad\qquad$ hi $\leftarrow$ $\text{guess} - 1$ \\
09: $\qquad\qquad$ \textbf{ELSE IF} mid $< \text{value}$ \\
10: $\qquad\qquad\qquad$ lo $\leftarrow$ $\text{guess} + 1$ \\
11: $\qquad\qquad$ \textbf{ELSE} \\
12: $\qquad\qquad\qquad$ \textbf{RETURN} guess \\
13:$\qquad$ \textbf{RETURN} -1 (not found)
\end{tabular}\\
Assume $L$ is a list of the integers $\{1,2,\ldots,100\}$, in that order. Further assume that accessing the $k$th index of $L$ costs $k+1$ tokens (e.g. $L[0]$ costs $1$ token). Let $S$ be the set of all $w\in[\tfrac12,1)$ which minimize the average cost when $\texttt{value}$ is an integer selected at random in the range $[1,50]$. Given that $S=\left(x,\tfrac {74}{99}\right]$, determine $x$.
2016 CMIMC, 7
Given the list \[A=[9,12,1,20,17,4,10,7,15,8,13,14],\] we would like to sort it in increasing order. To accomplish this, we will perform the following operation repeatedly: remove an element, then insert it at any position in the list, shifting elements if necessary. What is the minimum number of applications of this operation necessary to sort $A$?
2016 CMIMC, 1
For how many distinct ordered triples $(a,b,c)$ of boolean variables does the expression $a \lor (b \land c)$ evaluate to true?
2025 CMIMC Combo/CS, 6
Consider a $4 \times 4$ grid of squares. We place coins in some of the grid squares so that no two coins are orthogonally adjacent, and each $2 \times 2$ square in the grid has at least one coin. How many ways are there to place the coins?
2016 CMIMC, 1
A $\emph{planar}$ graph is a connected graph that can be drawn on a sphere without edge crossings. Such a drawing will divide the sphere into a number of faces. Let $G$ be a planar graph with $11$ vertices of degree $2$, $5$ vertices of degree $3$, and $1$ vertex of degree $7$. Find the number of faces into which $G$ divides the sphere.
2016 CMIMC, 2
The $\emph{Stooge sort}$ is a particularly inefficient recursive sorting algorithm defined as follows: given an array $A$ of size $n$, we swap the first and last elements if they are out of order; we then (if $n\ge3$) Stooge sort the first $\lceil\tfrac{2n}3\rceil$ elements, then the last $\lceil\tfrac{2n}3\rceil$, then the first $\lceil\tfrac{2n}3\rceil$ elements again. Given that this runs in $O(n^\alpha)$, where $\alpha$ is minimal, find the value of $(243/32)^\alpha$.
2018 CMIMC CS, 4
Consider the grid of numbers shown below.
20 01 96 56 16
37 48 38 64 60
96 97 42 20 98
35 64 96 40 71
50 58 90 16 89
Among all paths that start on the top row, move only left, right, and down, and end on the bottom row, what is the minimum sum of their entries?
2017 CMIMC Computer Science, 2
We are given the following function $f$, which takes a list of integers and outputs another list of integers. (Note that here the list is zero-indexed.)
\begin{tabular}{l}
1: \textbf{FUNCTION} $f(A)$ \\
2: $\quad$ \textbf{FOR} $i=1,\ldots, \operatorname{length}(A)-1$: \\
3: $\quad\quad$ $A[i]\leftarrow A[A[i]]$ \\
4: $\quad\quad$ $A[0]\leftarrow A[0]-1$ \\
5: $\quad$ \textbf{RETURN} $A$
\end{tabular}
Suppose the list $B$ is equal to $[0,1,2,8,2,0,1,7,0]$. In how many entries do $B$ and $f(B)$ differ?
2018 CMIMC CS, 1
Consider the following two vertex-weighted graphs, and denote them as having vertex sets $V=\{v_1,v_2,\ldots,v_6\}$ and $W=\{w_1,w_2,\ldots,w_6\}$, respectively (numbered in the same direction and way). The weights in the second graph are such that for all $1\le i\le 6$, the weight of $w_i$ is the sum of the weights of the neighbors of $v_i$.
Determine the sum of the weights of the original graph.
2025 CMIMC Combo/CS, 5
Consider a $12$-card deck containing all four suits of $2, 3,$ and $4.$ A [i]double[/i] is defined as two cards directly next to each other in the deck, with the same value. Suppose we scan the deck left to right, and whenever we encounter a double, we remove all the cards up to that point (including the double). Let $N$ denote the number of times we have to remove cards. What is the expected value of $N$?
2025 CMIMC Combo/CS, 9
Let $p(k)$ be the probability that if we choose a uniformly random subset $S$ of $\{1, 2, \ldots, 18\},$ then $|S| \equiv k \pmod{5}.$ Evaluate $$\sum_{k=0}^4 \left|p(k)-\frac{1}{5}\right|.$$
2019 CMIMC, 10
Define a [i]rooted tree[/i] to be a tree $T$ with a singular node designated as the [i]root[/i] of $T$. (Note that every node in the tree can have an arbitrary number of children.) Each vertex adjacent to the root node of $T$ is itself the root of some tree called a [i]maximal subtree[/i] of $T$.
Say two rooted trees $T_1$ and $T_2$ are [i]similar[/i] if there exists some way to cycle the maximal subtrees of $T_1$ to get $T_2$. For example, the first pair of trees below are similar but the second pair are not. How many rooted trees with $2019$ nodes are there up to similarity?
[center]
[img=500x100]https://i.imgur.com/8axcDvz.png[/img]
[/center]
2016 CMIMC, 10
Given $x_0\in\mathbb R$, $f,g:\mathbb R\to\mathbb R$, we define the $\emph{non-redundant binary tree}$ $T(x_0,f,g)$ in the following way:
[list=1]
[*]The tree $T$ initially consists of just $x_0$ at height $0$.
[*]Let $v_0,\dots,v_k$ be the vertices at height $h$. Then the vertices of height $h+1$ are added to $T$ by: for $i=0,1,\dots,k$, $f(v_i)$ is added as a child of $v_i$ if $f(v_i)\not\in T$, and $g(v_i)$ is added as a child of $v_i$ if $g(v_i)\not\in T$.
[/list]
For example, if $f(x)=x+1$ and $g(x)=x-1$, then the first three layers of $T(0,f,g)$ look like:
[asy]
size(100);
draw((-0.1,-0.2)--(-0.4,-0.8),EndArrow(size=3));
draw((0.1,-0.2)--(0.4,-0.8),EndArrow(size=3));
draw((-0.6,-1.2)--(-0.9,-1.8),EndArrow(size=3));
draw((0.6,-1.2)--(0.9,-1.8),EndArrow(size=3));
label("$0$",(0,0));
label("$1$",(-.5,-1));
label("$-1$",(.5,-1));
label("$2$",(-1,-2));
label("$-2$",(1,-2));[/asy]
If $f(x)=1024x-2047\lfloor x/2\rfloor$ and $g(x)=2x-3\lfloor x/2\rfloor+2\lfloor x/4\rfloor$, then how many vertices are in $T(2016,f,g)$?