Best-fit bin packing in O(n log n) time

Slides:



Advertisements
Similar presentations
COSC 2007 Data Structures II Chapter 14 External Methods.
Advertisements

Interval Trees Store intervals of the form [li,ri], li <= ri.
1 Pertemuan 12 Binary Search Tree Matakuliah: T0026/Struktur Data Tahun: 2005 Versi: 1/1.
Winner trees. Loser Trees.
Dictionaries Collection of items. Each item is a pair.  (key, element)  Pairs have different keys.
Binary Search Trees Dictionary Operations:  IsEmpty()  Search(key)  Insert(key, value)  Delete(key)
Digital Search Trees & Binary Tries Analog of radix sort to searching. Keys are binary bit strings.  Fixed length – 0110, 0010, 1010,  Variable.
CS 206 Introduction to Computer Science II 12 / 01 / 2008 Instructor: Michael Eckmann.
AVL trees. AVL Trees We have seen that all operations depend on the depth of the tree. We don’t want trees with nodes which have large height This can.
Chapter 9 contd. Binary Search Trees Anshuman Razdan Div of Computing Studies
1 Section 9.2 Tree Applications. 2 Binary Search Trees Goal is implementation of an efficient searching algorithm Binary Search Tree: –binary tree in.
Lecture – Searching a Tree Neil Ghani University of Strathclyde.
Priority Search Trees Keys are pairs (x,y). Basic (search, insert, delete) and rectangle operations. Two varieties.  Based on a balanced binary search.
Binary Search Trees Dictionary Operations:  get(key)  put(key, value)  remove(key) Additional operations:  ascend()  get(index) (indexed binary search.
Binary Search Trees Dictionary Operations:  search(key)  insert(key, value)  delete(key) Additional operations:  ascend()  IndexSearch(index) (indexed.
Winner trees. Loser Trees.
AVL Tree: Balanced Binary Search Tree 9.
Indexing Structures for Files
Dictionaries Collection of items. Each item is a pair. (key, element)
Lecture 15 Nov 3, 2013 Height-balanced BST Recall:
Lec 13 Oct 17, 2011 AVL tree – height-balanced tree Other options:
Multiway Search Trees Data may not fit into main memory
Recursive Objects (Part 4)
Insertion/Deletion in binary trees
Binary Search Trees A binary search tree is a binary tree
Binary search tree. Removing a node
Binary Search Tree (BST)
Chapter 11: Multiway Search Trees
Multidimensional Range Search
Multiway search trees and the (2,4)-tree
AVL Tree.
Binary Search Tree Chapter 10.
Tree.
Red-Black Trees 9/12/ :44 AM AVL Trees v z AVL Trees.
Section 8.1 Trees.
Digital Search Trees & Binary Tries
Binary Search Trees Dictionary Operations: Additional operations:
Chapter Trees and B-Trees
Chapter Trees and B-Trees
Chapter 10: Non-linear Data Structures
Binary Search Trees.
Interval Heaps Complete binary tree.
Red-Black Trees 11/13/2018 2:07 AM AVL Trees v z AVL Trees.
Trees and Binary Trees.
(2,4) Trees (2,4) Trees 1 (2,4) Trees (2,4) Trees
Priority Search Trees Keys are pairs (x,y).
Red-Black Trees v z Red-Black Trees 1 Red-Black Trees
Red-Black Trees 11/26/2018 3:42 PM AVL Trees v z AVL Trees.
Search Sorted Array: Binary Search Linked List: Linear Search
B-Tree.
Priority Queues (Chapter 6.6):
Digital Search Trees & Binary Tries
Balanced Binary Search Trees
Lecture 36 Section 12.2 Mon, Apr 23, 2007
CMSC 341 Splay Trees.
General Trees A general tree T is a finite set of zero or more nodes such that there is one designated node r, called the root of T, and the remaining.
Red-Black Trees 2/24/ :17 AM AVL Trees v z AVL Trees.
AVL-Trees (Part 1).
Podcast Ch18a Title: Overview of Binary Search Trees
Trees.
Chapter 20: Binary Trees.
Lecture 10 Oct 1, 2012 Complete BST deletion Height-balanced BST
Basic Data Structures - Trees
Priority Queues (Chapter 6):
Sorted Binary Trees.
B-Trees.
Red-Black Trees 5/19/2019 6:39 AM AVL Trees v z AVL Trees.
Bin Packing Michael T. Goodrich Some slides adapted from slides from
Data Structures Using C++ 2E
CS210- Lecture 19 July 18, 2005 Agenda AVL trees Restructuring Trees
Presentation transcript:

Best-fit bin packing in O(n log n) time The search tree will contain one element for each bin which is in use and has non-zero available capacity Notice! It is possible that for two or more bins to have the same available capacity

Best-fit bin packing in O(n log n) time Example Suppose that when object i is to be packed, there are nine bins (a through i) in use. Available capacity of these bins are 1, 3, 12, 6, 8, 1, 20, 6 and 5, respectively. The nine bins may be stored in a binary tree with duplicates, using as key the available capacity of a bin.

Best-fit bin packing in O(n log n) time A possible binary search tree. h 6 b c 3 12 a i g d 1 5 6 20 8 e f 1

Best-fit bin packing in O(n log n) time Object I that is to be packed requires s[i] = 4. h Root h fits, proceeds to the left subtree. 6 b c 3 12 a i g d 1 5 6 20 8 e f 1

Best-fit bin packing in O(n log n) time Object I that is to be packed requires s[i] = 4. h 6 b c 3 12 a i g d 1 5 6 20 8 e f 1

Best-fit bin packing in O(n log n) time Object I that is to be packed requires s[i] = 4. h b fails, proceeds to the right subtree of b. 6 b c 3 12 a i g d 1 5 6 20 8 e f 1

Best-fit bin packing in O(n log n) time Object I that is to be packed requires s[i] = 4. h 6 b c 3 12 a i g d 1 5 6 20 8 e f 1

Best-fit bin packing in O(n log n) time Object I that is to be packed requires s[i] = 4. i fits, proceeds to the left subtree of i. h 6 b c 3 12 a i g d 1 5 6 20 8 e f 1 i doesn’t have any left child, it is the best candidate.

Best-fit bin packing in O(n log n) time Another example, object I that is to be packed requires s[i] = 7. h fails, proceeds to the right subtree of h. h 6 b c 3 12 a i g d 1 5 6 20 8 e f 1

Best-fit bin packing in O(n log n) time Another example, object I that is to be packed requires s[i] = 7. h 6 b c 3 12 a i g d 1 5 6 20 8 e f 1

Best-fit bin packing in O(n log n) time Another example, object I that is to be packed requires s[i] = 7. c fits, proceeds to the left subtree of c. h 6 b c 3 12 a i g d 1 5 6 20 f e 1 8

Best-fit bin packing in O(n log n) time Another example, object I that is to be packed requires s[i] = 7. h 6 b c 3 12 a i g d 1 5 6 20 f e 1 8

Best-fit bin packing in O(n log n) time Another example, object I that is to be packed requires s[i] = 7. d fails, proceeds to the right subtree of d. h 6 b c 3 12 a i g d 1 5 6 20 f e 1 8

Best-fit bin packing in O(n log n) time Another example, object I that is to be packed requires s[i] = 7. h 6 b c 3 12 a i g d 1 5 6 20 f e 1 8

Best-fit bin packing in O(n log n) time Another example, object I that is to be packed requires s[i] = 7. e fits, proceeds to the left subtree of e. h 6 b c 3 12 a i g d 1 5 6 20 f e 1 e has no left child, so e is the best candidate. 8

Best-fit bin packing in O(n log n) time When we find the best bin, we can delete it from the search tree, reduce its capacity by s[i], and reinsert it (unless its remaining capacity is zero). If we do not find a bin with enough capacity, we can start a new bin.