We consider the alternating method (Kozlov, V. A. and Maz'ya, V. G., On iterative procedures for solving ill-posed boundary value problems that preserve differential equations, Algebra i Analiz 1 (1989), 144-170. (English transl.: Leningrad Math. J. 1 (1990), 1207-1228.)) for the stable reconstruction of the solution to the Cauchy problem for the stationary heat equation in a bounded Lipschitz domain. Using results from Baranger, T. N. and Andrieux, S., (Constitutive law gap functionals for solving the Cauchy problem for linear elliptic PDE, Appl. Math. Comput. 218 (2011), 1970-1989.), we show that the alternating method can be equivalently formulated as the minimisation of a certain gap functional, and we prove some properties of this functional and its minimum. It is shown that the original alternating method can be interpreted as a method for the solution of the Euler-Lagrange first-order optimality equations for the gap functional. Moreover, we show how to discretise this functional and equations via the finite element method (FEM). The error between the minimum of the continuous functional and the discretised one is investigated, and an estimate is given between these minima in terms of the mesh size and the error level in the data. Numerical examples are included showing that accurate reconstructions can be obtained also with a non-constant heat conductivity