In short they are both correct and can be used in both structures. These are expressions usually used for comparing and contrasting.
EX: Do you prefer studying or sleeping? Do you prefer to study or to sleep?
Or you can just use it the way you did in your question.