{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# sol10 - COP3530 Solution 10 1 a 14(3 12(2 10(2 8(1 4(1 9(2...

This preview shows pages 1–3. Sign up to view the full content.

COP3530 Solution 10 1. a) 14(3) / \ 12(2) 10(2) / \ / \ 8(1) 4(1) 9(2) 6(1) / / \ 2(1) 5(1) 7(1) b) Remember the definition of the height-biased min leftist tree. \\ - has min-heap property - swap only if needed Meld right subtree with smaller root and the other entire tree. meld [4, 10 ] meld [9, 4 ] 9 / / \ ===> / / ===> / \ 2 6 9 5 2 5 4 / / 5 2 10 swap 10 ===> / \ ===> / \ 6 9 9 6 / \ / \ 5 4 5 4 / / 2 2 12 12 / \ swap / \ ===> 8 10 =====> 10 8 / \ / \ 9 6 9 6 / \ / \ 5 4 5 4 / / 2 2 2. To merge two k-tournament trees T1 and T2, we proceed as follows: mergetree(T1, T2) (returns a tree T) create (T) (creates T) size[T] = size[T1]+1 left[T] = T1 (or root[T1]) right[T]= T2 (or root[T2]) if value[T1] > value[T2] then value[T] = value[T1] else value[T] = value[T2] return T The merge operation can be done in O(1), or constant time.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
3. /** worst fit bin packing */ /** worst fit bin packing */ package applications; import dataStructures.*; import utilities.*; public class WorstFit { // top-level nested class public static class Bin implements Playable { // data members int unusedCapacity; // constructor public Bin(int theUnusedCapacity) { unusedCapacity = theUnusedCapacity; } // method of Playable
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 5

sol10 - COP3530 Solution 10 1 a 14(3 12(2 10(2 8(1 4(1 9(2...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online