A pitcher contained 5g-2 gallons of water. Water was then poured from the pitcher into a glass that has a capacity of (g-5)gallons how many gallons of water are left in the pitcher?

You have two different volumes:

(Pitcher) 5g-2

(Glass) g-5

To know how many gallons of water were left in the pitcher after pouring water into the glass you have to subtract the glass volume from the pitcher volume:

5g-2 - (g-5)

5g-2-g+5

Rearrange the equation (to see it clearly)

5g-g+5-2

4g+3 These are the gallons of water left in the pitcher.