If an ability I control is on top of the stack, can I cast an instant before it resolves? For example, I have Sarkhan the Masterless and a dragon on the board. An opponent attacks, triggering 1 damage from the dragon to the attacker. Can I cast Alchemist's Gift to give my dragon deathtouch before that damage resolves, or would I have to have given it deathtouch before the opponent declared attackers?
Yes this works the way you're hoping.
If Alchemist's Gift resolves and then the dragon is killed, the ability on the stack will also retain the deathtouch due to the "last known information" rule (113.7a in the MtG Comprehensive Rules as of February 2021):
Once activated or triggered, an ability exists on the stack independently of its source. Destruction or removal of the source after that time won’t affect the ability. Note that some abilities cause a source to do something (for example, “Prodigal Pyromancer deals 1 damage to any target”) rather than the ability doing anything directly. In these cases, any activated or triggered ability that references information about the source for use while announcing an activated ability or putting a triggered ability on the stack checks that information when the ability is put onto the stack. Otherwise, it will check that information when it resolves. In both instances, if the source is no longer in the zone it’s expected to be in at that time, its last known information is used. The source can still perform the action even though it no longer exists.