Docsity

Tournament Trees - Advanced Data Structures - Lecture Slides, Slides of Computer Science

Partial preview of the text

Download Tournament Trees - Advanced Data Structures - Lecture Slides and more Slides Computer Science in PDF only on Docsity!

Tournament Trees

Winner trees.

Loser Trees.

Winner Tree – Definition

Complete binary tree with n externalnodes and n – 1 internal nodes.

External nodes represent tournamentplayers.

Each internal node represents a matchplayed between its two children;

the winner of the match is stored atthe internal node.

Root has overall winner.

Winner Tree For 16 Players

player match node

Winner Tree For 16 Players

Smaller element wins => min winner tree.

Winner Tree Operations

• Initialize

 O(n) time

• Get winner

 O(1) time

• Replace winner and replay  O(log n) time

 More precisely Theta(log n)

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

Replace Winner And Replay

Replace winner with 6.

Replace Winner And Replay

Replay matches on path to root.

Replace Winner And Replay

Replay matches on path to root.

Min Loser Tree For 16 Players

Min Loser Tree For 16 Players

Min Loser Tree For 16 Players

Min Loser Tree For 16 Players

Min Loser Tree For 16 Players

1 Winner

Complexity Of Loser Tree

• Start with 2 credits at each node.Initialize

• Use one to pay for the match played at thatnode.

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

• Total time is O(n).

• More precisely Theta(n).

Winner

Replace winner with 9 and replay matches.

Truck Loading

  n packages to be loaded into truckseach package has a weight

  each truck has a capacity of c tonsminimize number of trucks

Bin Packing

• n items to be packed into bins

• each item has a size

• each bin has a capacity of c tons

• minimize number of bins

Bin Packing

Truck loading is same as bin packing. Truck is a bin that is to be packed (loaded).

Bin packing to minimize number of bins is NP-hard.Package is an item/element.

Several fast heuristics have been proposed.

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 it

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

new bin.

Bin Packing Heuristics

• Best Fit Decreasing.

  Items are sorted into decreasing order.Then best fit is applied.

Performance

• For first fit and best fit:

Heuristic Bins <= (17/10)(Minimum Bins) + 2

• For first fit decreasing and best fitdecreasing:

Heuristic Bins <= (11/9)(Minimum Bins) + 4

Max Winner-Tree For 16 Bins

Item size = 7

Max Winner-Tree For 16 Bins