Professional Documents
Culture Documents
3
Greedy methods
4
Greedy methods
5
Greedy algorithm
6
Greedy Algorithm
Idea:
Always pick the shortest ride available at the time
Greedy-choice Property.
» A globally optimal solution can be arrived at by
making a locally optimal (greedy) choice.
7
Backtracking
8
Backtracking
Graph-coloring problem
8 queens problem
4 knight problem
9
Backtracking
The goal is to color vertices in a graph G={V,E} so that no 2 adjacent
vertices have the same color. Partial 3-coloring problem means only 3
colors are considered.
Direct approach builds the tree of ALL possibilities in exponential time.
10
Backtracking
Partial 3-coloring (3 colors) is solved by the following method:
Color first vertex with 1st color, color next vertex with the next color,
check if those two vertices are adjacent, if not - coloring is legal,
proceed to next vertex, if yes and color is the same – coloring is illegal,
try next color for second vertex. If all colors tried and all colorings are
illegal, backtrack, try next color for previous vertex etc.
Note: sometimes solution is impossible.
Exponential O(3^n) complexity is reduced to O(n) on average.
11
Job scheduling problem
12
Review questions
13
Thank You