{"id":416,"date":"2021-08-11T00:51:00","date_gmt":"2021-08-11T00:51:00","guid":{"rendered":"http:\/\/www.ethanepperly.com\/?p=416"},"modified":"2021-08-11T00:51:00","modified_gmt":"2021-08-11T00:51:00","slug":"why-randomized-algorithms","status":"publish","type":"post","link":"https:\/\/www.ethanepperly.com\/index.php\/2021\/08\/11\/why-randomized-algorithms\/","title":{"rendered":"Why Randomized Algorithms?"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<p>In this post, I want to answer a simple question: <em>how can randomness help in solving a deterministic (non-random) problem?<\/em><\/p>\n\n\n\n<p>Let&#8217;s start by defining some terminology. An <em>algorithm<\/em> is just a precisely defined procedure to solve a problem. For example, one algorithm to compute the integral of a function <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-c23e757cb6bd08fe194e942085387dcd_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#102;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"10\" style=\"vertical-align: -4px;\"\/> on the interval <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-76562478d920e62fd22b998039d40967_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#091;&#48;&#44;&#49;&#093;\" title=\"Rendered by QuickLaTeX.com\" height=\"18\" width=\"32\" style=\"vertical-align: -5px;\"\/> is to pick 100 equispaced points <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-105cc362cacdcf78a39fd31b33584491_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#48;&#32;&#61;&#32;&#120;&#95;&#49;&#32;&#60;&#32;&#92;&#116;&#102;&#114;&#97;&#99;&#123;&#49;&#125;&#123;&#49;&#48;&#48;&#125;&#32;&#61;&#32;&#120;&#95;&#50;&#32;&#60;&#32;&#92;&#116;&#102;&#114;&#97;&#99;&#123;&#50;&#125;&#123;&#49;&#48;&#48;&#125;&#32;&#61;&#32;&#120;&#95;&#51;&#32;&#60;&#92;&#99;&#100;&#111;&#116;&#115;&#60;&#92;&#116;&#102;&#114;&#97;&#99;&#123;&#57;&#57;&#125;&#123;&#49;&#48;&#48;&#125;&#61;&#120;&#95;&#123;&#49;&#48;&#48;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"22\" width=\"377\" style=\"vertical-align: -6px;\"\/> on this interval and output the Riemann sum <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-0362b9e07d80ceaf42c753c531ec9362_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#116;&#102;&#114;&#97;&#99;&#123;&#49;&#125;&#123;&#110;&#125;&#32;&#92;&#115;&#117;&#109;&#95;&#123;&#106;&#61;&#49;&#125;&#94;&#123;&#49;&#48;&#48;&#125;&#32;&#102;&#40;&#120;&#95;&#106;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"25\" width=\"100\" style=\"vertical-align: -8px;\"\/>. A <em>randomized algorithm<\/em> is simply an algorithm which uses, in some form, randomly chosen quantities. For instance, a randomized algorithm<sup class=\"modern-footnotes-footnote \" data-mfn=\"1\" data-mfn-post-scope=\"000000000000057e0000000000000000_416\"><a href=\"javascript:void(0)\"  role=\"button\" aria-pressed=\"false\" aria-describedby=\"mfn-content-000000000000057e0000000000000000_416-1\">1<\/a><\/sup><span id=\"mfn-content-000000000000057e0000000000000000_416-1\" role=\"tooltip\" class=\"modern-footnotes-footnote__note\" tabindex=\"0\" data-mfn=\"1\">This randomized algorithm is an example of the strategy of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Monte_Carlo_integration\">Monte Carlo integration<\/a>, which has proved particularly effective at computing integrals of functions on high-dimensional spaces.<\/span> for computing integrals would be to pick 100 random points <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-c3d3ec069d9d099ef30665c8058cd971_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#88;&#95;&#49;&#44;&#92;&#108;&#100;&#111;&#116;&#115;&#44;&#88;&#95;&#123;&#49;&#48;&#48;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"98\" style=\"vertical-align: -4px;\"\/> uniformly distributed in the interval <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-76562478d920e62fd22b998039d40967_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#091;&#48;&#44;&#49;&#093;\" title=\"Rendered by QuickLaTeX.com\" height=\"18\" width=\"32\" style=\"vertical-align: -5px;\"\/> and output the average <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-dd6868e0467ed09c7f7e5b8188c4e5f1_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#116;&#102;&#114;&#97;&#99;&#123;&#49;&#125;&#123;&#110;&#125;&#32;&#92;&#115;&#117;&#109;&#95;&#123;&#106;&#61;&#49;&#125;&#94;&#123;&#49;&#48;&#48;&#125;&#32;&#102;&#40;&#88;&#95;&#106;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"25\" width=\"105\" style=\"vertical-align: -8px;\"\/>. To help to distinguish, an algorithm which does not use randomness is called a <em>deterministic algorithm<\/em>.<\/p>\n\n\n\n<p>To address the premise implicit in our central question, there are problems where randomized algorithms provably outperform the best possible deterministic algorithms.<sup class=\"modern-footnotes-footnote \" data-mfn=\"2\" data-mfn-post-scope=\"000000000000057e0000000000000000_416\"><a href=\"javascript:void(0)\"  role=\"button\" aria-pressed=\"false\" aria-describedby=\"mfn-content-000000000000057e0000000000000000_416-2\">2<\/a><\/sup><span id=\"mfn-content-000000000000057e0000000000000000_416-2\" role=\"tooltip\" class=\"modern-footnotes-footnote__note\" tabindex=\"0\" data-mfn=\"2\">Examples abound in <a href=\"https:\/\/twitter.com\/BooleanAnalysis\/status\/1365297029505835011?s=20\">online decision making<\/a>, <a href=\"https:\/\/en.wikipedia.org\/wiki\/Communication_complexity#Randomized_communication_complexity\">distributed computation<\/a>, <a href=\"https:\/\/arxiv.org\/pdf\/2010.09649\">linear algebra in the matrix-vector query model<\/a>, and in simple computational models like <a href=\"https:\/\/twitter.com\/BooleanAnalysis\/status\/1365297029505835011?s=20\">single tape Turing machines<\/a>.<\/span> Additionally, even for problems for which randomized algorithms have not been <em>formally proven<\/em> to outperform deterministic ones, the best randomized algorithms we know for many problems dramatically outperform the best-known deterministic algorithms. For example, testing whether an <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-75a5652acadcd645b180a972b75a9d09_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#110;\" title=\"Rendered by QuickLaTeX.com\" height=\"8\" width=\"11\" style=\"vertical-align: 0px;\"\/>-digit number is prime takes roughly <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-979076e8ccb24728ade4e3dcb2d0f8da_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#110;&#94;&#54;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"18\" style=\"vertical-align: 0px;\"\/> operations <a href=\"https:\/\/en.wikipedia.org\/wiki\/Primality_test#Fast_deterministic_tests\">using the best-known deterministic algorithm<\/a> and only roughly <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-13686b36ed5e56ea6998abe1bc940995_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#110;&#94;&#50;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"18\" style=\"vertical-align: 0px;\"\/> operations<a href=\"https:\/\/en.wikipedia.org\/wiki\/Primality_test#Probabilistic_tests\"> allowing randomness<\/a>. The power of randomness extends beyond discrete problems typically considered by computer scientists to continuous problems of interest to computational mathematicians and scientists. For instance, the <a href=\"https:\/\/dl.acm.org\/doi\/abs\/10.1145\/2591796.2591833?casa_token=cD3F0mQ1Yc8AAAAA:S5R6xx11Fu6yHcNOkvK2Z7cepiglL_gm4Bi5rwsnc9rxCzV8xD7ly826SaiP3a_1F1HRQph83Uastg\">(asymptotically) fastest known<\/a> algorithms to solve <a href=\"https:\/\/en.wikipedia.org\/wiki\/Laplacian_matrix\">Laplacian<\/a> linear system of equations use random sampling as a key ingredient. The workhorse optimization routines in machine learning are mostly variants of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Stochastic_gradient_descent\">stochastic gradient descent<\/a>, a randomized algorithm. To list off a few more, randomized algorithms have proven incredibly effective in <a href=\"https:\/\/epubs.siam.org\/doi\/abs\/10.1137\/16M1091745?casa_token=Z1j5A_3N2MkAAAAA:6kaOYyXVI56tscoAegZsZXtoiPLXUdgeufDEDQIlX6Qg9AkbJLBoKOoHrds40JjTUMnpBkAs5A\">solving eigenvalue and singular value problems<\/a>, <a href=\"https:\/\/arxiv.org\/pdf\/2010.09649.pdf\">approximating the trace of a very large matrix<\/a>, <a href=\"https:\/\/epubs.siam.org\/doi\/abs\/10.1137\/090771806?casa_token=rRoACk2kKnsAAAAA:zn-1tnUT5lfZ1B6lF_pYvUQJ3PMNiAf8ArsaTOkBQgfZOtdGejOGbCJxw-PtEIi89NVQ1ukqPg\">computing low-rank approximations<\/a>, <a href=\"https:\/\/arxiv.org\/abs\/1906.07832\">evaluating integrals<\/a>, and <a href=\"https:\/\/www.annualreviews.org\/doi\/abs\/10.1146\/annurev-fluid-060420-023735\">simulating subgrid phenomena in fluid problems<\/a>. <\/p>\n\n\n\n<p>This may seem puzzling and even paradoxical. There is no randomness in, say, a system of linear equations, so why should introducing randomness help solve such a problem? It can seem very unintuitive that leaving a decision in an algorithm up to chance would be better than making an informed (and non-random) choice. Why do randomized algorithms work so well; what is the randomness actually buying us?<\/p>\n\n\n\n<p>A partial answer to this question is that it can be very costly to choose the best possible option at runtime for an algorithm. Often, a random choice is &#8220;good enough&#8221;.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">A Case Study: Quicksort<\/h2>\n\n\n\n<p>Consider the example of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Quicksort\">quicksort<\/a>. Given a list of <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-ec1be7928bcd319c17c1931fbb8059ac_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#78;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"16\" style=\"vertical-align: 0px;\"\/> integers to sort in increasing order, quicksort works by selecting an element to be the pivot and then divides the elements of the list into groups larger and smaller than the pivot. One then recurses on the two groups, ending up with a sorted list.<\/p>\n\n\n\n<p>The best choice of pivot is the median of the list, so one might naturally think that one should use the median as the pivot for quicksort. The problem with this reasoning is that finding the median is time-consuming; even using the fastest possible median-finding algorithm,<sup class=\"modern-footnotes-footnote \" data-mfn=\"3\" data-mfn-post-scope=\"000000000000057e0000000000000000_416\"><a href=\"javascript:void(0)\"  role=\"button\" aria-pressed=\"false\" aria-describedby=\"mfn-content-000000000000057e0000000000000000_416-3\">3<\/a><\/sup><span id=\"mfn-content-000000000000057e0000000000000000_416-3\" role=\"tooltip\" class=\"modern-footnotes-footnote__note\" tabindex=\"0\" data-mfn=\"3\">There is an <a href=\"https:\/\/en.wikipedia.org\/wiki\/Median_of_medians#Proof_of_O(n)_running_time\">algorithm guaranteed to find the median in<\/a> <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-9f813a6a06077d7003933310e3982e2d_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#99;&#97;&#108;&#123;&#79;&#125;&#40;&#78;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"43\" style=\"vertical-align: -5px;\"\/> time, which is asymptotically fast as this problem could possibly be solved since any median-finding algorithm must in general look at the entire list.<\/span>quicksort with exact median pivot selection isn&#8217;t very quick. However, one can show quicksort with a pivot selected (uniformly) at random <a href=\"https:\/\/en.wikipedia.org\/wiki\/Quicksort#Formal_analysis\">achieves the same <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-3eacdd13b0066c46a59bd79cad85be6b_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#99;&#97;&#108;&#123;&#79;&#125;&#40;&#78;&#92;&#108;&#111;&#103;&#32;&#78;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"88\" style=\"vertical-align: -5px;\"\/> <em>expected<\/em> runtime<\/a> as quicksort with optimal pivot selection and is much faster in practice.<sup class=\"modern-footnotes-footnote \" data-mfn=\"4\" data-mfn-post-scope=\"000000000000057e0000000000000000_416\"><a href=\"javascript:void(0)\"  role=\"button\" aria-pressed=\"false\" aria-describedby=\"mfn-content-000000000000057e0000000000000000_416-4\">4<\/a><\/sup><span id=\"mfn-content-000000000000057e0000000000000000_416-4\" role=\"tooltip\" class=\"modern-footnotes-footnote__note\" tabindex=\"0\" data-mfn=\"4\">In fact, <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-51c1aafd4a0eca1a84826f7a66685601_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#99;&#97;&#108;&#123;&#79;&#125;&#40;&#78;&#32;&#92;&#108;&#111;&#103;&#32;&#78;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"88\" style=\"vertical-align: -5px;\"\/> is the fastest possible runtime for any <a href=\"https:\/\/en.wikipedia.org\/wiki\/Sorting_algorithm#Comparison_sorts\">comparison sorting algorithm<\/a>.<\/span>\n\n\n\n<p>But perhaps we have given up on fast deterministic pivot selection in quicksort too soon. What if we just pick the first entry of the list as the pivot? This strategy usually works fairly well too, but it runs into an unfortunate shortfall: if one feeds in a sorted list, the first-element pivot selection is terrible, resulting in a <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-3a183d1e7c22c983ac27554abdb5f510_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#99;&#97;&#108;&#123;&#79;&#125;&#40;&#78;&#94;&#50;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"50\" style=\"vertical-align: -5px;\"\/> algorithm. If one feeds in a list in a random order, the first-element pivot selection has a <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-51c1aafd4a0eca1a84826f7a66685601_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#99;&#97;&#108;&#123;&#79;&#125;&#40;&#78;&#32;&#92;&#108;&#111;&#103;&#32;&#78;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"88\" style=\"vertical-align: -5px;\"\/> <em>expected<\/em> runtime,<sup class=\"modern-footnotes-footnote \" data-mfn=\"5\" data-mfn-post-scope=\"000000000000057e0000000000000000_416\"><a href=\"javascript:void(0)\"  role=\"button\" aria-pressed=\"false\" aria-describedby=\"mfn-content-000000000000057e0000000000000000_416-5\">5<\/a><\/sup><span id=\"mfn-content-000000000000057e0000000000000000_416-5\" role=\"tooltip\" class=\"modern-footnotes-footnote__note\" tabindex=\"0\" data-mfn=\"5\">Another way of implementing randomized quicksort is to first randomize the list and then always pick the first entry as the pivot. This is fully equivalent to using quicksort with random pivot selection in the given ordering. Note that randomizing the order of the list before its sorted is still a randomized algorithm because, naturally, randomness is needed to randomize order.<\/span> but for certain specific orderings (in this case, e.g., the sorted ordering) the runtime is a disappointing <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-3a183d1e7c22c983ac27554abdb5f510_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#99;&#97;&#108;&#123;&#79;&#125;&#40;&#78;&#94;&#50;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"50\" style=\"vertical-align: -5px;\"\/>. The first-element pivot selection is particularly bad since its nemesis ordering is the common-in-practice already-sorted ordering. But other simple deterministic pivot selections are equally bad. If one selects, for instance, the pivot to be the entry in the position <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-2aea8616f29b5203f9af921504279c84_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#108;&#102;&#108;&#111;&#111;&#114;&#32;&#78;&#47;&#50;&#32;&#92;&#114;&#102;&#108;&#111;&#111;&#114;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"43\" style=\"vertical-align: -5px;\"\/>, then we can still come up with an ordering of the input list that makes the algorithm run in time <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-3a183d1e7c22c983ac27554abdb5f510_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#99;&#97;&#108;&#123;&#79;&#125;&#40;&#78;&#94;&#50;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"50\" style=\"vertical-align: -5px;\"\/>. And because the algorithm is deterministic, it runs in <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-3a183d1e7c22c983ac27554abdb5f510_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#99;&#97;&#108;&#123;&#79;&#125;&#40;&#78;&#94;&#50;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"20\" width=\"50\" style=\"vertical-align: -5px;\"\/> time every time with such-ordered inputs. If the lists we need to sort in our code just happen to be bad for our deterministic pivot selection strategy, quicksort will be slow <em>every time<\/em>.<\/p>\n\n\n\n<p>We typically analyze algorithms based on their worst-case performance. And this can often be unfair to algorithms. Some algorithms work excellently in practice but are horribly slow on manufactured examples which never occur in &#8220;real life&#8221;.<sup class=\"modern-footnotes-footnote \" data-mfn=\"6\" data-mfn-post-scope=\"000000000000057e0000000000000000_416\"><a href=\"javascript:void(0)\"  role=\"button\" aria-pressed=\"false\" aria-describedby=\"mfn-content-000000000000057e0000000000000000_416-6\">6<\/a><\/sup><span id=\"mfn-content-000000000000057e0000000000000000_416-6\" role=\"tooltip\" class=\"modern-footnotes-footnote__note\" tabindex=\"0\" data-mfn=\"6\">The <a href=\"https:\/\/en.wikipedia.org\/wiki\/Simplex_algorithm?wprov=sfti1\">simplex algorithm<\/a> is an example of algorithm which is often highly effective in practice, but can take a huge amount of time on some pathological cases.<\/span> But average-case analysis of algorithms, where one measures the average performance of an algorithm over a distribution of inputs, can be equally misleading. If one were swayed by the average-case analysis of the previous section for quicksort with first-element pivot selection, one would say that this should be an effective pivot selection in practice. But sorting an already-sorted or nearly-sorted list occurs <em>all the time<\/em> in practice: how many times do programmers read in a sorted list from a data source and sort it again <em>just to be safe<\/em>? In real life, we don&#8217;t encounter random inputs to our algorithms: we encounter a very specific distribution of inputs specific to the application we use the algorithm in. An algorithm with excellent average-case runtime analysis is of little use to me if it is consistently and extremely slow every time I run it on <em>my<\/em> input data on the problem I&#8217;m working on. This discussion isn&#8217;t meant to disparage average-case analysis (indeed, very often the &#8220;random input&#8221; model is not too far off), but to explain why worst-case guarantees for algorithms can still be important.<\/p>\n\n\n\n<p>To summarize, often we have a situation where we have an algorithm which makes some choice (e.g. pivot selection). A particular choice usually works well for a randomly chosen input, but can be stymied by certain specific inputs. However, we don&#8217;t get to pick which inputs we receive, and it is fully possible the user will always enter inputs which are bad for our algorithms. Here is where randomized algorithms come in. Since we are unable to randomize the <em>input<\/em>, we instead randomize the <em>algorithm<\/em>.<\/p>\n\n\n\n<p>A randomized algorithm can be seen as a random selection from a collection of deterministic algorithms. Each individual deterministic algorithm may be confounded by an input, but most algorithms in the collection will do well on any given input. Thus, by picking a random algorithm from our collection, the probability of poor algorithmic performance is small. And if we run our randomized algorithm on an input and it happens to do poorly by chance, if we run it again it is unlikely to do so; there isn&#8217;t a specific input we can create which consistently confounds our randomized algorithm.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Game Theory Framework<\/h2>\n\n\n\n<p>Let&#8217;s think about algorithm design as a game. The game has two players: you and an opponent. The game is played by solving a certain algorithmic problem, and the game has a score which quantifies how effectively the problem was solved. For example, the score might be the runtime of the algorithm, the amount of space required, or the error of a computed quantity. For simplicity of discussion, let&#8217;s use runtime as an example for this discussion. You have to pay your opponent a dollar for every second of runtime, so you want to have the runtime be as low as possible.<sup class=\"modern-footnotes-footnote \" data-mfn=\"7\" data-mfn-post-scope=\"000000000000057e0000000000000000_416\"><a href=\"javascript:void(0)\"  role=\"button\" aria-pressed=\"false\" aria-describedby=\"mfn-content-000000000000057e0000000000000000_416-7\">7<\/a><\/sup><span id=\"mfn-content-000000000000057e0000000000000000_416-7\" role=\"tooltip\" class=\"modern-footnotes-footnote__note\" tabindex=\"0\" data-mfn=\"7\">In this scenario, we consider algorithms which always produce the correct answer to the problem, and it is only a matter of how long it takes to do so. In the field of algorithms, randomized algorithms of this type are referred to as <a href=\"https:\/\/en.wikipedia.org\/wiki\/Las_Vegas_algorithm\">Las Vegas algorithms<\/a>. Algorithms which can also give the wrong answer with some (hopefully small) probability are referred to as <a href=\"https:\/\/en.wikipedia.org\/wiki\/Monte_Carlo_algorithm\">Monte Carlo algorithms<\/a>.<\/span>\n\n\n\n<p>Each player makes one move. Your move is to present an algorithm <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-11f4f587954b361e7d78940f65b8d70d_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#65;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"13\" style=\"vertical-align: 0px;\"\/> which solves the problem. Your opponent&#8217;s move is to provide an input <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-06a46a64abb2fc8a9d51631fef84fe19_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#73;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"9\" style=\"vertical-align: 0px;\"\/> to your algorithm. Your algorithm <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-11f4f587954b361e7d78940f65b8d70d_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#65;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"13\" style=\"vertical-align: 0px;\"\/> is then run on your opponents input <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-06a46a64abb2fc8a9d51631fef84fe19_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#73;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"9\" style=\"vertical-align: 0px;\"\/> and you pay your opponent a dollar for every second of runtime.<\/p>\n\n\n\n<p>This setup casts algorithm design as a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Zero-sum_game\">two-person, zero-sum game<\/a>. It is a feature of such games that a player&#8217;s optimal strategy is often <a href=\"https:\/\/en.wikipedia.org\/wiki\/Strategy_(game_theory)#Pure_and_mixed_strategies\">mixed<\/a>, picking a move at random subject to some probability distribution over all possible moves.<\/p>\n\n\n\n<p>To see why this is the case, let&#8217;s consider a classic and very simple game: <a href=\"https:\/\/en.wikipedia.org\/wiki\/Rock_paper_scissors\">rock paper scissors<\/a>. If I use a deterministic strategy, then I am forced to pick one choice, say rock, and throw it every time. But then my savvy opponent could pick paper and be assured victory. By randomizing my strategy and selecting between rock, paper, and scissors (uniformly) at random, I improve my odds to winning a third of the time, losing a third of the time, and drawing a third of the time. Further, there is no way my opponent can improve their luck by adopting a different strategy. This strategy is referred to as <a href=\"https:\/\/en.wikipedia.org\/wiki\/Minimax#In_zero-sum_games\">minimax optimal<\/a>: among all (mixed) strategies I could adopt, this strategy has the best performance over all strategies provided my opponent always counters my strategy with the best response strategy they can find.<\/p>\n\n\n\n<p>Algorithm design is totally analogous. For the pivot selection problem, if I pick a the fixed strategy of choosing the first entry to be the pivot (analogous to always picking rock), then my opponent could always give me a sorted list (analogous to always picking paper) and I would always lose. My randomizing my pivot selection, my opponent could input the list in whatever order they choose and my pivot selection will always have the excellent (expected) <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-3eacdd13b0066c46a59bd79cad85be6b_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#99;&#97;&#108;&#123;&#79;&#125;&#40;&#78;&#92;&#108;&#111;&#103;&#32;&#78;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"88\" style=\"vertical-align: -5px;\"\/> runtime characteristic of quicksort. In fact, randomized pivot selection is the minimax optimal pivot selection strategy (assuming pivot selection is non-adaptive in that we don&#8217;t choose the pivot based on the values in the list).<sup class=\"modern-footnotes-footnote \" data-mfn=\"8\" data-mfn-post-scope=\"000000000000057e0000000000000000_416\"><a href=\"javascript:void(0)\"  role=\"button\" aria-pressed=\"false\" aria-describedby=\"mfn-content-000000000000057e0000000000000000_416-8\">8<\/a><\/sup><span id=\"mfn-content-000000000000057e0000000000000000_416-8\" role=\"tooltip\" class=\"modern-footnotes-footnote__note\" tabindex=\"0\" data-mfn=\"8\">This is not to say that quicksort with randomized pivot selection is necessarily the minimax optimal sorting algorithm, but to say that once we have <em>fixed<\/em> quicksort as our sorting algorithm, randomized pivot selection is the minimax optimal non-adaptive <em>pivot selection strategy<\/em> for quicksort.<\/span>\n\n\n\n<h2 class=\"wp-block-heading\">How Much Does Randomness Buy?<\/h2>\n\n\n\n<p>Hopefully, now, the utility of randomness is less opaque. Randomization, in effect, allows an algorithm designer to trade algorithm which <em>runs fast for most inputs all of the time<\/em> for an algorithm which <em>runs fast for all inputs most of the time<\/em>. They do this by introducing randomized decision-making to hedge against particular bad inputs which could confound their algorithm.<\/p>\n\n\n\n<p>Randomness, of course, is not a panacea. Randomness does not allow us to solve every algorithmic problem arbitrarily fast. But how can we quantify this? Are there <em>algorithmic speed limits<\/em> for computational problems for which no algorithm, randomized or not, can exceed?<\/p>\n\n\n\n<p>The game theoretic framework for randomized algorithms can shed light on this question. Let us return to the framing of last section where you choose an algorithm <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-11f4f587954b361e7d78940f65b8d70d_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#65;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"13\" style=\"vertical-align: 0px;\"\/>, your opponent chooses an input <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-06a46a64abb2fc8a9d51631fef84fe19_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#73;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"9\" style=\"vertical-align: 0px;\"\/>, and you pay your opponent a dollar for every second of runtime. Since this cost depends on the algorithm and the input, we can denote the cost <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-c9318ffabac4bcaaeead71a37230449d_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#67;&#40;&#65;&#44;&#73;&#41;\" title=\"Rendered by QuickLaTeX.com\" height=\"19\" width=\"57\" style=\"vertical-align: -5px;\"\/>.<\/p>\n\n\n\n<p>Suppose you devise a randomized algorithm for this task, which can be interpreted as selecting an algorithm <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-11f4f587954b361e7d78940f65b8d70d_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#65;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"13\" style=\"vertical-align: 0px;\"\/> from a probability distribution <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e0b7f55ebbc9bb715e8b20ffdc459df7_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#80;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"14\" style=\"vertical-align: 0px;\"\/> over the class of all algorithms <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-11ff712a9a2ac2bf351b2404348a5faf_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#99;&#97;&#108;&#123;&#65;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"14\" width=\"15\" style=\"vertical-align: -1px;\"\/> which solve the problem. (Less formally, we assign each possible algorithm a probability of picking it and pick one subject to these probabilities.) Once your opponent sees your randomized algorithm (equivalently, the distribution <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e0b7f55ebbc9bb715e8b20ffdc459df7_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#80;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"14\" style=\"vertical-align: 0px;\"\/>), they can come up with the on-average slowest possible input <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-d4aa998a69c5940caa50f9c2216b0f5a_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#73;&#95;&#123;&#92;&#114;&#109;&#32;&#119;&#111;&#114;&#115;&#116;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"39\" style=\"vertical-align: -3px;\"\/> and present it to your algorithm.<\/p>\n\n\n\n<p>But now let&#8217;s switch places to see things from your opponent. Suppose they choose their own strategy of randomly selecting an input <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-06a46a64abb2fc8a9d51631fef84fe19_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#73;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"9\" style=\"vertical-align: 0px;\"\/> from among all inputs <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-62d8682fe0f0873b16eb8926b6256242_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#99;&#97;&#108;&#123;&#73;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"13\" style=\"vertical-align: 0px;\"\/> with some distribution <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e7f252699e1616398a7ce5179d3e425e_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#81;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"14\" style=\"vertical-align: -4px;\"\/>. Once you see the distribution <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e7f252699e1616398a7ce5179d3e425e_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#81;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"14\" style=\"vertical-align: -4px;\"\/>, you can come up with the best possible deterministic algorithm <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-bf2f7d0bd2a2dc98ca92ad4a2cf8ce95_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#65;&#95;&#123;&#92;&#114;&#109;&#32;&#98;&#101;&#115;&#116;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"37\" style=\"vertical-align: -3px;\"\/> to counter their strategy.<\/p>\n\n\n\n<p>The next part gets a bit algebraic. Suppose now we apply your randomized algorithm against your opponents strategy. Then, your randomized algorithm could only take longer on average than <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-bf2f7d0bd2a2dc98ca92ad4a2cf8ce95_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#65;&#95;&#123;&#92;&#114;&#109;&#32;&#98;&#101;&#115;&#116;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"37\" style=\"vertical-align: -3px;\"\/> because, by construction, <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-bf2f7d0bd2a2dc98ca92ad4a2cf8ce95_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#65;&#95;&#123;&#92;&#114;&#109;&#32;&#98;&#101;&#115;&#116;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"37\" style=\"vertical-align: -3px;\"\/> is the fastest possible algorithm against the input distribution <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e7f252699e1616398a7ce5179d3e425e_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#81;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"14\" style=\"vertical-align: -4px;\"\/>. Symbolically, we have<\/p>\n\n\n<p><p class=\"ql-center-displayed-equation\" style=\"line-height: 19px;\"><span class=\"ql-right-eqno\"> (1) <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-89a553be927a6715a3582584e0c917b4_l3.png\" height=\"19\" width=\"337\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#101;&#113;&#117;&#97;&#116;&#105;&#111;&#110;&#42;&#125; &#92;&#109;&#97;&#116;&#104;&#98;&#98;&#123;&#69;&#125;&#95;&#123;&#73;&#92;&#115;&#105;&#109;&#32;&#81;&#125;&#32;&#92;&#108;&#101;&#102;&#116;&#091;&#32;&#67;&#40;&#65;&#95;&#123;&#92;&#114;&#109;&#32;&#98;&#101;&#115;&#116;&#125;&#44;&#73;&#41;&#32;&#92;&#114;&#105;&#103;&#104;&#116;&#093;&#32;&#92;&#108;&#101;&#32;&#92;&#109;&#97;&#116;&#104;&#98;&#98;&#123;&#69;&#125;&#95;&#123;&#65;&#92;&#115;&#105;&#109;&#32;&#80;&#125;&#32;&#92;&#108;&#101;&#102;&#116;&#091;&#32;&#92;&#109;&#97;&#116;&#104;&#98;&#98;&#123;&#69;&#125;&#95;&#123;&#73;&#92;&#115;&#105;&#109;&#32;&#81;&#125;&#32;&#92;&#108;&#101;&#102;&#116;&#091;&#32;&#67;&#40;&#65;&#44;&#32;&#73;&#41;&#32;&#92;&#114;&#105;&#103;&#104;&#116;&#093;&#32;&#92;&#114;&#105;&#103;&#104;&#116;&#093;&#46; &#92;&#101;&#110;&#100;&#123;&#101;&#113;&#117;&#97;&#116;&#105;&#111;&#110;&#42;&#125;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p><\/p>\n\n\n<p>Here, <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-d1e704867a7623aebb95464174ab04ce_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#98;&#98;&#123;&#69;&#125;&#95;&#123;&#73;&#92;&#115;&#105;&#109;&#32;&#81;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"18\" width=\"41\" style=\"vertical-align: -6px;\"\/> and <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-a74f63890c81597d57353ef947f28a3e_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#98;&#98;&#123;&#69;&#125;&#95;&#123;&#65;&#92;&#115;&#105;&#109;&#32;&#80;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"44\" style=\"vertical-align: -3px;\"\/> denote the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Expected_value\">average (expected) value<\/a> of a random quantity when an input <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-06a46a64abb2fc8a9d51631fef84fe19_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#73;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"9\" style=\"vertical-align: 0px;\"\/> is drawn randomly with distribution <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e7f252699e1616398a7ce5179d3e425e_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#81;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"14\" style=\"vertical-align: -4px;\"\/> or an algorithm <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-11f4f587954b361e7d78940f65b8d70d_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#65;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"13\" style=\"vertical-align: 0px;\"\/> is drawn randomly with distribution <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e0b7f55ebbc9bb715e8b20ffdc459df7_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#80;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"14\" style=\"vertical-align: 0px;\"\/>. But we know that <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-d4aa998a69c5940caa50f9c2216b0f5a_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#73;&#95;&#123;&#92;&#114;&#109;&#32;&#119;&#111;&#114;&#115;&#116;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"39\" style=\"vertical-align: -3px;\"\/> is the slowest input for our randomized algorithm, so, on average, our randomized algorithm will take longer on worst-case input <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-d4aa998a69c5940caa50f9c2216b0f5a_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#73;&#95;&#123;&#92;&#114;&#109;&#32;&#119;&#111;&#114;&#115;&#116;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"15\" width=\"39\" style=\"vertical-align: -3px;\"\/> then a random input from <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e7f252699e1616398a7ce5179d3e425e_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#81;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"14\" style=\"vertical-align: -4px;\"\/>. In symbols,<\/p>\n\n\n<p><p class=\"ql-center-displayed-equation\" style=\"line-height: 19px;\"><span class=\"ql-right-eqno\"> (2) <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-0f1bb38e9547b1c6a3fff52465bee9de_l3.png\" height=\"19\" width=\"347\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#101;&#113;&#117;&#97;&#116;&#105;&#111;&#110;&#42;&#125; &#92;&#109;&#97;&#116;&#104;&#98;&#98;&#123;&#69;&#125;&#95;&#123;&#65;&#92;&#115;&#105;&#109;&#32;&#80;&#125;&#32;&#92;&#108;&#101;&#102;&#116;&#091;&#32;&#92;&#109;&#97;&#116;&#104;&#98;&#98;&#123;&#69;&#125;&#95;&#123;&#73;&#92;&#115;&#105;&#109;&#32;&#81;&#125;&#32;&#92;&#108;&#101;&#102;&#116;&#091;&#32;&#67;&#40;&#65;&#44;&#32;&#73;&#41;&#32;&#92;&#114;&#105;&#103;&#104;&#116;&#093;&#32;&#92;&#114;&#105;&#103;&#104;&#116;&#093;&#32;&#92;&#108;&#101;&#32;&#92;&#109;&#97;&#116;&#104;&#98;&#98;&#123;&#69;&#125;&#95;&#123;&#65;&#92;&#115;&#105;&#109;&#32;&#80;&#125;&#32;&#92;&#108;&#101;&#102;&#116;&#091;&#32;&#67;&#40;&#65;&#44;&#73;&#95;&#123;&#92;&#114;&#109;&#32;&#119;&#111;&#114;&#115;&#116;&#125;&#41;&#32;&#92;&#114;&#105;&#103;&#104;&#116;&#093;&#46; &#92;&#101;&#110;&#100;&#123;&#101;&#113;&#117;&#97;&#116;&#105;&#111;&#110;&#42;&#125;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p><\/p>\n\n\n<p>Combining Eqs. (1) and (2) gives <a href=\"https:\/\/en.wikipedia.org\/wiki\/Yao%27s_principle\">Yao&#8217;s minimax principle<\/a><sup class=\"modern-footnotes-footnote \" data-mfn=\"9\" data-mfn-post-scope=\"000000000000057e0000000000000000_416\"><a href=\"javascript:void(0)\"  role=\"button\" aria-pressed=\"false\" aria-describedby=\"mfn-content-000000000000057e0000000000000000_416-9\">9<\/a><\/sup><span id=\"mfn-content-000000000000057e0000000000000000_416-9\" role=\"tooltip\" class=\"modern-footnotes-footnote__note\" tabindex=\"0\" data-mfn=\"9\">Note that Yao&#8217;s minimax principle is a consequence of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Minimax_theorem\">von Neumann&#8217;s minimax theorem<\/a> in game theory.<\/span>:<\/p>\n\n\n<p><p class=\"ql-center-displayed-equation\" style=\"line-height: 19px;\"><span class=\"ql-right-eqno\"> (3) <\/span><span class=\"ql-left-eqno\"> &nbsp; <\/span><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-1fd0c09fd23c2139e92beaf1800b57ad_l3.png\" height=\"19\" width=\"315\" class=\"ql-img-displayed-equation quicklatex-auto-format\" alt=\"&#92;&#98;&#101;&#103;&#105;&#110;&#123;&#101;&#113;&#117;&#97;&#116;&#105;&#111;&#110;&#42;&#125; &#92;&#109;&#97;&#116;&#104;&#98;&#98;&#123;&#69;&#125;&#95;&#123;&#73;&#92;&#115;&#105;&#109;&#32;&#81;&#125;&#32;&#92;&#108;&#101;&#102;&#116;&#091;&#32;&#67;&#40;&#65;&#95;&#123;&#92;&#114;&#109;&#32;&#98;&#101;&#115;&#116;&#125;&#44;&#73;&#41;&#32;&#92;&#114;&#105;&#103;&#104;&#116;&#093;&#32;&#92;&#108;&#101;&#32;&#92;&#109;&#97;&#116;&#104;&#98;&#98;&#123;&#69;&#125;&#95;&#123;&#65;&#92;&#115;&#105;&#109;&#32;&#80;&#125;&#32;&#92;&#108;&#101;&#102;&#116;&#091;&#32;&#67;&#40;&#65;&#44;&#73;&#95;&#123;&#92;&#114;&#109;&#32;&#119;&#111;&#114;&#115;&#116;&#125;&#41;&#32;&#92;&#114;&#105;&#103;&#104;&#116;&#093;&#46; &#92;&#101;&#110;&#100;&#123;&#101;&#113;&#117;&#97;&#116;&#105;&#111;&#110;&#42;&#125;\" title=\"Rendered by QuickLaTeX.com\"\/><\/p><\/p>\n<p>In words, <em data-rich-text-format-boundary=\"true\">the average performance of any randomized algorithm on its worst-case input can be no better than the average performance of the best possible deterministic algorithm for a<\/em> <em>distribution of inputs<\/em>.<sup class=\"modern-footnotes-footnote \" data-mfn=\"10\" data-mfn-post-scope=\"000000000000057e0000000000000000_416\"><a href=\"javascript:void(0)\"  role=\"button\" aria-pressed=\"false\" aria-describedby=\"mfn-content-000000000000057e0000000000000000_416-10\">10<\/a><\/sup><span id=\"mfn-content-000000000000057e0000000000000000_416-10\" role=\"tooltip\" class=\"modern-footnotes-footnote__note\" tabindex=\"0\" data-mfn=\"10\">In fact, there is a strengthening of Yao&#8217;s minimax principle. That Eqs. (1) and (2) are equalities when <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e0b7f55ebbc9bb715e8b20ffdc459df7_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#80;\" title=\"Rendered by QuickLaTeX.com\" height=\"12\" width=\"14\" style=\"vertical-align: 0px;\"\/> and <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e7f252699e1616398a7ce5179d3e425e_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#81;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"14\" style=\"vertical-align: -4px;\"\/> are taken to be the minimax optimal randomized algorithm and input distribution, respectively. Specifically, assuming the cost is a natural number and we restrict to a finite class of potential inputs, <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-a6f8e1dce8877537d45660d7df712961_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#120;&#95;&#123;&#92;&#109;&#98;&#111;&#120;&#123;&#105;&#110;&#112;&#117;&#116;&#32;&#100;&#105;&#115;&#116;&#114;&#105;&#98;&#117;&#116;&#105;&#111;&#110;&#115;&#32;&#125;&#32;&#81;&#125;&#32;&#92;&#109;&#105;&#110;&#95;&#123;&#92;&#109;&#98;&#111;&#120;&#123;&#97;&#108;&#103;&#111;&#114;&#105;&#116;&#104;&#109;&#115;&#32;&#125;&#65;&#125;&#32;&#92;&#109;&#97;&#116;&#104;&#98;&#98;&#123;&#69;&#125;&#95;&#123;&#73;&#92;&#115;&#105;&#109;&#32;&#81;&#125;&#32;&#091;&#67;&#40;&#65;&#44;&#73;&#41;&#093;\" title=\"Rendered by QuickLaTeX.com\" height=\"24\" width=\"437\" style=\"vertical-align: -10px;\"\/>&nbsp;<span style=\"font-size: inherit;\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-4bffd4d8610692752e6945af287171d3_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#61;&#92;&#109;&#105;&#110;&#95;&#123;&#92;&#109;&#98;&#111;&#120;&#123;&#114;&#97;&#110;&#100;&#111;&#109;&#105;&#122;&#101;&#100;&#32;&#97;&#108;&#103;&#111;&#114;&#105;&#116;&#104;&#109;&#115;&#32;&#125;&#80;&#125;&#32;&#92;&#109;&#97;&#120;&#95;&#123;&#92;&#109;&#98;&#111;&#120;&#123;&#105;&#110;&#112;&#117;&#116;&#115;&#32;&#125;&#73;&#125;&#92;&#109;&#97;&#116;&#104;&#98;&#98;&#123;&#69;&#125;&#95;&#123;&#65;&#92;&#115;&#105;&#109;&#32;&#80;&#125;&#32;&#92;&#108;&#101;&#102;&#116;&#091;&#32;&#67;&#40;&#65;&#44;&#73;&#41;&#32;&#92;&#114;&#105;&#103;&#104;&#116;&#093;&#46;\" title=\"Rendered by QuickLaTeX.com\" height=\"24\" width=\"466\" style=\"vertical-align: -10px;\"\/> This nontrivial fact is a consequence of the full power of the&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Minimax_theorem\" data-rich-text-format-boundary=\"true\">von Neumann&#8217;s minimax theorem<\/a>, which itself is a consequence of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Dual_linear_program#Strong_duality\">strong duality<\/a> in <a href=\"https:\/\/en.wikipedia.org\/wiki\/Linear_programming\">linear programming<\/a>. My thanks go to <a href=\"http:\/\/users.cms.caltech.edu\/~schulman\/\">Professor Leonard Schulman<\/a>&nbsp;for teaching me this result.<\/span><span style=\"font-size: inherit;\"><\/span><\/span><\/p>\n\n\n<p>This, in effect, allows the algorithm analyst seeking to prove &#8220;no randomized algorithm can do better than this&#8221; to trade randomness in the algorithm to randomness in the input in their analysis. This is a great benefit because randomness in an algorithm can be used in arbitrarily complicated ways, whereas random inputs can be much easier to understand. To prove any randomized algorithm takes at least cost <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-97ef9906ba01e608975440d5f5812edb_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#99;\" title=\"Rendered by QuickLaTeX.com\" height=\"8\" width=\"8\" style=\"vertical-align: 0px;\"\/> to solve a problem, the algorithm analyst can find a distribution <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-e7f252699e1616398a7ce5179d3e425e_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#81;\" title=\"Rendered by QuickLaTeX.com\" height=\"16\" width=\"14\" style=\"vertical-align: -4px;\"\/> on which every deterministic algorithm takes at least cost <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-97ef9906ba01e608975440d5f5812edb_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#99;\" title=\"Rendered by QuickLaTeX.com\" height=\"8\" width=\"8\" style=\"vertical-align: 0px;\"\/>. Note that Yao&#8217;s minimax principle is an analytical tool, not an algorithmic tool. Yao&#8217;s principle establishes <em>speed limits<\/em> on the best possible randomized algorithm: it does not imply that one can just use deterministic algorithms and assume or make the input to be random.<\/p>\n\n\n\n<p>There is a fundamental question concerning the power of randomized algorithms not answered by Yao&#8217;s principle that is worth considering: how much better can randomized algorithms be than deterministic ones? Could infeasible problems for deterministic computations be solved tractably by randomized algorithms?<\/p>\n\n\n\n<p>Questions such as these are considered in the field of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Computational_complexity_theory\">computational complexity theory<\/a>. In this context, one can think of a problem as tractably solvable if it can be solved in <a href=\"https:\/\/mathworld.wolfram.com\/PolynomialTime.html\">polynomial time<\/a>\u2014that is, in an amount of time proportional to a polynomial function of the size of the input. Very roughly, we call the <a href=\"https:\/\/en.wikipedia.org\/wiki\/P_(complexity)\">class of all such problems<\/a> to be <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-83ac0ecb3b633c63d08cba1b9ad2f40b_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#115;&#102;&#123;&#80;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"10\" style=\"vertical-align: 0px;\"\/>. If one in addition allows randomness, we call this <a href=\"https:\/\/en.wikipedia.org\/wiki\/BPP_(complexity)\">class of problems<\/a> <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-66f4dc880c95ec5e94905ab3cbe4d854_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#115;&#102;&#123;&#66;&#80;&#80;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"33\" style=\"vertical-align: 0px;\"\/>.<sup class=\"modern-footnotes-footnote \" data-mfn=\"11\" data-mfn-post-scope=\"000000000000057e0000000000000000_416\"><a href=\"javascript:void(0)\"  role=\"button\" aria-pressed=\"false\" aria-describedby=\"mfn-content-000000000000057e0000000000000000_416-11\">11<\/a><\/sup><span id=\"mfn-content-000000000000057e0000000000000000_416-11\" role=\"tooltip\" class=\"modern-footnotes-footnote__note\" tabindex=\"0\" data-mfn=\"11\">More precisely, <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-66f4dc880c95ec5e94905ab3cbe4d854_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#115;&#102;&#123;&#66;&#80;&#80;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"33\" style=\"vertical-align: 0px;\"\/> is the class of problems solvable in polynomial time by a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Monte_Carlo_algorithm\">Monte Carlo randomized algorithm<\/a>. The class of problems solvable in polynomial time by a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Las_Vegas_algorithm\">Las Vegas randomized algorithm<\/a>, which we&#8217;ve focused on for the duration of this article, is a <a href=\"https:\/\/en.wikipedia.org\/wiki\/ZPP_(complexity)\">possibly smaller class<\/a> called <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-12c501b5f3df8cbafb6cc2475733e124_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#115;&#102;&#123;&#90;&#80;&#80;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"33\" style=\"vertical-align: 0px;\"\/>.<\/span>\n\n\n\n<p>It has widely been conjectured that <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-c0519c466bb6d42b1cbacdf4c6501673_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#115;&#102;&#123;&#80;&#125;&#32;&#61;&#32;&#92;&#109;&#97;&#116;&#104;&#115;&#102;&#123;&#66;&#80;&#80;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"68\" style=\"vertical-align: 0px;\"\/>: all problems that can be tractably solved with randomness can tractably be solved without. There is <a href=\"https:\/\/www.math.ias.edu\/~avi\/PUBLICATIONS\/MYPAPERS\/NOAM\/HARDNESS\/final.pdf\">some convincing evidence<\/a> for this belief. Thus, provided this conjecture turns out to be true, randomness can give us reductions in operation counts by a polynomial amount in the input size for problems already in <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-83ac0ecb3b633c63d08cba1b9ad2f40b_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#115;&#102;&#123;&#80;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"10\" style=\"vertical-align: 0px;\"\/>, but they cannot efficiently solve <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-b60577e6a62be7434f17234d2eddfe92_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#115;&#102;&#123;&#78;&#80;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"13\" width=\"23\" style=\"vertical-align: 0px;\"\/><a href=\"https:\/\/en.wikipedia.org\/wiki\/NP-hardness\">-hard computational problems<\/a> like the <a href=\"https:\/\/en.wikipedia.org\/wiki\/Travelling_salesman_problem\">traveling salesman problem<\/a>.<sup class=\"modern-footnotes-footnote \" data-mfn=\"12\" data-mfn-post-scope=\"000000000000057e0000000000000000_416\"><a href=\"javascript:void(0)\"  role=\"button\" aria-pressed=\"false\" aria-describedby=\"mfn-content-000000000000057e0000000000000000_416-12\">12<\/a><\/sup><span id=\"mfn-content-000000000000057e0000000000000000_416-12\" role=\"tooltip\" class=\"modern-footnotes-footnote__note\" tabindex=\"0\" data-mfn=\"12\">Assuming the also quite believable <a href=\"https:\/\/en.wikipedia.org\/wiki\/P_versus_NP_problem\">conjecture<\/a> that <img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.ethanepperly.com\/wp-content\/ql-cache\/quicklatex.com-756e902e6f9fb40359e93d1708496a93_l3.png\" class=\"ql-img-inline-formula quicklatex-auto-format\" alt=\"&#92;&#109;&#97;&#116;&#104;&#115;&#102;&#123;&#80;&#125;&#92;&#110;&#101;&#92;&#109;&#97;&#116;&#104;&#115;&#102;&#123;&#78;&#80;&#125;\" title=\"Rendered by QuickLaTeX.com\" height=\"17\" width=\"58\" style=\"vertical-align: -4px;\"\/>.<\/span>\n\n\n\n<p>So let&#8217;s return to the question which is also this article&#8217;s title: <strong>why randomized algorithms?<\/strong> Because randomized algorithms are often faster. <strong>Why, intuitively, is this the case?<\/strong> Randomization can us to upgrade simple algorithms that are great for most inputs to randomized algorithms which are great most of the time for all inputs. <strong>How much can randomization buy? <\/strong>A randomized algorithm on its worst input can be no better than a deterministic algorithm on a worst-case distribution. Assuming a widely believed and theoretically supported, but not yet proven, conjecture, randomness can&#8217;t make intractable problems into tractable ones. Still, there is great empirical evidence that randomness can be an immensely effective algorithm design tool in practice, including computational math and science problems like <a href=\"https:\/\/arxiv.org\/pdf\/2010.09649.pdf\">trace estimation<\/a> and <a href=\"https:\/\/arxiv.org\/abs\/1605.02353\">solving Laplacian linear systems<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post, I want to answer a simple question: how can randomness help in solving a deterministic (non-random) problem? Let&#8217;s start by defining some terminology. An algorithm is just a precisely defined procedure to solve a problem. For example, one algorithm to compute the integral of a function on the interval is to pick<a class=\"more-link\" href=\"https:\/\/www.ethanepperly.com\/index.php\/2021\/08\/11\/why-randomized-algorithms\/\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-416","post","type-post","status-publish","format-standard","hentry","category-expository"],"_links":{"self":[{"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/posts\/416","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/comments?post=416"}],"version-history":[{"count":76,"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/posts\/416\/revisions"}],"predecessor-version":[{"id":809,"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/posts\/416\/revisions\/809"}],"wp:attachment":[{"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/media?parent=416"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/categories?post=416"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ethanepperly.com\/index.php\/wp-json\/wp\/v2\/tags?post=416"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}