
Title:
13ps06 A Better Tree Solution

Description:

All right, so let's take a look at how I decide to do this.

Like I said, you set up a second vertex called u and set it to equal to 1.

In other words, it's not set to any actual vertex in the graph at first.

So for every single element in the upper triangular portion of the adjacency matrix

since we're presenting this as an adjacency matrix,

we check if there is an edge between those two vertices between vertices I and J.

And if there is, then we check if the assignment for I and J is zero

that is they're not none anymore, we have specifically set them to not be in the assignment.

Well, if both of them are explicitly out of the assignment and there's an edge between them

well then that's not going to be a valid vertex cover, so we return float infinity.

Now, otherwise, if we find that the assignment for both I and J is equal to none,

then that means we haven't actually look at this yet, so it's a good candidate for setting v and u

so that we set u equal i and v equal to j and we continue on.

Now, once we go through the entire double for loop, we check if v is still on set.

If v is still on set, that means first of all we didn't fall out of this by not having a valid vertex cover

and second of all, it means that all the vertices have been assigned to something rather

because that's the only way that v could still be set to 1

and if v is set to 1, then note that u also is.

Now, if that's the case, then we set a variable size equal to zero

and we start simply counting up all of the different vertices in the assignment.

If the vertex is set in the assignment, then we increment size.

It it's still unset, well then we have to do a little bit of manipulation here.

We'll just set the vertex i to 1 if a neighbor is zero

because we want to make sure that this is still a valid vertex cover.

So, for every j in range iwell, I just realized I put an i in here.

Well, then there are unnecessary just a slight inefficiency,

you can boost this to i+1 since we don't allow any loops in the graph.

If we did, then we would have to simply use i but this doesn't really particularly matter for this.

Moving on, so for every other vertex in the graph, we check if there is an edge between i and j again

and if there is and if the assignment of j is zero, well then, we have to set i

and we say that the size is an additional element because we now have to set i,

and once we go through all this, we return the size and that's done.

Now, for each of these for the recursive part that you don't have to worry about,

we try all the different possible combinations that aren't zerozeros

since that would not be a valid vertex cover.

We try 1, 0; 0, 1; and 1, 1.

We compute the size for each of these and then we return the minimum of those

and compute this whole thing recursively.

So that was a little tricky. If you had trouble with that, totally understandable.

This does give you a little bit of improvement in the total size

of the search tree we end up searching through.

Before, it was 2 to the endNow, we got about 1.733 to the end.

It might not seem like much but in practice, it can be helpful.

So, okay. Let's go ahead and look a different problem now.