Video 7-1: Randomization, Selection Lower Bounds
CS 627 – Advanced Algorithms (Winter 2026-27) · unit page
· YouTube
2026-11-23, 22:49
← Video 6-10: DP over Tree DecompositionsVideo 7-2: Selection Lower Bound →
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:04 In the last units, we talked about fixed parameter tractability. And the main idea there was let's not give up much. We still want precise, optimal, exact solutions all the time, but at least the running time is allowed to be a bit worse in terms of how hard the input is. And we formalize that in terms of a parameter. Now, sometimes this doesn't help in that even with this slightly more clever angle, you're not able to get your problem into a shape that you can solve. And maybe that's just what it is. So, you have to compromise at something. And the two other loopholes of of NP hardness theory that we looked at was either give up the always correct part and that's what we'll look at here. Uh the other one is give up the always optimal part or give up the optimal strictly optimal part. We'll look at that uh at the end of the module. But for now, let's say we're taking the gamble that things may sometimes go wrong. [snorts] Uh we'll look at that in in some detail.
1:10 First for today, I I'll show you some some uh example that's not an NP hard problem uh but one where we see a a very clear-cut and easy to state distinction between doing a randomized algorithm and deterministic. It's also completely without any assumptions. It's uh fully rigorous and proven. There is more power to randomization. Full stop. That's what this first example will show. uh then I'll I'll spend some time defining what we mean by randomized computations. I found this rather enlightening when I first thought about it. We'll see if you uh if you agree. Uh and then we'll look a bit at um some um some basics from the analysis side. Uh most most specifically the tail inequalities or concentration inequalities that help to analyze algorithms that use randomness. So um step by step though uh in the first bit as I as I mentioned um why do we look at randomness or randomization uh we have to somehow uh give up something let's give up the always and allow the algorithms to occasionally fail but the type of algorithms we've looked at so far that doesn't this doesn't make sense I mean if I give them a specific input a deterministic algorithm will always produce the same output So either it is always correct or it's always wrong. Uh if it's a yes no question there's nothing in between. So we must use some form of non-determinism in the sense that same input may not need and necessarily go to get you the same output. And randomization is both theoretically and practically the only useful alternative that I I think we have here.
3:01 You could throw in quantum, but let's certainly not talk about practical at this point. Um, and I don't like the theory as much, but that's a bad reason. That's just me. Uh, let's use randomization instead. So, we allow random bits to guide the computation. We'll formalize this later what it exactly means. And and we'll allow the output to depend on these random bits also in the sense that it sometimes is wrong. Um but uh we'll see that's the rest of this unit. We can make it with relatively simple techniques so that this probability of failure is so small that it's practically irrelevant and you can precisely quantify how much you have to pay for making it small in a certain sense and so on. I think all of this is very well understood. Let let me also point out that it's a real thing. We can use randomness for all practical purposes in our computations. in two ways. You can have actual physical randomness measured from some say an electrical resistor. You measure the noise and that's random to a good degree. It's just not very fast. It doesn't give you a ton of random bits.
4:12 Uh and then there's this notion of of uh pseudo random number generators that I'm sure you you know as well uh that you just take some computation that looks for all intents and purposes random. And um what exactly that means is usually fluffed a lot, right? What is random enough? We'll make this extremely precise in the next unit when we look at the um complexity theory behind this. Again, I think I I think a rather enlightening piece of theory uh that helps there. Does there is there any hope that this helps? So um intuitively it seems whenever you think about real life it seems much easier to have something that mostly works but occasionally fails even if this availability is maybe a bit hard to get to in usual scenarios but something that never ever fails no matter what seems sub uh qualitatively different.
5:12 What we'll hope to get is is that the algorithms are faster and simpler often. That's a nice side effect. Um why should we have hope that this might work? Well, hashing is a key technique that you all know. Um and it seems to work wonders in many simple uh cases like dictionaries where you have lower bounds to run against if you don't use anything like that. Um, so we can uh we can use short short fingerprints of complicated objects to quickly rule out that they're equal. And that's a powerful general principle. Uh, the other one maybe a bit more subtle, but you've also seen examples of this. Think of quicksort. You can protect against these odd really awkward scenarios where what you do doesn't quite work. If they're rare enough, you may not care. But an deterministic algorithm will ex will always have an input where they happen deterministically. If you randomize then you turn that into an unlikely thing to happen on any input.
6:17 Um there's also just in pure maths uh cool applications of of randomness in the sense that you don't you don't even care about something that is originally random but you use random uh an explicit randomization in some otherwise just combinatorial object to make proofs easier. And um this is called in general the probabilistic method. you you show that there's a nonzero probability that some randomly constructed object has a certain property. Well, if the probability is non zero, there's at least one such object. End of proof. It's entirely non-constructive. There's no way for you to get to that object unless you throw in other intelligence. And um the type the type of [snorts] um results that you get there is is uh was called Ramsey theory for example.
7:17 And the classic one is in any large enough graph. If you have a a graph a complete graph of six uh let me let me draw the edges differently. Um a complete graph of six vertices. And now I'm coloring the edges either red or blue.
7:35 And uh the goal is to avoid triangles. I'm trying not to make a triangle, but I might try hard. I'm missing some edges. No.
7:50 Yeah. And there you go. So, this this is a triangle. Now, let me try not to make that red. So, let's make it blue.
8:06 I'm still missing edges. And now I made a blue triangle. So it turns out you can prove uh no matter how you put the edges red or blue I was uh set to fail. It cannot work. Every graph that is colored in red or has his edges colored red or blue um that has at least six vertices contains a monochromatic triangle. [snorts] And you can uh uh as an exercise you can see for K5 if it fails there you can still win this game of coloring. And the Ramsey theory says oh what if uh the graph is larger and I'm interested in a monochromatic complete graph monochromatic click of larger sizes. So, say I want a a monochromatic 17 click for some reason. How large does my graph have to be until I'm certain that one occurs no matter how you color the edges? And um I'm not going to do any proofs here. And Ramsey theory is one of these things that are really hard to get precise answers. Often we know only very loose bounds. But you think about a an enormously large graph and you color the edges with probability 1/2 red or blue.
9:37 Uh if you wait long enough, there's enough independence in this that all the there's a lot of 17 vertex subsets and each has a small tiny probability to be monochromatic. If you make the graph big enough by union bound, there will be one. there will be well the expectation of how many monochromatic 17 clicks you'll have will eventually turn positive and if the expectation is positive well then there is an example where it's not zero whereas otherwise I think we know no other route to proving such things sometimes yeah so random randomization seems seems rather crucial there and um a tool that has power that we don't know how to match in in other ways and of course again finding I mean this uh construction of monochromatic clicks there's no way to construct this graph just out of this random uh probabilistic method argument.
10:38 Uh let me let me point out the difference maybe this is uh not needed here in full detail. Uh it it sounds a bit similar to doing an average case analysis where the inputs are random. Um the stress is that really we want the expectation over random choices that we make. We are full in control. The randomness we're in the driver's seat. We explicitly design when things are randomly decided and then the input can be chosen adversarially. We're adversarily subject to not knowing our random choice otherwise we're too transparent. Now analysis technique-wise the two are often the same because you can start by analyzing your algorithm assuming a random input and often that's effectively what you're trying to make the randomized algorithm do. So the analysis often looks the same but uh the conceptual ideas will will always live on this side that uh we don't rely on the inputs to be be nice structured and random. Uh instead we want to force them force the algorithms to behave as if they were.
12:00 Let me give a concrete example where we can pin down very precisely and and beyond any doubt that randomization has um more power than than using a deterministic algorithm. And that's the good old um selection by rank example quick select and its friends. So this is not really a hard problem in the sense of this module, right? This uh it's not even close to being np hard or anything like this. So maybe it's a bit of a side story. Think of it as just a a motivation um by metaphor.
12:34 So you know quick select we can find out of uh an array of numbers we can find the kith smallest or precisely um suppose you just sort the array and pick the index k that's what we mean. So that definition covers duplicates as well. And of course you can um wish for any rank and we we'll specifically care about finding the median of an input. So here's quick select and the really the way you want to do this is with a random pivot so that you're not running against a quadratic worst case. Now the correct worst case of course still exists with randomization but now this is worst over our random in random bits not about the inputs not over the inputs. Uh of course I'm aware that there's also the median of medians algorithm that gets this done deterministically in linear time but for this for this section we'll care about the constants and their median of medians kind of sucks. the constant is fairly large.
13:43 Let's look at selection with precisely this constant factor in front in mind. And um you can prove that any deterministic comparison based algorithm. So in the same category as uh we want our algorithms to be is all about counting comparisons. Um for finding the median of n elements you need to pay two comparisons per element asmtoically.
14:14 Uh this is not the best known bound. There's actually some slightly larger bound just above two which maybe a two to the minus 80 you don't care about. But the point is people for some time thought maybe two is the truth but it's not. Uh also three is not the truth. There used to be an algorithm the best known for a long time was 3 * n and people thought ah maybe that's the truth but neither is there's an algorithm strictly better and there's a lower bound strictly better so the truth is somewhere between two and three strictly okay now uh sad confession uh the proof of this theorem led a bit too far so I'm not going to show this I'm instead going to show a weaker result which says uh one and a half comparisons per element asmtoically. Um same otherwise so still a deterministic algorithm and in this case you'll have to take my word for it or the word of of Bend and John that you can extend this proof to show 2N uh yeah it just gets a bit a bit more technical. I didn't want to spend all our time uh analyzing selection algorithms as much fun as it is. Uh but let's see if we can we can um prove the 1.5 bound um and we'll start with um the a simple case.
15:42 So how do you in general prove lower bounds for such a case? We've seen or you've seen in in in undergrad algorithms classes things like uh the information theory bounds for sorting. Any comparison based algorithm has to learn that many bits about the input to distinguish all possible input orderings. Hence it needs to spend log base 2 of n factorial bits n factorial comparisons because that's the number of different inputs there are n factorial for sorting. You could try the same here. um and that's going to be in a way the first step but it's a rather um insufficient bound in this case. So the other maybe let's do that for you know what let's do that first and we'll do the the proper adversary proof next time. The other technique you have is to construct a specific adversary uh which is another algorithm that produces the input you get to your deterministic algorithm on the fly making its choices depending on what you've done to try to fool you. That's why it's an adversary. They're trying to make make you look bad.
16:55 That's the only other technique um that often works. Um but let's let's first try So what I mean by that is um we have n elements that we know nothing about initially. um these guys and suppose we fix the scenario we want the median.
17:40 Now what does this mean and for sake of simplicity let's assume they're all different. This is a is one specific case. We're showing a worst case bound. So, you know, oh, come on. Nope. Wrong direction.
18:29 In the end, we want to have learned about some specific element that it is the median and that's all we care about. So, how many comparisons do we need to spend for that? Well, the algorithm needs to be sure. In other words, I cannot have I cannot allow an adversary to kind of produce two inputs that I react on the same but where the median is different because then one of the two would make me report the wrong result. So I have to make sure that what I return as the median is also kind of proven to be the median.
19:24 And what's the certificate of that element being the median out of all the other elements? Well, I need somehow indirect comparisons. A chain of comparisons via transitivity has to prove that half of the elements are smaller and half of the elements are larger. That's the definition of the median. So I need somehow comparisons to the top and to the bottom. So the certificate here means we need to know and this is a bit of a the algorithm needs to acquire this information via comparisons. That's what what it means.
20:11 And uh if I if I know that there's n half elements above a certain value, I also know which ones which of the input they are.
20:41 and you can uh there's different ways to to look at this but essentially each of these elements contributes one bit of information. uh it either either is at the top or it is at the bottom. Or you could also say um I must have compared the median to all of these elements at least indirectly. Maybe I didn't ask specifically is this larger than this. Maybe it's a chain of comparisons.
21:09 But I definitely need n minus one comparisons for proving that this guy is the median. I cannot do it with fewer. If I use less than that, then there's one element where I didn't do any comparison that places it against M. And then this element could either be larger or smaller than the median. And one of the two options must make my choice invalid. Pick pick pick the sizes of the elements odd so that uh you know there's a unique median. So that's that's the information theory lower bound which is uh um only one comparison. So that's not very informative. It basically says I need to read the input to compute the median. Well thanks. That's uh already clear. So to do better than that you need to have an additional argument. It turns out that no algorithm can actually just come up with this certificate from the start. There's this is provably impossible as we'll see next time. I need to spend extra comparisons necessarily just to find the right certificate.
22:17 This is why this is harder than proving lower bounds for sorting where this was all that we had to do. Count the different cases that occur and take the log and that that's it. Um, by the way, this is another way to get to the get to the bits here. the the number of different options you have it's uh n choose n /2 and take log of that you get again uh essentially n comparisons that's not sufficient here so we'll have to work a little harder for the lower bound Okay.