CS 627 – Advanced Algorithms (Winter 2026-27) · unit page · YouTube
2026-11-26, 19:00

← Video 7-3: Probability Theory RecapVideo 7-5: Las Vegas and Monte Carlo →

Click any sentence to play from there.

The transcript was generated automatically by YouTube's speech recognition and is offered as is. It may contain errors, in particular concerning technical terms, names and formulas.

0:01 After our refresher of of probability theory, let's uh put this to use in in algorithms again. Um the next section wants to define what randomized computation really is. I also will try not to spend too much time on on the formalities there. But it was somehow a desire of mine to have a foundation for this for this uh notion of a randomized algorithm. I found this a bit um unsatisfying to just budge it or handwave it. On the other hand, we don't really need the formalization for much. It's just a backdrop. Um as for the rest of the the complexity theory part, we'll we'll base the computation model on touring machines. So now we want a probabilistic model for touring machines that allows randomness. Okay, so far so good. Um, formally we essentially keep the machine the same except that there's another input tape and that input tape is prefilled with it's a readonly input tape. I guess input tape is always read only.

1:10 It's a is an additional readonly tape filled with random bits from the start and it's infinite to the right. And now um you have uh one additional component in your transition uh function. You can read this random bit in each state and you can decide whether you want to move the read head on your random bits left or right or not. And all the rest is essentially the same as for standard Turing machines. So I'm not going to give the full full details. uh well ultimately the the desire will be to have these random bits iid per bulli distributed uh with probability 1/2 so what we would think of as random bits uh for the moment the distribution or the the the definitions don't really um capture this directly they they just say suppose there is some bitst string on this random input tape what would the machine then do of course once you fix the content of this random input tape there's nothing random left it's a deterministic computation again uh the configurations of this Turing machine of these probabilistic Turing machines they consist of of two components the normal tape that we work on and then this random tape that we can only move through but not not change okay and remember we write this as this this uh shorthand notation uh your head is at some position And which way around was it? Is it the first bit of sigma? Thank god I put it on the slides. So if the normal tape has the contents alpha beta and the head sits on this character here on the first character of beta, then we write the this state as alpha q beta. if the machine is in state Q and we'll repeat this state for the input tape with the random bits to also indicate that we're sitting on this first bit from sigma.

3:13 Then you can imagine how you would define the computation relation. Again, at this point it's really just a two-tape Turing machine and there's no randomness involved anymore once you fix the input here on the tape. Um for the semantics uh what we mean what what does it mean that that such a probabilistic machine computes some function? Well, it means we have some input on on the normal tape and we have some random bits on this on this random bit tape. Once both is fixed, it's deterministic and we say well the machine has an output y if it produces this output here as the thing following the halting state and we don't care what it does with the random bits. uh and then we can define what a randomized computation is. Namely, it's a random variable where you have a fixed input for X and then an IID sequence of Boli trials as inputs on this random tape.

4:15 Okay. Now, we'd like to write something like this. The probability that our machine outputs Y. And this is a bit of a um uh problematic statement. I could say I'm just summing over all random random bits and then the probability that this these are my random bits multiplied by the indicator whether the machine with these bits computes my specific value y that gives me my dist my probability that the machine outputs y. Where's the problem with that?

5:03 That's also true. The machine might not hold. In this case, I would have to say something. Um, it might just be that, you know, um, we have to make some definition of of this deterministic computation. If it doesn't hold, then it doesn't output y because then it doesn't have this finite many steps that lead to this point. That's another problem. There's another one here from the probability sense and it's it's this lie here. I'm just summing over some infinite things and it's not just countably infinite here, right? This is uh arbitrarily many bit strings. The problem is I I don't know uh how many bits the machine will read and I can't simply put an upper bound on that. Uh we'll see an example in a second. So really what you should do here is use this contour tree space definition.

5:55 So we should say we're summing over all finite prefixes and then uh the probability that we um terminate with that. So the probability that m outputs our specific value y and it used exactly that many uh random bits. it it read those and it never touched what came after. So it's a bit uh think of this tree the machine explores in different random branches maybe explores more or less random bits but there's always going to be some front in this tree and you you can sum over those. uh this this line is is all that we needed the whole general probability spaces for.

6:43 Okay, why do we need this general mess? Why can't we not somehow just say it needs so and so many random bits? Well, there's reasonable, sensible, practical algorithms that we cannot express with that. And the simplest example is um a rejection sampling based algorithm for simulating a fair die. So standard die with six sides. I should have probability 1 over six for each of the outcomes. How would you do that if all you have is random bits? I'm sure you thought about this at some point. How would you do it? I can only give you random coin flips and you have to give exactly uniform over 1 2 3 4 5 6.

7:44 So the obvious part is suppose you use a thousand bits and never more. Then I can say I'm going to write down all the two to the thousand possible paths. Each has probability two to the minus thousand and you sum up how many outputs? 1 2 3 4 5 6. That's not going to work because the denominator is the the number of um the probability is always 1 over 2 to the minus a thousand and you're have integer multiples for that. So it's always going to be a rational with some integer in the numerator and some power of two in the denominator. That's never going to be one over six. The only option is you leave some things undecided. For example, you flip a coin three times. And let me show you the complicated algorithm. Yeah, you flip a coin three times. interpret that bit sequence as a number between zero and seven. And if you have one of the ones that are not supposed to be the outcome of a die roll, then you just try again. That's the important point. This algorithm is is a bit dangerous. It might run forever, right?

8:59 On the other hand, it's not going to run forever with any probability because in each step you have a 2/3 uh 3/4 chance to stop and you take powers of 3/4 um say the probability that this runs for 100 times is 3/4 to the hundredths. That's by and large one. that's going to stop with high probability after a sensible number of of trials.

9:37 In particular, um well, it's correct by construction. That's the good thing. It might not terminate but the expected running time is very tame because the uh number of repetitions is a geometric random variable with a certain probability here three fours to stop and the expectation is really uh not even two right most of the time one trial is good enough sometimes you need two and then it already gets exponentially unlikely that you need to continue so this is a good algorithm even though it might run forever. This is a good algorithm. We want to allow this. But then our random model, our model of randomized computations has to allow this. And to be able to foster that or to allow that, we need this business of infinitely long bit strings.

10:29 I don't think there's a way around it. On the other hand, it's also not that bad. Also, most algorithms are not really like this. uh we can often uh not worry about infinitely running algorithms.

10:45 [snorts] In general, what could go wrong with these with this random model of computations? Um what you said before, we could deterministically go into an infinite loop. But uh I mean that we had that problem before and that's just a stupid algorithm. Let's just not look at those. Okay.

11:03 Uh we could have stuff like the algorithm on this previous slide that uh it has randomized branches where it makes a decision based on random bits and some of them keep going whereas others terminate. So that's not a deterministic infinite loop. There's no specific set of bits that makes it loop forever in the that's of course wrong. Um but it has probability zero. There's no uh it's subtle, right?

11:42 >> Probability. >> Yeah, even for for every time I think this is the proper statement. Um the slide is right as always if um [snorts] uh this is my inside joke with just myself. Um slides are of course always correct. um for every time that you're supposed to not wait longer, there's a probability that it uh that it might run longer. So this could be a problem. Uh but most of the algorithms that we have will not run into this problem. um specifically for our um probabilistic Turing machine for this die roll example. Um if we define things correctly then uh we'll find that the probability for it to run infinitely is zero precisely. And so to unroll unpack this a little bit, we have these infinite bit strings. And I think this is okay, this is um over it's a bit too alarmist.

12:51 uh we have these these prefix sets and um the way this roll die is made is that there's always whenever you have a branch there's after a finitely many steps there's a way to terminate and that means you always after a finite number of steps here three bits right you um lose a constant fraction of probability on stopping so it's always going to be a geometric pick some geometric series and the probability that you keep going forever is is just zero.

13:30 And we can um in particular we can define the expected number of of runs as we've done informally before even on on the notion of these infinite bit strings. It's well defined via these uh sigma algebra is defined by these prefix sets.

13:53 So formally let's define what a running time of a probabilistic touring machine is. We can finally leave this behind us. If we have a fixed set of bits, a fixed bit string, then it's easy. It's just a uh shortest t steps after which we are in the halting state. Same as before.

14:15 um like for with nondeterministic touring machines where we also had to deal with several potential runs if we don't specify. So here time with fixed random bits everything well defined time without that random thing is a random variable. Um, and here we're going to use the the worst case the the time uh is supposed to be the worst case time which could be infinite in this case. We'll just accept that that's a possibility. But then uh we can also define things like the expected time where you take the expectation over the random bits and you can take the so I think this is this is um a mistake. I would want this to be capital T. The worst case was capital time and the little uh the little time this should just be a random variable that is is random via this bit string and it is what it is like it's a random variable you can then study it with the usual rules.

15:49 Well, for the expectation, um it's well defined if the expectation is well defined, which it need not be, right? Uh you can have um do I want this capitalized or not? Ah, no I don't. Sorry. Uh, let me take this back. This is this is bad notation. I should eventually make this more intuitive. The capital capital time is for the worst case overall inputs of a size n. This is still a fixed input. So here little time with just xf fixed is the worst case over all random choices. If we need the random variable, we'll just write time with that row and say that row is random. I apologize. This is uh uh uh well, I think this is consistent. It's maybe not beautiful. Um if the expectation is is finite, then certainly also you terminate with probability one almost surely. But the converse may not be true. You can build sums that diverge, right? Even if you multiply with an exponential, uh you can say there's worse things than exponential.

17:11 So it's it's two separate things. Uh and maybe it was a bit too proud about all the nitpicks. Uh note that we have another complexity measure, namely the number of random bits that we consume. uh we'll often not worry about this too much, but let's introduce a notation analogous to time. It just does the very same thing. It measures how many random bits you take. Uh let's not read the full definition. Um you can never read more bits than you spend time because you read at most one bit a time, but it may make sense to restrict your algorithm to use these bits scarcely because they are a scarce resource. If you in practice want to generate properly random bits then they can be expensive and there's going to be a very good theoretical reason for the next unit.

18:04 Okay. Um let me stress that there's from the definitions similarities between randomization and non-determinism but kind of also not like we don't have a second tape for non-determinism but the the notion of verification of of verifiers has a bit of a similarity right the NP as verifiers you give a certificate and then the certificate is behaves a bit like the random bits tells the machine where to go so there's similarities the crucial difference is the uh the semantic um of when is a machine accepting something. For a nondeterministic machine, it's enough if if out of these exponentially many choices or computations that are possible, a single one accepts. And for randomization, we'll think of most should accept in the sense of most weighted by probability with with large probability they should accept.