electrolysis - selection of what is going to be on anode and cathode
It depends on its oxidation/reduction potentials. For example, in the electrolysis of a NaCl solution (in water), the reduction potential of water to H2 is -0.83 V while the reduction potential for Na+ to Na is -2.71 V. As the potential for water is greater, water will be reduced instead Na+.
Another example, a solution of CuSO4 in water, the potential reduction for Cu2+ to Cu is +0.34 V, greater than the -0.83 V for water, so the Cu2+ will be reduced.