In this section, we will sort out which of the three terms in the first law are path dependent, and which are not.
For example, in the P-V diagram below, an ideal (monatomic) gas started from state 1 and ended in state 2.
Its internal energy at state 1 is .
Its internal energy at state 2 is
The change in internal energy from state 1 to state 2 is .
Notice that ΔU is the same, whether the gas took the red path (1→3→2) or blue path (1→4→2) or whichever other path, as long as we start and end at the same states. In bombastic jargon, we say that since the internal energy is a state function dependent only on the state, ΔU is path independent.
To calculate the work done by the gas during state 1 to state 2, we need to know the specific thermodynamic processes undertaken by the gas. For example, the work done by the gas (shaded in purple) if the gas underwent an isobaric expansion before an isochoric cooling (1→4→2), is more than the work done by the gas (shaded in red) if it underwent an isochoric cooling first before an isobaric expansion (1→3→2). So work, unlike internal energy, is path dependent.
Using our example, we note that ΔU is the same regardless of the path taken. But WON is more negative for path 1→4→2 than path 1→3→2. So it is obvious from the first law that Q is more positive for the former. So heat, just like work, is also path dependent.
Basically, we can use different combinations or heat supply/removal and compression/expansion to move a gas from one state to another state. But if the start and end states are the same, Q and WON always sum up to the same ΔU.