Why should I use X.509 Authentication over PKC based Authentication?

So I have two examples and I don't understand why one would be chosen over the other.

Example 1. A sends EPUb[r1] to B (asks B to prove knowledge of PRb) B replies with r1, EPUa[r2] (asks A to prove knowledge of PRa) A replies with r2 to prove it

Example 2. A sends r1 to B (asks B to prove knowledge of PRb) B replies with r2, EPRb[h(r1)], CertB (provides B with signature and certificate and own challenge) A replies with EPRa[h(r2)], CertA

Why would example 2 be better than example 1? Are there any security loopholes I'm not seeing in example 1 than example 2 fixes?

I'm studying for my cryptography exam tomorrow and been stumped by this example. Fast responses would greatly appreciated.

From what I can pick up on these two examples. Example 2, you provide each other with your public keys and you know the origin is trustworthy after you verify the certificates. When communicating you can then use each others public keys for encryption or you could establish a symmetric key which eliminates the man in the middle attack possibility.

In Example 1 all I can think of is that without the certificate they can't be sure the other entity is who they claim to be but then again to know each others public keys there must be some form of trust between them. Is example 2 better just because you can be MORE sure that the other entity is who they claim to be?