A desired group can basically set the hierarchy by what they define as attractive.
Most people don't actually want to leave the social group that they're in, as pg observed in one of his essays. The one exception is when their group is specifically a lesser version of another, usually the hangers-on.The nerds may really like programming and have no desire to play sports -- but they would love to date the attractive girls from any group.
The verbal and physical abuse in the system comes from members of a group which has attractive members of the opposite sex trying to keep down the others. For example, the jocks know that the nerds would like to date the cheerleaders, and so the jocks act to keep their supremacy.
It's high school, it's all about sex, what did you expect?