# Quickly write a unitary transformation connecting two arbitrary states

This is for an introductory QM course. Say, I have pure states $$\vert\alpha\rangle$$ and $$\vert\beta\rangle$$. I would like to find a unitary operator that takes me from one to the other. What is the obvious way to do this? I also realize that the constraints are not fully specified but that's fine.

If I try $$U = \vert\beta\rangle\langle\alpha\vert$$, this seems to do the job but is not unitary. Other approaches seem quite messy e.g. the answer at Unitary transformation from pure unentangled state to pure entangled state (nothing to do with entanglement).

What is an efficient way to find the requisite $$U$$ given the states in question?

More generally, if $$\{ | \phi_i \rangle \}$$ is a orthonormal basis, and $$\{ | \psi_i \rangle \}$$ another, then $$U: | \phi_i \rangle \mapsto | \psi_i \rangle$$ (or, formally, $$U = \sum_i | \psi_i \rangle\!\langle \phi_i |$$) is unitary.
So, you just have to find such orthonormal bases with $$|\alpha\rangle = |\phi_0\rangle$$, $$|\beta\rangle = |\psi_0\rangle$$. Than can be done e.g. using the Gram-Schmidt process.
To simplify notation and make manipulations easier, let's focus on a finite Hilbert space $$H$$ that is spanned by a complete orthonormal set {$${|\phi_1 \rangle, |\phi_2 \rangle,...,|\phi_N \rangle }$$}. Let's look for a unitary operator $$U$$ that switches two states, and we can take them to be $$|\phi_1 \rangle$$ and $$|\phi_2 \rangle$$ without loss of generality. Then: $$U|\phi_1 \rangle=|\phi_2 \rangle$$ $$U|\phi_2 \rangle=|\phi_1 \rangle$$ $$\langle\Psi |U^{\dagger}U|\Psi \rangle=\langle\Psi |\Psi \rangle$$
By simple analogy to how this would be done in $$\mathbb{R}^N$$, we can choose:
$$U=|\phi_1 \rangle \langle\phi_2 |+|\phi_2 \rangle \langle\phi_1 |+\sum_{i=3}^N|\phi_i \rangle \langle\phi_i |$$
Using this expression for $$U$$ in the first three equations, and using the stated facts that the states are orthonormal, i.e. $$\langle\phi_i |\phi_j \rangle=\delta_{ij}$$, and that this basis set is complete, i.e. $$\sum_{i=1}^N|\phi_i \rangle \langle\phi_i |=I$$, it is easy to show that this is the correct expression for $$U$$.