In both cases, the more prepared you are the better. If you have the time and energy, it is best to plan for all possible contingencies, to have detailed scripts and props prepared, and to take the time to account for the various playing (learning) styles of the people you will be working with. That said, as you gain more experience in DMing and teaching, the fewer notes you need to make for a successful session.
You have to be ready to "wing it." Players and students are adept at tearing the best laid plans apart. Also, there are "teachable moments" where greatness happens in a game or a classroom that no plan could possibly hope to recreate. Whatever the reason, it is important to adapt. Sometimes that tremendously intricate plan you had for the day can be used later; sometimes it gets scrapped entirely. You have to be open to those possibilities.
You need to be in control of the environment of the game or class. While the players or students might force you to change your plans, it's up to you to run the game or class. Students and players alike depend on you to provide a level of dependable, consistent structure. You are expected to get them interested and keep them in the game or lesson. You can't expect them (whether they are high school sophomores or grown men with an average age in the mid forties) to take the initiative on their own. You are in charge of the game (or class) and need to keep the focus on it.
It is also up to you as to how much you want to incorporate from "canned" campaigns or lessons. I have found that both my best games and my best lessons come from a mix of published works and my own imagination. It is important to know what fits your DM or teaching style and that it's okay to lose the rest.
I am certain that there are more comparisons to be made, but there is one last one to leave people with. People are going to complain. It is important to know when their concerns are valid and when they are just whining because the world isn't working they way they want at the moment. Don't take the complaints personally, even though both of these ventures require a great deal of personal investment. In the end, we have to be able to divorce ourselves from the roles we play, even if the roles are being a DM or a teacher.