Randomness is a fleeting commodity if you believe in the “Big Freeze” theory of our universe’s fate [3]. Should we survive as flesh or metal to explore the universe, a lack of randomness could make our algorithms and programs inefficient (if ), or at least it would likely be more complicated to write (if ) [1]. It is currently unknown which case we exist in, although most likely the former case, but neither are ideal situations. Randomness is particularly vital to a field I find great interest in, that is probabilistic proof systems [2] [5]. Although it may make winning the big lottery jackpot harder, we should be cherishing randomness while we have it, because in this blog post I will show examples where access to randomness can give us improvements in communication cost, running time, and space cost.
Communication Complexity Improvements
Imagine the following scenario. Alice and Bob are on opposite ends of the earth. Bob wants to check if a document that Alice has on her computer is the same as the one Bob has on his. How might Bob be convinced of this? Well, the first idea that probably comes to mind is for Alice to just send her file to Bob. If Alice is not using any coding theory techniques to detect if any errors occur during the transmission, which would be unlikely in practice, Alice would have to send the entire file to Bob. This may be doable if our file is small, but what if the file was all of Wikipedia? Or what if it were the Ethereum blockchain? That would start to become an issue. Unfortunately if we had to be 100% confident that our files were the same, there is no shortcut. However, if we were willing to allow some probability of one-sided error, that is Bob being convinced the files are the same when they are not, then we can utilize randomness to help us with this task. I will walk through an example of a protocol for this, then describe the protocol in technical detail, then prove the correctness of the protocol.
First, let’s assume that they already established that their file is the same size, because if not, they quickly know the contents aren’t the same. Suppose Alice has a file containing “hello”, as does Bob. Supposing we know the file contains only ASCII characters, then each character can be mapped to a number between 0 and 127, inclusive. So, “hello” gets mapped to “104 101 108 108 111”. We then interpret this encoded message as the polynomial
over the field . If you don’t know what a field is, don’t worry. I won’t go over it here, since there are many introductions to fields available online, including Dummit and Foote notes, Wikipedia, and Socratica. All you need to know for the purpose of this article, for the fields we will be working with, is a number system that works exactly like clock arithmetic, but on a clock with hours. You can do all your familiar operations you know and love, just mod by in the end. Division is a little trickier, since you’ll have to use the Extended Euclidean Algorithm, or you can trust my math here.
Now that Alice encoded her message as a polynomial, she will pick an element uniformly random from the field, notated , and evaluate it on the polynomial. For this example, say . So, Alice calculates
Alice then sends Bob the message . Now, Bob encodes his file contents as the polynomial in the same way that Alice did hers, and he also evaluates his polynomial on . So, he checks . If so, he is convinced that with high probability (at least 96.9%) that they share the same file, otherwise he knows the file contents are different. We prove this property of the protocol shortly below. This confidence can also be made arbitrarily high!
Let’s take a second to really appreciate the power of what we just did. Instead of Alice sending the entire file contents, which happen to be five elements from the field in this example, she instead only sent two field elements to Bob, 24 and 71. You might be thinking, we saved our communication by halfish, but we did FAR better than that! If you look closely, it doesn’t matter how big the file is. We always only need to send two field elements to Bob to convince him of his question!
- INPUT: Alice has file contents and Bob has file contents , whose characters come from an alphabet of size . Let be prime.
- GOAL: Bob wants to determine if . If so, he outputs , otherwise he outputs .
- Alice selects .
- Alice sends the message to Bob, where .
- Bob checks , where . If true, output , otherwise output .
Now, below, I will prove that if the file contents are the same and Alice is honest, meaning Alice may not deviate from the protocol to convince Bob otherwise, then Bob is convinced that the files are the same with probability 1. I will also prove that if the file contents are not the same and Alice is honest, then Bob will be falsely convinced the files are the same with probability . In other words, the probability that Bob is convinced of the contrary decreases linearly with the size of the file contents. Both properties have technical terms in probabilistic proof systems, where the first property is called completeness and the second is called soundness. Completeness is usually trivial, while soundness is not.
Proof.
Completeness: Suppose that and Alice is honest. Since for all , then Bob outputs for all choices of .
Soundness: Suppose . Then the polynomials and are distinct, since for at least some . Since the degree of both polynomials is at most and they are distinct, then for at most values of . Now, since , the probability that Bob outputs is .
Running Time Complexity Improvements
Now, I’ll describe how randomness can improve the running time performance of algorithms. Imagine this new scenario. Some salesman comes to your door and is selling you a black box which will spit out the result of two matrices multiplied together in time! Now, the naive time complexity of multiplying two matrices is with your normal matrix multiplication you would learn in a linear algebra class. A popular improvement used today is called Strassen’s algorithm, which runs in time. The fastest known algorithm for multiplying two matrices currently runs in time , however it isn’t very useful unless the matrices are incredibly large.
This would be an incredibly useful tool to have to quickly satisfy all your square matrix multiplication needs! But, you don’t really trust what the salesman says and what he claims the product to do. You also don’t want to spend a lot of time checking if it did the calculation right, which would require running one of those algorithms above, and at that point there would be no point in buying the box. However, luckily we can use randomness to be highly convinced of the correctness of the answer in time!
Now, from a bird’s eye view, how does this algorithm work? Imagine you have two matrices and you throw them into this machine, which returns the supposed result . Now, we don’t want to check if since, again, we would need to use one of the algorithms above, which is too slow. Instead, what if we choose and multiply both sides of the equation by the column vector so that we now check if ? Well, now we still have a matrix multiplication, which is slow, but we are definitely getting somewhere because matrix multiplication is associative! So, we can check if without the slow matrix multiplication.
Freivalds' Algorithm (Variant)
- INPUT:
- GOAL: Determine . Output if true, and output otherwise.
- Choose and let .
- Check . If true, output , otherwise output .
This algorithm is a variation of Freivalds’ algorithm, runs in time , and can verify the matrix product with a probability of failure . This is a variation on the original because the original algorithm chooses , which still runs in time , but has an error probability of . You can see that we get a tradeoff where choosing much larger than gives us better confidence in our verification, at the cost of using randomness from a larger field. I chose to show the variation of Freivalds’ algorithm because its analysis is actually easier, especially given the proof we already established in the section above.
Proof.
Completeness: Suppose that . Let . Then because for all . Thus, for all . Thus, we output with probability 1.
Soundness: Suppose . Let . Then for some . Without loss of generality, suppose it is such that . Then we are testing the equality of two distinct polynomials at a point . Namely, the polynomial on the LHS is and the RHS polynomial is . Since they are distinct, they agree on at most points. Therefore, we will output with probability .
Space Complexity Improvements
Lastly, we are going to look at an example where access to randomness can save us space. The problem we are going to look at is called the undirected - connectivity (USTCON) problem. Given an undirected graph and two vertices and in , we must decide whether and are in the same component, that is that there is a path going from one to the other. This may seem like an esoteric example, but there are actually many real-world examples where this is useful. We could imagine that Google Maps stores all of the roads as a graph where the vertices are intersections and the roads going in and out of intersections are edges. So, we could see Google Maps being able to answer the question “Can you get from intersection to intersection ”?
How might we solve this problem if we wanted to be 100% sure of its connectivity? Well, the easiest way might be to do a depth-first search starting from . The space complexity of this solution is and the time complexity is , where and are the number of vertices and edges in the graph, respectively, since it has to keep track of where it has been and possibly traverse the whole graph. As with our previous examples, if we use randomness and we allow ourselves a probability of outputting the incorrect solution, we can find improvements in space complexity.
Now, what if we just walk around the graph randomly? This could greatly reduce our space because all we need to do is keep track of the current vertex we are on, which only takes space with a numbering scheme of the vertices. But, we don’t want to be walking forever because it may be the case that and are not connected. So, how long might we want to be randomly walking for in order to be highly confident in outputting if we have not seen ? Luckily for us the study of Markov Chains gives us some terminology and prior results to solve this question.
The hitting time between vertices and , denoted , is the expected number of steps in a random walk that starts at and ends upon first reaching . The commute time between vertices and , denoted , is the expected number of steps in a random walk that starts at , reaches , and returns to . Clearly, when . I will prove that if we walk for steps and and are connected, we will output with probability . The following corollary is useful to us, but will not be proved, as it is out of the scope of the blog post. See Chapter 6 of the Motwani and Raghavan book for details [4].
Corollary 1 Commute Time Bound
For any connected undirected graph with vertices, and any distinct vertices , the hitting and commute times satisfy .
For a graph with vertices and vertices , if we perform a random walk of length starting at and output if we reach , then if and are connected, we will output with probability , and if they are not connected, we will output with probability 1.
Proof.
Let . If are not connected, then our random walk of length starting at will never reach . Thus, we output with probability 1.
If and are connected and , then we output immediately. If and are connected and distinct, then the corollary above gives . By Markov’s inequality, the probability that the random walk has not reached after steps is less than . Therefore, when we walk for steps, we output with probability .
So, notice that we have given ourselves a trade-off. The depth-first search solution was able to output an always correct answer in time , which is in the densest case, while the randomized walk algorithm runs in time , with a probability of outputting a correct answer. However, as noted previously, we do not need to store all previously visited vertices in the randomized algorithm, just the current vertex and a step counter, which gives us a greatly improved space complexity of .
There is one important modern caveat here. This random-walk algorithm is a simple and historically important way to see how randomness can reduce space, but it is not the final word on USTCON. Omer Reingold later proved that undirected - connectivity can be solved deterministically in logarithmic space. So, randomness is not necessary for the best-known space bound here, but it remains the most approachable route to the idea.
References
[1] Adleman, L. (1979). Time, space and randomness. MIT/LCS/TM-131.
[2] Goldreich, O. (2011). Randomness and Computation. In: Goldreich, O. (eds) Studies in Complexity and Cryptography. Miscellanea on the Interplay between Randomness and Computation. Lecture Notes in Computer Science, vol 6650. Springer, Berlin, Heidelberg.
[3] Hayes, B. (2001). Computing Science: Randomness as a Resource. American Scientist, 89(4), 300-304.
[4] Motwani, R., & Raghavan, P. (1995). Randomized Algorithms. Cambridge, England: Cambridge University Press.
[5] Thaler, J. (2023). Proofs, Arguments, and Zero-Knowledge (Draft).