What is the most efficient way to become proficient at melodic dictation? Could you give a basic algorithm which one can follow to learn to transcribe music in different keys?
Melodic dictation is a process that is built off of many skills that you will build incidentally if you study theory and ear training. These skills boil down to two main things:
Your ability to recognize musical patterns, particularly those patterns that pertain to the idiom you're dictating, and
Your ability to hear those patterns
Imagine a case where you'd never heard the major scale before and the melody you were trying to dictate was... the major scale. In this hypothetical where you've never heard it before, it would probably be quite tough for you. You would have to listen for each interval individually and you'd pretty likely miss the big picture entirely because you wouldn't know what you're listening to. In contrast, someone who has been exposed to the major scale will be able to solve this dictation task pretty quickly since they'll be aware of what it is and they'll know what's coming every step of the way.
The actual process of melodic transcription is a lot like this. Most collections of notes aren't arbitrarily connected and by far the easiest way to listen to something and write it down is to be able to quickly relate it to something you already know. You are likely not going to have a repository of every possible combination of notes in your head (given that this is impossible), but if you can make general, scope-narrowing assertions, like "this is diatonic" or "hey wait a minute that's just the same note over and over again" then the process of melodic dictation becomes much easier.
Depending on how difficult the thing you're dictating is you're probably still going to run into some things that you can't relate to a pattern, and you will probably spend a disproportionately long amount of time looking at them and trying to figure out what they are. But you want to minimize this part of the process as much as you can.
In short, the most efficient way to get good at melodic dictation is to develop and foster an inventory of patterns in melodies, in particular melodies in the same style as the thing you're dictating, and then train your ear to recognize them. If that sounds very far removed from the actual process of melodic dictation, that's because it is: Melodic dictation is a high level skill built from the development of many other low level skills.