What is the polynomial time reduction between these two Hamiltonian cycle problems? Problem 1: Given an undirected graph, return the edges of a Hamiltonian cycle, or correctly decide that the graph has no such cycle.
Problem 2: Given an undirected graph, decide whether or not the graph contains at least one Hamiltonian cycle.
What is the polynomial-time reduction of problem 1 to problem 2?

Let TSP1 denote the following problem: given a TSP instance in which all edge costs are positive integers, compute the value of an optimal TSP tour. Let TSP2 denote: given a TSP instance in which all edge costs are positive integers, and a positive integer T, decide whether or not there is a TSP tour with total length at most T. Let HAM1 denote: given an undirected graph, either return the edges of a Hamiltonian cycle (a cycle that visits every vertex exactly once), or correctly decide that the graph has no such cycle. Let HAM2 denote: given an undirected graph, decide whether or not the graph contains at least one Hamiltonian cycle.
From Roughgarden's online algorithms course

The solution:

If TSP2 is polynomial-time solvable, then so is TSP1. If HAM2 is polynomial-time solvable, then so is HAM1.
First the reduction from P2 to P1 is easy cause if you can decide whether there is one cycle you can also decide whether there is at least one cycle. The other way around is more tricky.
Notice that P1 can be solved in polynomial time if we have an oracle for P2 (an oracle for P2 means that we can use a subroutine that solves P2).
algorithm for P1 with input G = (V,E):
  E' = {} # edges of &quot;Hamilton Cycle&quot;
  run subroutine for P2 on G
  if there is no Ham. Cycle:
    report that there is no Ham. Cycle
  for e in E:
    run P2 on (V,E - {e})
    if (V,E - {e}) contains &quot;Hamilton Cycle&quot;:
      E &lt;- E - {e}   # remove e
    else:
      E' &lt;- E' + {e} # add e to cycle
  return E'

It uses the procedure for P2 $O(|E|)$ times, thus we obtained a polynomial reduction.