I'm having trouble figuring out an algorithm for constructing a loser's bracket in a double elimination tournament. A naive approach would give something like this
But implementing it this way creates a problem: teams could potentially play repeat matches early in bracket. For example, if Team 9 loses their first match, then wins their subsequent loser's match, and Team 8 wins their first match and loses their next, Teams 8 and 9 will end up playing for a second time in bracket in loser's round 2 for 9th place. This could potentially result in a team getting a low placing while losing to the winner of the bracket twice. A loser's bracket that is more "fair" would have the lowest placing a team can get while losing to the first place team be as high as possible.
The first step of fixing this should be easy. If you reverse the order of which winner's matches map to loser's matches in loser's round to (in the example, switch L1 Loser with L4 Loser and L2 Loser with L3 Loser), then the lowest placement a team could get while losing to only the first place team goes from 9th to 5th, which is an improvement.
The real problem is that I can't figure out how to make this generalizable and work for larger tournaments, or even what approach I can take to get that answer. Any help would be appreciated.