Download presentation

Presentation is loading. Please wait.

Published byJenny Tatham Modified over 2 years ago

1
CS223 Advanced Data Structures and Algorithms 1 Greedy Algorithms Neil Tang 4/8/2010

2
CS223 Advanced Data Structures and Algorithms 2 Class Overview Basic idea Examples: “Greed is good” The bin packing problem and the algorithms The path scheduling problem and the algorithms: Greed is no good.

3
CS223 Advanced Data Structures and Algorithms 3 Basic Idea In each phase, it makes the best choice based on the current partial solution and the performance metric. No future consequences are considered when making decisions. Usually it will not go back to change the previous choices.

4
CS223 Advanced Data Structures and Algorithms 4 Examples: “Greed is good” Dijkstra’s algorithm Prim’s algorithm Kruskal’s algorithm

5
CS223 Advanced Data Structures and Algorithms 5 Bin Packing Bin packing: Given N items with sizes s 1, s 2,…, s N, where 0 s i 1. The bin packing is to pack these items in the fewest bins, given that each bin has unit capacity. Online bin packing (dynamic case): Each item must be placed in a bin before the size of the next item is given. Offline bin packing (static case): You cannot make decision until all the input has been read.

6
CS223 Advanced Data Structures and Algorithms 6 An Example Pack: 0.2,0.5,0.4,0.7,0.1,0.3,0.8

7
CS223 Advanced Data Structures and Algorithms 7 The Next Fit Algorithm For each new item, check to see if it fits in the same bin as the last one. If it does, place it there. Otherwise, create a new bin. Time complexity: O(N).

8
CS223 Advanced Data Structures and Algorithms 8 The Next Fit Algorithm Pack: 0.2,0.5,0.4,0.7,0.1,0.3,0.8

9
CS223 Advanced Data Structures and Algorithms 9 The Next Fit Algorithm Theorem: Let M be the optimal solution. The next fit algorithm never uses more than 2M bins. There exist sequences such that it uses 2M-2 bins.

10
CS223 Advanced Data Structures and Algorithms 10 The First Fit Algorithm For each new item, scan the existing bins in order and place it in the first bin that can hold it. Create a new bin if none of them can hold it. Time complexity: O(N 2 )

11
CS223 Advanced Data Structures and Algorithms 11 The First Fit Algorithm Pack: 0.2,0.5,0.4,0.7,0.1,0.3,0.8

12
CS223 Advanced Data Structures and Algorithms 12 The First Fit Algorithm Theorem: Let M be the optimal solution. The first fit algorithm never uses more than 1.7M bins. There exist sequences such that it uses 1.7(M-1) bins.

13
CS223 Advanced Data Structures and Algorithms 13 The Best Fit Algorithm For each new item, scan the existing bins in order and place it in the tightest spot among all bins. Create a new bin if none of them can hold it. Time complexity: O(N 2 )

14
CS223 Advanced Data Structures and Algorithms 14 The Best Fit Algorithm Pack: 0.2,0.5,0.4,0.7,0.1,0.3,0.8

15
CS223 Advanced Data Structures and Algorithms 15 The Offline Algorithms The first/best fit decreasing algorithm: Sort the items in the descending order of their sizes, then use the first/best fit algorithm. Time complexity: O(N 2 )

16
CS223 Advanced Data Structures and Algorithms 16 The Offline Algorithms First fit for 0.8, 0.7, 0.5, 0.4, 0.3, 0.2, 0.1

17
CS223 Advanced Data Structures and Algorithms 17 The Offline Algorithms Theorem: Let M be the optimal solution. The first fit descending algorithm never uses more than 11/9M+4 bins. There exists sequences such that it uses 11/9M bins.

18
CS440 Computer Networks 18 The Path Scheduling Problem Given a path, and free timeslots of every nodes in the path, find a collision-free transmission schedule. J. Tang, G. Xue and C. Chandler, Interference-aware routing and bandwidth allocation for QoS provisioning in multihop wireless networks, Wireless Communications and Mobile Computing (WCMC), Vol. 5, No. 8, 2005, pp. 933-944.

19
CS440 Computer Networks 19 The First Fit Algorithm

20
CS440 Computer Networks 20 The Optimal Algorithm

Similar presentations

OK

CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.

CPSC 411, Fall 2008: Set 4 1 CPSC 411 Design and Analysis of Algorithms Set 4: Greedy Algorithms Prof. Jennifer Welch Fall 2008.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on dry cell and wet cell batteries Hypothalamus anatomy and physiology ppt on cells Download ppt on history and sport the story of cricket Ppt on history of pie in math Ppt on environmental sustainability Ppt on importance of sports and games Ppt on power sharing in democracy who makes Ppt on kingdom monera organisms A ppt on right to education Ppt on computer languages to learn