Documente Academic
Documente Profesional
Documente Cultură
Attempt to find an optimal solution in each stage Make decision that appears to be best at that stage
Bin-Packing
INTRODUCTION:
Packing various items of certain sizes into a minimum number of bins with a fixed size Bin size is usually smaller than the sum of all objects
5 1 2 3 4 A B C
Application
Filling up containers Loading trucks with weight capacity Creating file backup in removable media Tapes and songs Breaks and commercials Bandwidth and packets Technology mapping in field-programmable gate array semiconductor chip design
Algorithm (Next-Fit)
FOR all objects i = 1, 2, . . . , n do WHILE ( Current Bin ! <= Available Bin ) IF Object i fits in current bin then Pack object i in current bin. ELSE Go to next bin make it the current bin, and pack object i END IF END WHILE END FOR
FOR i = 1 6
3 2 4 5 6 1
A
Execute ELSE STATEMENT! 3 FOR i = 3 6 2 4 5 6 A 1
2
4 5 6 A FOR i = 4 6 1
2 5 6 1
3 4
Analysis Of Algorithm
Packing an object can be done in constant time, the algorithm is dominated by the FOR LOOP, which has a running-time of (n) Every case Algorithm.
Solution ?
All bins are examined in each step Put each new item into a bin that comes
closest to filling it
Algorithm(Best-Fit)
FOR All objects i = 1, 2, . . . , n FOR All bins j = 1, 2, . . .n IF Object i fits in bin j then Calculate remaining capacity after the object has been added. END IF END FOR Pack object i in bin j, where j is the bin with minimum remaining capacity after adding the object (i.e. the object fits best) IF no such bin exists, open a new one and add the object. END FOR
3 2 4 5 6 A 1 B C
FOR i = 1 & j = 2
3 2 4 5 6 1
3 2 4 5 6 1
FOR i = 2 & j = 1
3 4 5 6 2 1
3 4 5 6 A 2 1 B C
FOR i = 2 & j = 3
3 4 5 6
2 1
3 4 5 6 A B
2 1 C
FOR i = 3 & j = 2
3 4 5 6
2 1
2 4 5 6 1
FOR i = 3
3 4 5 6
2 1
3 5 6
2 1
FOR i = 4 & j = 2
3 4 5 6
2 1
4 3 5 6 A B
2 1 C
FOR i = 4
3 4 5 6
2 1
3 4 6 A B
2 1 C
FOR i = 5 & j = 2
5 3 4 6 1 2
5 3 4 6 1 2
A
6
FOR i = 6 & j = 1
5 3 4 1 2
6
3 4
5
2 1
C 6
FOR i = 6 & j = 3
5 3 4 1 2
6 3
5 2
4
1 A
END FOR
Analysis Of Algorithm
Since all bins are examined in each step, the algorithm has an obvious running time of (n2)
This is an every Case time complex algorithm.
Graph Coloring
Color the vertices of graph using as few colors as possible Colors in some sense represent resources
So, graph coloring is to assign a limited number of resources (colors) to a set of vertices (nodes) under incompatibility constraints (adjacent vertices)
Applications
Timetabling Scheduling Frequency assignment Register allocation Air traffic management Train plat forming Sudoku Pattern matching
Algorithm ( First-Fit )
FOR all (vi E) do choose a legal color ci color vi V with ci END FOR
Dry Run
D Consider this input with Vertices = 5 & Input Sequence INP = { A, D, E, C, B }
C
E
C
E
Dry Run
D
FOR VD INP VD = BLUE A B C E
C
E
Dry Run
D
FOR VC INP VC = GREEN A B C E
C E
Drawback
Given graph could be colored using only 2 colors but greedy choice to the input sequence is not optimal as it uses 3 colors.
Analysis of Algorithm
Every case time complex algorithm, with running time (v)
Solution?
DSATUR algorithm
Color v with the maximal degree repeat color v having the maximal saturation degree if tie of saturation degrees then color v having the maximal uncolored neighbors if tie of uncolored neighbors then color v randomly end if end if until V is empty
Analysis Of Algorithm
DSATUR a sequential coloring algorithm with a dynamically established order of the vertices DSATUR starts by assigning color 1 to a vertex of maximal degree. The vertex to be colored next in the sequential coloring procedure of DSATUR is a vertex x with maximal degs(x) The complexity of DSATUR is O(|V |)
Thank you!