{
  "index": "2006-A-4",
  "type": "COMB",
  "tag": [
    "COMB",
    "ALG"
  ],
  "difficulty": "",
  "question": "Let $S = \\{1, 2, \\dots, n\\}$ for some integer $n > 1$. Say a permutation\n$\\pi$ of $S$ has a \\emph{local maximum} at $k \\in S$ if\n\\begin{enumerate} % The for parts are aligned in the AMM version\n\\item[(i)]\n$\\pi(k) > \\pi(k+1)$ for $k=1$;\n\\item[(ii)]\n$\\pi(k-1) < \\pi(k)$ and $\\pi(k) > \\pi(k+1)$ for $1 < k < n$;\n\\item[(iii)]\n$\\pi(k-1) < \\pi(k)$ for $k=n$.\n\\end{enumerate}\n(For example, if $n=5$ and $\\pi$ takes values at $1, 2, 3, 4, 5$ of\n$2, 1, 4, 5, 3$, then $\\pi$ has a local maximum of 2 at $k=1$,\nand a local maximum of 5 at $k=4$.)\nWhat is the average number of local maxima of a permutation of $S$,\naveraging over all permutations of $S$?",
  "solution": "\\textbf{First solution:}\nBy the linearity of expectation, the average number of local maxima is equal\nto the sum of the probability of having a local maximum at $k$ over\n$k=1,\\dots, n$.\nFor $k=1$, this probability is 1/2: given the pair\n$\\{\\pi(1), \\pi(2)\\}$, it is equally likely that $\\pi(1)$ or $\\pi(2)$ is\nbigger. Similarly, for $k=n$, the probability is 1/2. For $1 < k < n$,\nthe probability is 1/3: given the pair $\\{\\pi(k-1), \\pi(k), \\pi(k+1)\\}$,\nit is equally likely that any of the three is the largest.\nThus the average number of local maxima is\n\\[\n2 \\cdot \\frac{1}{2} + (n-2) \\cdot \\frac{1}{3} =\n\\frac{n+1}{3}.\n\\]\n\n\\textbf{Second solution:}\nAnother way to apply the linearity of expectation is to compute the\nprobability that $i \\in \\{1, \\dots, n\\}$ occurs as a local maximum.\nThe most efficient way to do this is to imagine the permutation\nas consisting of the symbols $1, \\dots, n, *$ written in a circle in\nsome order. The number $i$ occurs as a local maximum if the two symbols\nit is adjacent to both belong to the set $\\{*, 1, \\dots, i-1\\}$. There are\n$i(i-1)$ pairs of such symbols and $n(n-1)$ pairs in total, so the\nprobability of $i$ occurring as a local maximum is $i(i-1)/(n(n-1))$, and\nthe average number of local maxima is\n\\begin{align*}\n\\sum_{i=1}^n \\frac{i(i-1)}{n(n-1)} &=\n\\frac{2}{n(n-1)} \\sum_{i=1}^n \\binom{i}{2} \\\\\n&= \\frac{2}{n(n-1)} \\binom{n+1}{3} \\\\\n&= \\frac{n+1}{3}.\n\\end{align*}\nOne can obtain a similar (if slightly more intricate)\nsolution inductively, by removing the known\nlocal maximum $n$ and splitting into two shorter sequences.\n\n\\textbf{Remark:}\nThe usual term for a local maximum in this sense is a \\emph{peak}.\nThe complete distribution for the number of peaks is known;\nRichard Stanley suggests the reference:\nF. N. David and D. E. Barton, \\textit{Combinatorial Chance}, Hafner, New York,\n1962, p.\\ 162 and subsequent.",
  "vars": [
    "\\\\pi",
    "k",
    "i"
  ],
  "params": [
    "S",
    "n"
  ],
  "sci_consts": [],
  "variants": {
    "descriptive_long": {
      "map": {
        "S": "setdomain",
        "n": "totalsize",
        "\\pi": "permfunc",
        "k": "position",
        "i": "indexer"
      },
      "question": "Let $setdomain = \\{1, 2, \\dots, totalsize\\}$ for some integer $totalsize > 1$. Say a permutation\n$permfunc$ of $setdomain$ has a \\emph{local maximum} at $position \\in setdomain$ if\n\\begin{enumerate} % The for parts are aligned in the AMM version\n\\item[(indexer)]\n$permfunc(position) > permfunc(position+1)$ for $position=1$;\n\\item[(ii)]\n$permfunc(position-1) < permfunc(position)$ and $permfunc(position) > permfunc(position+1)$ for $1 < position < totalsize$;\n\\item[(iii)]\n$permfunc(position-1) < permfunc(position)$ for $position=totalsize$.\n\\end{enumerate}\n(For example, if $totalsize=5$ and $permfunc$ takes values at $1, 2, 3, 4, 5$ of\n$2, 1, 4, 5, 3$, then $permfunc$ has a local maximum of 2 at $position=1$,\nand a local maximum of 5 at $position=4$.)\nWhat is the average number of local maxima of a permutation of $setdomain$,\naveraging over all permutations of $setdomain$?",
      "solution": "\\textbf{First solution:}\nBy the linearity of expectation, the average number of local maxima is equal\nto the sum of the probability of having a local maximum at $position$ over\n$position=1,\\dots, totalsize$.\nFor $position=1$, this probability is 1/2: given the pair\n$\\{permfunc(1), permfunc(2)\\}$, it is equally likely that $permfunc(1)$ or $permfunc(2)$ is\nbigger. Similarly, for $position=totalsize$, the probability is 1/2. For $1 < position < totalsize$,\nthe probability is 1/3: given the pair $\\{permfunc(position-1), permfunc(position), permfunc(position+1)\\}$,\nit is equally likely that any of the three is the largest.\nThus the average number of local maxima is\n\\[\n2 \\cdot \\frac{1}{2} + (totalsize-2) \\cdot \\frac{1}{3} =\n\\frac{totalsize+1}{3}.\n\\]\n\n\\textbf{Second solution:}\nAnother way to apply the linearity of expectation is to compute the\nprobability that $indexer \\in \\{1, \\dots, totalsize\\}$ occurs as a local maximum.\nThe most efficient way to do this is to imagine the permutation\nas consisting of the symbols $1, \\dots, totalsize, *$ written in a circle in\nsome order. The number $indexer$ occurs as a local maximum if the two symbols\nit is adjacent to both belong to the set $\\{*, 1, \\dots, indexer-1\\}$. There are\n$indexer(indexer-1)$ pairs of such symbols and $totalsize(totalsize-1)$ pairs in total, so the\nprobability of $indexer$ occurring as a local maximum is $\\frac{indexer(indexer-1)}{totalsize(totalsize-1)}$, and\nthe average number of local maxima is\n\\begin{align*}\n\\sum_{indexer=1}^{totalsize} \\frac{indexer(indexer-1)}{totalsize(totalsize-1)} &=\n\\frac{2}{totalsize(totalsize-1)} \\sum_{indexer=1}^{totalsize} \\binom{indexer}{2} \\\\\n&= \\frac{2}{totalsize(totalsize-1)} \\binom{totalsize+1}{3} \\\\\n&= \\frac{totalsize+1}{3}.\n\\end{align*}\nOne can obtain a similar (if slightly more intricate)\nsolution inductively, by removing the known\nlocal maximum $totalsize$ and splitting into two shorter sequences.\n\n\\textbf{Remark:}\nThe usual term for a local maximum in this sense is a \\emph{peak}.\nThe complete distribution for the number of peaks is known;\nRichard Stanley suggests the reference:\nF. N. David and D. E. Barton, \\textit{Combinatorial Chance}, Hafner, New York,\n1962, p.\\ 162 and subsequent."
    },
    "descriptive_long_confusing": {
      "map": {
        "\\\\pi": "journeyed",
        "k": "harmonica",
        "i": "lighthouse",
        "S": "tangerine",
        "n": "porcupine"
      },
      "question": "Let $tangerine = \\{1, 2, \\dots, porcupine\\}$ for some integer $porcupine > 1$. Say a permutation $journeyed$ of $tangerine$ has a \\emph{local maximum} at $harmonica \\in tangerine$ if\n\\begin{enumerate}\n\\item[(i)]\n$journeyed(harmonica) > journeyed(harmonica+1)$ for $harmonica=1$;\n\\item[(ii)]\n$journeyed(harmonica-1) < journeyed(harmonica)$ and $journeyed(harmonica) > journeyed(harmonica+1)$ for $1 < harmonica < porcupine$;\n\\item[(iii)]\n$journeyed(harmonica-1) < journeyed(harmonica)$ for $harmonica=porcupine$.\n\\end{enumerate}\n(For example, if $porcupine=5$ and $journeyed$ takes values at $1, 2, 3, 4, 5$ of\n$2, 1, 4, 5, 3$, then $journeyed$ has a local maximum of 2 at $harmonica=1$,\nand a local maximum of 5 at $harmonica=4$.)\nWhat is the average number of local maxima of a permutation of $tangerine$,\naveraging over all permutations of $tangerine$?",
      "solution": "\\textbf{First solution:}\nBy the linearity of expectation, the average number of local maxima is equal\nto the sum of the probability of having a local maximum at $harmonica$ over\n$harmonica=1,\\dots, porcupine$.\nFor $harmonica=1$, this probability is 1/2: given the pair\n$\\{journeyed(1), journeyed(2)\\}$, it is equally likely that $journeyed(1)$ or $journeyed(2)$ is\nbigger. Similarly, for $harmonica=porcupine$, the probability is 1/2. For $1 < harmonica < porcupine$,\nthe probability is 1/3: given the pair $\\{journeyed(harmonica-1), journeyed(harmonica), journeyed(harmonica+1)\\}$,\nit is equally likely that any of the three is the largest.\nThus the average number of local maxima is\n\\[\n2 \\cdot \\frac{1}{2} + (porcupine-2) \\cdot \\frac{1}{3} =\n\\frac{porcupine+1}{3}.\n\\]\n\n\\textbf{Second solution:}\nAnother way to apply the linearity of expectation is to compute the\nprobability that $lighthouse \\in \\{1, \\dots, porcupine\\}$ occurs as a local maximum.\nThe most efficient way to do this is to imagine the permutation\nas consisting of the symbols $1, \\dots, porcupine, *$ written in a circle in\nsome order. The number $lighthouse$ occurs as a local maximum if the two symbols\nit is adjacent to both belong to the set $\\{*, 1, \\dots, lighthouse-1\\}$. There are\n$lighthouse(lighthouse-1)$ pairs of such symbols and $porcupine(porcupine-1)$ pairs in total, so the\nprobability of $lighthouse$ occurring as a local maximum is $lighthouse(lighthouse-1)/(porcupine(porcupine-1))$, and\nthe average number of local maxima is\n\\begin{align*}\n\\sum_{lighthouse=1}^{porcupine} \\frac{lighthouse(lighthouse-1)}{porcupine(porcupine-1)} &=\n\\frac{2}{porcupine(porcupine-1)} \\sum_{lighthouse=1}^{porcupine} \\binom{lighthouse}{2} \\\\\n&= \\frac{2}{porcupine(porcupine-1)} \\binom{porcupine+1}{3} \\\\\n&= \\frac{porcupine+1}{3}.\n\\end{align*}\nOne can obtain a similar (if slightly more intricate)\nsolution inductively, by removing the known\nlocal maximum $porcupine$ and splitting into two shorter sequences.\n\n\\textbf{Remark:}\nThe usual term for a local maximum in this sense is a \\emph{peak}.\nThe complete distribution for the number of peaks is known;\nRichard Stanley suggests the reference:\nF. N. David and D. E. Barton, \\textit{Combinatorial Chance}, Hafner, New York,\n1962, p.\\ 162 and subsequent."
    },
    "descriptive_long_misleading": {
      "map": {
        "\\pi": "constancy",
        "k": "nonplace",
        "i": "outsider",
        "S": "emptiness",
        "n": "nonnumber"
      },
      "question": "Let $emptiness = \\{1, 2, \\dots, nonnumber\\}$ for some integer $nonnumber > 1$. Say a permutation\n$constancy$ of $emptiness$ has a \\emph{local maximum} at $nonplace \\in emptiness$ if\n\\begin{enumerate}\n\\item[(i)]\n$constancy(nonplace) > constancy(nonplace+1)$ for $nonplace=1$;\n\\item[(ii)]\n$constancy(nonplace-1) < constancy(nonplace)$ and $constancy(nonplace) > constancy(nonplace+1)$ for $1 < nonplace < nonnumber$;\n\\item[(iii)]\n$constancy(nonplace-1) < constancy(nonplace)$ for $nonplace=nonnumber$.\n\\end{enumerate}\n(For example, if $nonnumber=5$ and $constancy$ takes values at $1, 2, 3, 4, 5$ of\n$2, 1, 4, 5, 3$, then $constancy$ has a local maximum of 2 at $nonplace=1$,\nand a local maximum of 5 at $nonplace=4$.)\nWhat is the average number of local maxima of a permutation of $emptiness$,\naveraging over all permutations of $emptiness$?",
      "solution": "\\textbf{First solution:}\nBy the linearity of expectation, the average number of local maxima is equal\nto the sum of the probability of having a local maximum at $nonplace$ over\n$nonplace=1,\\dots, nonnumber$.\nFor $nonplace=1$, this probability is 1/2: given the pair\n$\\{constancy(1), constancy(2)\\}$, it is equally likely that $constancy(1)$ or $constancy(2)$ is\nbigger. Similarly, for $nonplace=nonnumber$, the probability is 1/2. For $1 < nonplace < nonnumber$,\nthe probability is 1/3: given the pair $\\{constancy(nonplace-1), constancy(nonplace), constancy(nonplace+1)\\}$,\nit is equally likely that any of the three is the largest.\nThus the average number of local maxima is\n\\[\n2 \\cdot \\frac{1}{2} + (nonnumber-2) \\cdot \\frac{1}{3} =\n\\frac{nonnumber+1}{3}.\n\\]\n\n\\textbf{Second solution:}\nAnother way to apply the linearity of expectation is to compute the\nprobability that $outsider \\in \\{1, \\dots, nonnumber\\}$ occurs as a local maximum.\nThe most efficient way to do this is to imagine the permutation\nas consisting of the symbols $1, \\dots, nonnumber, *$ written in a circle in\nsome order. The number $outsider$ occurs as a local maximum if the two symbols\nit is adjacent to both belong to the set $\\{*, 1, \\dots, outsider-1\\}$. There are\n$outsider(outsider-1)$ pairs of such symbols and $nonnumber(nonnumber-1)$ pairs in total, so the\nprobability of $outsider$ occurring as a local maximum is $outsider(outsider-1)/(nonnumber(nonnumber-1))$, and\nthe average number of local maxima is\n\\begin{align*}\n\\sum_{outsider=1}^{nonnumber} \\frac{outsider(outsider-1)}{nonnumber(nonnumber-1)} &=\n\\frac{2}{nonnumber(nonnumber-1)} \\sum_{outsider=1}^{nonnumber} \\binom{outsider}{2} \\\\\n&= \\frac{2}{nonnumber(nonnumber-1)} \\binom{nonnumber+1}{3} \\\\\n&= \\frac{nonnumber+1}{3}.\n\\end{align*}\nOne can obtain a similar (if slightly more intricate)\nsolution inductively, by removing the known\nlocal maximum $nonnumber$ and splitting into two shorter sequences.\n\n\\textbf{Remark:}\nThe usual term for a local maximum in this sense is a \\emph{peak}.\nThe complete distribution for the number of peaks is known;\nRichard Stanley suggests the reference:\nF. N. David and D. E. Barton, \\textit{Combinatorial Chance}, Hafner, New York,\n1962, p.\\ 162 and subsequent."
    },
    "garbled_string": {
      "map": {
        "\\pi": "wjkrtbslu",
        "k": "plmrynzqa",
        "i": "sxvdfgkqt",
        "S": "brqcjzpte",
        "n": "gslhdxumv"
      },
      "question": "Let $brqcjzpte = \\{1, 2, \\dots, gslhdxumv\\}$ for some integer $gslhdxumv > 1$. Say a permutation\n$wjkrtbslu$ of $brqcjzpte$ has a \\emph{local maximum} at $plmrynzqa \\in brqcjzpte$ if\n\\begin{enumerate}\n\\item[(i)]\n$wjkrtbslu(plmrynzqa) > wjkrtbslu(plmrynzqa+1)$ for $plmrynzqa=1$;\n\\item[(ii)]\n$wjkrtbslu(plmrynzqa-1) < wjkrtbslu(plmrynzqa)$ and $wjkrtbslu(plmrynzqa) > wjkrtbslu(plmrynzqa+1)$ for $1 < plmrynzqa < gslhdxumv$;\n\\item[(iii)]\n$wjkrtbslu(plmrynzqa-1) < wjkrtbslu(plmrynzqa)$ for $plmrynzqa=gslhdxumv$.\n\\end{enumerate}\n(For example, if $gslhdxumv=5$ and $wjkrtbslu$ takes values at $1, 2, 3, 4, 5$ of\n$2, 1, 4, 5, 3$, then $wjkrtbslu$ has a local maximum of 2 at $plmrynzqa=1$,\nand a local maximum of 5 at $plmrynzqa=4$.)\nWhat is the average number of local maxima of a permutation of $brqcjzpte$,\naveraging over all permutations of $brqcjzpte$?",
      "solution": "\\textbf{First solution:}\nBy the linearity of expectation, the average number of local maxima is equal\nto the sum of the probability of having a local maximum at $plmrynzqa$ over\n$plmrynzqa=1,\\dots, gslhdxumv$.\nFor $plmrynzqa=1$, this probability is 1/2: given the pair\n$\\{wjkrtbslu(1), wjkrtbslu(2)\\}$, it is equally likely that $wjkrtbslu(1)$ or $wjkrtbslu(2)$ is\nbigger. Similarly, for $plmrynzqa=gslhdxumv$, the probability is 1/2. For $1 < plmrynzqa < gslhdxumv$,\nthe probability is 1/3: given the pair $\\{wjkrtbslu(plmrynzqa-1), wjkrtbslu(plmrynzqa), wjkrtbslu(plmrynzqa+1)\\}$,\nit is equally likely that any of the three is the largest.\nThus the average number of local maxima is\n\\[\n2 \\cdot \\frac{1}{2} + (gslhdxumv-2) \\cdot \\frac{1}{3} =\n\\frac{gslhdxumv+1}{3}.\n\\]\n\n\\textbf{Second solution:}\nAnother way to apply the linearity of expectation is to compute the\nprobability that $sxvdfgkqt \\in \\{1, \\dots, gslhdxumv\\}$ occurs as a local maximum.\nThe most efficient way to do this is to imagine the permutation\nas consisting of the symbols $1, \\dots, gslhdxumv, *$ written in a circle in\nsome order. The number $sxvdfgkqt$ occurs as a local maximum if the two symbols\nit is adjacent to both belong to the set $\\{*, 1, \\dots, sxvdfgkqt-1\\}$. There are\n$sxvdfgkqt(sxvdfgkqt-1)$ pairs of such symbols and $gslhdxumv(gslhdxumv-1)$ pairs in total, so the\nprobability of $sxvdfgkqt$ occurring as a local maximum is $sxvdfgkqt(sxvdfgkqt-1)/(gslhdxumv(gslhdxumv-1))$, and\nthe average number of local maxima is\n\\begin{align*}\n\\sum_{sxvdfgkqt=1}^{gslhdxumv} \\frac{sxvdfgkqt(sxvdfgkqt-1)}{gslhdxumv(gslhdxumv-1)} &=\n\\frac{2}{gslhdxumv(gslhdxumv-1)} \\sum_{sxvdfgkqt=1}^{gslhdxumv} \\binom{sxvdfgkqt}{2} \\\\\n&= \\frac{2}{gslhdxumv(gslhdxumv-1)} \\binom{gslhdxumv+1}{3} \\\\\n&= \\frac{gslhdxumv+1}{3}.\n\\end{align*}\nOne can obtain a similar (if slightly more intricate)\nsolution inductively, by removing the known\nlocal maximum gslhdxumv and splitting into two shorter sequences.\n\n\\textbf{Remark:}\nThe usual term for a local maximum in this sense is a \\emph{peak}.\nThe complete distribution for the number of peaks is known;\nRichard Stanley suggests the reference:\nF. N. David and D. E. Barton, \\textit{Combinatorial Chance}, Hafner, New York,\n1962, p.\\ 162 and subsequent."
    },
    "kernel_variant": {
      "question": "Let  n\\ge 2  be an integer and let  \\mathcal B  be an arbitrary set of  n  distinct real numbers (their particular labels are irrelevant).  Arrange the elements of  \\mathcal B  in a row in a uniformly random order.  For a position  k\\in\\{1,\\dots ,n\\}  call the element in that position a \\emph{valley} if\n\\[\n\\begin{cases}\n\\text{(i)} & k=1\\;\\text{ and the first element is smaller than the second;}\\\\[2mm]\n\\text{(ii)} & 1<k<n\\;\\text{ and the element is smaller than both its immediate neighbours;}\\\\[2mm]\n\\text{(iii)}& k=n\\;\\text{ and the last element is smaller than the $(n-1)$st.}\n\\end{cases}\n\\]\n(Thus a valley is a local minimum rather than a local maximum.)  Find the expected number of valleys when the ordering is chosen uniformly at random.",
      "solution": "Label the random ordering by the positions 1,2,…,n. For each position k define the indicator random variable\n\nX_k = \\begin{cases}1,&\\text{if the element at position }k\\text{ is a valley},\\\\0,&\\text{otherwise.}\\end{cases}\n\nBecause the total number of valleys is X = X_1 + … + X_n, linearity of expectation gives\n\nE[X] = \\sum_{k=1}^{n} P(X_k = 1).\n\nWe now determine P(X_k = 1). Since the multiset of values occupying the relevant neighbouring spots is always a collection of distinct numbers, every relative ordering of those numbers is equally likely.\n\n• Endpoints k = 1 and k = n. The element in an endpoint position has only one neighbour. Given the two distinct numbers that occupy positions 1 and 2 (resp. n–1 and n), each is equally likely to be the smaller. Hence\n\nP(X_1 = 1) = P(X_n = 1) = 1/2.\n\n• Interior positions 1 < k < n. Now three distinct numbers occupy the triple (k–1, k, k+1). Every one of these three numbers is equally likely to be the smallest, so\n\nP(X_k = 1) = 1/3  for 1 < k < n.\n\nPutting these probabilities into the earlier sum yields\n\nE[X] = 2·(1/2) + (n–2)·(1/3) = (n + 1)/3.\n\nTherefore the expected number of valleys in a uniformly random arrangement of the n distinct real numbers is\n\n\\boxed{(n+1)/3}.  (By symmetry the same answer holds for local maxima.)",
      "_meta": {
        "core_steps": [
          "Introduce indicator X_k for “is a local max at position k”.",
          "Invoke linearity of expectation:  E(total peaks)=Σ P(X_k=1).",
          "Use symmetry of a random permutation:  for an endpoint, the larger of 2 adjacent values is equally likely (prob. 1/2); for an interior position, the largest of 3 adjacent values is equally likely (prob. 1/3).",
          "Add the endpoint contributions and the (n−2) interior contributions.",
          "Obtain the closed form (n+1)/3."
        ],
        "mutable_slots": {
          "slot1": {
            "description": "The actual set being permuted only needs to consist of n distinct elements; labeling it {1,…,n} is inessential.",
            "original": "S = {1,2,…,n}"
          },
          "slot2": {
            "description": "‘Local maximum’ may be swapped with ‘local minimum’ (replace ‘>’ by ‘<’ everywhere); symmetry makes all probabilities identical.",
            "original": "inequalities use “>” (peak)"
          }
        }
      }
    }
  },
  "checked": true,
  "problem_type": "calculation"
}