Tournament Trees

download Tournament Trees

of 35

Transcript of Tournament Trees

  • 7/27/2019 Tournament Trees

    1/35

    Tournament Trees

    Winner trees.

    Loser Trees.

  • 7/27/2019 Tournament Trees

    2/35

    Winner Tree Definition

    Complete binary tree with n external

    nodes and n 1 internal nodes.

    External nodes represent tournament

    players.

    Each internal node represents a match

    played between its two children;

    the winner of the match is stored atthe internal node.

    Root has overall winner.

  • 7/27/2019 Tournament Trees

    3/35

    Winner Tree For 16 Players

    player match node

  • 7/27/2019 Tournament Trees

    4/35

    Winner Tree For 16 Players

    4 3 6 8 1 5 7 3 2 6 9 4 5 2 5 8

    Smaller element wins =>min winner tree.

    3 6 1 3 2 4 2 5

    3 1 2 2

    12

    1

  • 7/27/2019 Tournament Trees

    5/35

    Winner Tree For 16 Players

    4 3 6 8 1 5 7 3 2 6 9 4 5 2 5 8

    height is log2 n (excludes player level)

    3 6 1 3 2 4 2 5

    3 1 2 2

    12

    1

  • 7/27/2019 Tournament Trees

    6/35

    Complexity Of Initialize

    O(1)time to play match at each match node.

    n 1 match nodes.

    O(n) time to initialize n-player winner tree.

  • 7/27/2019 Tournament Trees

    7/35

    Winner Tree Operations

    Initialize

    O(n) time

    Get winner O(1) time

    Replace winner and replay

    O(log n)time More preciselyTheta(log n)

    Tie breaker (player on left wins in case of a tie).

  • 7/27/2019 Tournament Trees

    8/35

    Replace Winner And Replay

    4 3 6 8 1 5 7 3 2 6 9 4 5 2 5 8

    3 6 1 3 2 4 2 5

    3 1 2 2

    12

    1

    Replace winner with 6.

  • 7/27/2019 Tournament Trees

    9/35

    Replace Winner And Replay

    4 3 6 8 6 5 7 3 2 6 9 4 5 2 5 8

    3 6 1 3 2 4 2 5

    3 1 2 2

    12

    1

    Replay matches on path to root.

  • 7/27/2019 Tournament Trees

    10/35

    Replace Winner And Replay

    4 3 6 8 6 5 7 3 2 6 9 4 5 2 5 8

    3 6 1 3 2 4 2 5

    3 1 2 2

    12

    1

    Replay matches on path to root.

  • 7/27/2019 Tournament Trees

    11/35

    Replace Winner And Replay

    4 3 6 8 6 5 7 3 2 6 9 4 5 2 5 8

    3 6 1 3 2 4 2 5

    3 1 2 2

    12

    1

    Opponent is player who lost last match played at this node.

  • 7/27/2019 Tournament Trees

    12/35

    Loser Tree

    Each match node stores the match

    loser rather than the match winner.

  • 7/27/2019 Tournament Trees

    13/35

    Min Loser Tree For 16 Players

    4 3 6 8 1 5 7 3 2 6 9 4 5 2 5 8

    4

    3

    8

  • 7/27/2019 Tournament Trees

    14/35

    Min Loser Tree For 16 Players

    4 3 6 8 1 5 7 3 2 6 9 4 5 2 5 8

    4

    6

    8

    3

    5

    1

    7

  • 7/27/2019 Tournament Trees

    15/35

    Min Loser Tree For 16 Players

    4 3 6 8 1 5 7 3 2 6 9 4 5 2 5 8

    4

    6

    8

    3

    5

    3

    7

    1

    6

    2

    9

  • 7/27/2019 Tournament Trees

    16/35

    Min Loser Tree For 16 Players

    4 3 6 8 1 5 7 3 2 6 9 4 5 2 5 8

    4

    6

    8

    3

    5

    3

    7

    2

    5

    2

    8

    1

    6

    4

    9

  • 7/27/2019 Tournament Trees

    17/35

    Min Loser Tree For 16 Players

    4 3 6 8 1 5 7 3 2 6 9 4 5 2 5 8

    4

    6

    8

    3

    5

    3

    7

    2

    5

    5

    8

    1

    6

    4

    9

  • 7/27/2019 Tournament Trees

    18/35

    Min Loser Tree For 16 Players

    4 3 6 8 1 5 7 3 2 6 9 4 5 2 5 8

    4

    6

    8

    3

    5

    3

    7

    2

    5

    5

    8

    1

    6

    4

    9

  • 7/27/2019 Tournament Trees

    19/35

    Min Loser Tree For 16 Players

    4 3 6 8 1 5 7 3 2 6 9 4 5 2 5 8

    4

    6

    8

    3

    5

    3

    7

    2

    5

    5

    8

    2

    6

    4

    9

  • 7/27/2019 Tournament Trees

    20/35

    4 3 6 8 1 5 7 3 2 6 9 4 5 2 5 8

    4

    6

    8

    3

    5

    3

    7

    2

    5

    5

    8

    2

    6

    4

    9

    1 Winner

  • 7/27/2019 Tournament Trees

    21/35

    Complexity Of Loser Tree

    Initialize

    Start with 2 credits at each node. Use one to pay for the match played at that

    node.

    Use the other to pay for the store of a leftchild winner.

    Total time is O(n).

    More preciselyTheta(n).

  • 7/27/2019 Tournament Trees

    22/35

    Winner

    4 3 6 8 1 5 7 3 2 6 9 4 5 2 5 8

    4

    6

    8

    3

    5

    3

    7

    2

    5

    5

    8

    2

    6

    4

    9

    1

    Replace winner with 9 and replay matches.

    9

    5

    9

    3

    3

    2

  • 7/27/2019 Tournament Trees

    23/35

    Complexity Of Replay

    One match at each level that has a match

    node.

    O(log n)

    More preciselyTheta(log n).

  • 7/27/2019 Tournament Trees

    24/35

    Tournament Tree Applications

    Run generation.

    k-way merging of runs during an external

    merge sort.

    Truck loading.

  • 7/27/2019 Tournament Trees

    25/35

    Truck Loading

    n packages to be loaded into trucks

    each package has a weight

    each truck has a capacity ofc tons

    minimize number of trucks

  • 7/27/2019 Tournament Trees

    26/35

    Bin Packing

    n items to be packed into bins

    each item has a size

    each bin has a capacity ofc tons

    minimize number of bins

  • 7/27/2019 Tournament Trees

    27/35

    Bin Packing

    Truck loading is same as bin packing.

    Truck is a bin that is to be packed (loaded).

    Package is an item/element.

    Bin packing to minimize number of bins is NP-hard.

    Several fast heuristics have been proposed.

  • 7/27/2019 Tournament Trees

    28/35

    Bin Packing Heuristics

    First Fit.

    Bins are arranged in left to right order.

    Items are packed one at a time in given order.

    Current item is packed into leftmost bin into which itfits.

    If there is no bin into which current item fits, start anew bin.

  • 7/27/2019 Tournament Trees

    29/35

    Bin Packing Heuristics

    First Fit Decreasing.

    Items are sorted into decreasing order.

    Then first fit is applied.

  • 7/27/2019 Tournament Trees

    30/35

    Bin Packing Heuristics

    Best Fit.

    Items are packed one at a time in given order.

    To determine the bin for an item, first determine setS

    ofbins into which the item fits. IfS is empty, then start a new bin and put item into this

    new bin.

    Otherwise, pack into bin ofSthat has least available

    capacity.

  • 7/27/2019 Tournament Trees

    31/35

    Bin Packing Heuristics

    Best Fit Decreasing.

    Items are sorted into decreasing order.

    Then best fit is applied.

  • 7/27/2019 Tournament Trees

    32/35

    Performance

    For first fit and best fit:

    Heuristic Bins

  • 7/27/2019 Tournament Trees

    33/35

    Max Winner-Tree For 16 Bins

    8

    4 3 6 8 1 5 7 3 2 6 9 4 5 2 5 8

    4 8 5 7 6 9 5 8

    7 9 8

    89

    9

    Item size = 7

  • 7/27/2019 Tournament Trees

    34/35

    7

    1

    Max Winner-Tree For 16 Bins

    6

    4 3 6 1 5 7 3 2 6 9 4 5 2 5 8

    4 6 5 7 6 9 5 8

    7 9 8

    9

    9

  • 7/27/2019 Tournament Trees

    35/35

    Complexity Of First Fit

    O(n log n), where n is the number of

    items.