How to obtain the basis functions in DG space

Well, they will of course give the same result, as by setting the ith and jth degree of freedom to one, you are making a global basis function.

This only works for specific spaces (Lagrange, DG), and not necessarily for Nedelec/RT, as covered in: Assemble with dolfin VS dolfinx - #2 by dokken

Note that the second approach is doing alot more work than the first approach.
It will integrate over the whole domain M**2 times (M=V.dim()), while the first approach does the integration once.

I still do not understand the need for the tabulated values of a basis function here?

You have also not explained what is wrong with the approach in: