SlideShare a Scribd company logo
1 of 44
Unit 5
LIMITATION OF ALGORITHM
POWER
Dr.S.Gunasundari
Associate Professor
CSE Dept
Lower Bounds
Lower bound: an estimate on a minimum amount of work
needed to solve a given problem
Examples:
• number of comparisons needed to find the largest element
in a set of n numbers
• number of comparisons needed to sort an array of size n
• number of comparisons necessary for searching in a sorted
array
• number of multiplications needed to multiply two n-by-n
matrices
Lower Bounds (cont.)
• Lower bound can be
– an exact count
– an efficiency class ()
• Tight lower bound: there exists an algorithm
with the same efficiency as the lower bound
Problem Lower bound Tightness
sorting (nlog n) yes
searching in a sorted array (log n) yes
element uniqueness (nlog n) yes
n-digit integer multiplication (n) unknown
multiplication of n-by-n matrices (n2) unknown
Methods for Establishing Lower
Bounds
• trivial lower bounds
• information-theoretic arguments (decision
trees)
• adversary arguments
• problem reduction
Trivial Lower Bounds
Trivial lower bounds: based on counting the number
of items that must be processed in input and
generated as output
Examples
• finding max element
• polynomial evaluation
• sorting
• element uniqueness
• Hamiltonian circuit existence
Conclusions
• may and may not be useful
• be careful in deciding how many elements must be processed
Decision Trees
Decision tree — a convenient model of algorithms involving
comparisons in which:
• internal nodes represent comparisons
• leaves represent outcomes
Decision tree for 3-element insertion sort
a < b
b < c a < c
y es
y es no
no
y es
no
a < c b < c
a < b < c
c < a < b
b < a < c
b < c < a
no y es
abc
abc bac
bca
acb
y es
a < c < b c < b < a
no
Decision Trees and Sorting Algorithms
• Any comparison-based sorting algorithm can be
represented by a decision tree
• Number of leaves (outcomes)  n!
• Height of binary tree with n! leaves  log2n!
• Minimum number of comparisons in the worst case
 log2n! for any comparison-based sorting
algorithm
• log2n!  n log2n
• This lower bound is tight (mergesort)
Adversary Arguments
Adversary argument: a method of proving a lower bound by playing role of
adversary that makes algorithm work the hardest by adjusting input
Example 1: “Guessing” a number between 1 and n with yes/no
questions
Adversary: Puts the number in a larger of the two subsets generated by last
question
Example 2: Merging two sorted lists of size n
a1 < a2 < … < an and b1 < b2 < … < bn
Adversary: ai < bj iff i < j
Output b1 < a1 < b2 < a2 < … < bn < an requires 2n-1 comparisons
of adjacent elements
Lower Bounds by Problem Reduction
Idea: If problem P is at least as hard as problem Q, then
a lower bound for Q is also a lower bound for P.
Hence, find problem Q with a known lower bound
that can be reduced to problem P in question.
Example: P is finding MST for n points in Cartesian
plane Q is element uniqueness problem (known to
be in (nlogn))
Classifying Problem Complexity
Is the problem tractable, i.e., is there a polynomial-time (O(p(n))
algorithm that solves it?
Possible answers:
• yes (give examples)
• no
– because it’s been proved that no algorithm exists at all
(e.g., Turing’s halting problem)
– because it’s been be proved that any algorithm takes exponential
time
• unknown
Problem Types: Optimization and
Decision
• Optimization problem: find a solution that maximizes or minimizes
some objective function
• Decision problem: answer yes/no to a question
Many problems have decision and optimization versions.
E.g.: traveling salesman problem
• optimization: find Hamiltonian cycle of minimum length
• decision: find Hamiltonian cycle of length  m
Decision problems are more convenient for formal investigation of
their complexity.
Class P
P: the class of decision problems that are solvable in O(p(n)) time,
where p(n) is a polynomial of problem’s input size n
Examples:
• searching
• element uniqueness
• graph connectivity
• graph acyclicity
• primality testing (finally proved in 2002)
Class NP
NP (nondeterministic polynomial): class of decision problems whose
proposed solutions can be verified in polynomial time = solvable
by a nondeterministic polynomial algorithm
A nondeterministic polynomial algorithm is an abstract two-stage
procedure that:
• generates a random string purported to solve the problem
• checks whether this solution is correct in polynomial time
By definition, it solves the problem if it’s capable of generating and
verifying a solution on one of its tries
Why this definition?
• led to development of the rich theory called “computational
complexity”
Example: CNF satisfiability
Problem: Is a boolean expression in its conjunctive
normal form (CNF) satisfiable, i.e., are there
values of its variables that makes it true?
This problem is in NP. Nondeterministic algorithm:
• Guess truth assignment
• Substitute the values into the CNF formula to
see if it evaluates to true
Example: (A | ¬B | ¬C) & (A | B) & (¬B | ¬D | E) & (¬D | ¬E)
Truth assignments:
A B C D E
0 0 0 0 0
. . .
1 1 1 1 1
Checking phase: O(n)
What problems are in NP?
• Hamiltonian circuit existence
• Partition problem: Is it possible to partition a set of n
integers into two disjoint subsets with the same sum?
• Decision versions of TSP, knapsack problem, graph
coloring, and many other combinatorial optimization
problems. (Few exceptions include: MST, shortest
paths)
• All the problems in P can also be solved in this manner
(but no guessing is necessary), so we have:
P  NP
• Big question: P = NP ?
NP-Complete Problems
A decision problem D is NP-complete if it’s as hard as any
problem in NP, i.e.,
• D is in NP
• every problem in NP is polynomial-time reducible to D
Cook’s theorem (1971): CNF-sat is NP-complete
NP-complete
problem
NP problems
NP-Complete Problems (cont.)
Other NP-complete problems obtained through polynomial-
time reductions from a known NP-complete problem
Examples: TSP, knapsack, partition, graph-coloring and
hundreds of other problems of combinatorial
nature
known
NP-complete
problem
NP problems
candidate
f or NP -
completeness
P = NP ? Dilemma Revisited
• P = NP would imply that every problem in NP, including all NP-
complete problems, could be solved in polynomial time
• If a polynomial-time algorithm for just one NP-complete problem
is discovered, then every problem in NP can be solved in
polynomial time, i.e., P = NP
• Most but not all researchers believe that P  NP , i.e. P is a proper
subset of NP
NP-complete
problem
NP problems
Tackling Difficult Combinatorial Problems
There are two principal approaches to tackling
difficult combinatorial problems (NP-hard
problems):
• Use a strategy that guarantees solving the
problem exactly but doesn’t guarantee to find a
solution in polynomial time
• Use an approximation algorithm that can find an
approximate (sub-optimal) solution in polynomial
time
Exact Solution Strategies
• exhaustive search (brute force)
– useful only for small instances
• dynamic programming
– applicable to some problems (e.g., the knapsack problem)
• backtracking
– eliminates some unnecessary cases from consideration
– yields solutions in reasonable time for many instances but
worst case is still exponential
• branch-and-bound
– further refines the backtracking idea for optimization
problems
Backtracking
• Construct the state-space tree
– nodes: partial solutions
– edges: choices in extending partial solutions
• Explore the state space tree using depth-first
search
• “Prune” nonpromising nodes
– dfs stops exploring subtrees rooted at nodes that cannot lead to
a solution and backtracks to such a node’s parent to continue
the search
Example: n-Queens Problem
Place n queens on an n-by-n chess board so that
no two of them are in the same row, column, or
diagonal
State-Space Tree of the 4-Queens
Problem
Example: Hamiltonian Circuit Problem
d
a b
e
c f
0
0
0
5
11 5
3
3
8
3
with 3
with 5
with 6
w/o 3
w/o 5
w/o 6 with 6 w/o 6
w/o 5 with 5
X X X X
X
14+7>15 3+7<15 11+7>14 5+7<15
0+13<15
with 6
X
9+7>15
14 9
8
8
w/o 7
w/o 6
X
8<15
solution
with 7
15
Branch-and-Bound
• An enhancement of backtracking
• Applicable to optimization problems
• For each node (partial solution) of a state-space
tree, computes a bound on the value of the
objective function for all descendants of the node
(extensions of the partial solution)
• Uses the bound for:
– ruling out certain nodes as “nonpromising” to prune the tree – if
a node’s bound is not better than the best solution seen so far
– guiding the search through state-space
Select one element in each row of the cost matrix C so that:
• no two selected elements are in the same column
• the sum is minimized
Example
Job 1 Job 2 Job 3 Job 4
Person a 9 2 7 8
Person b 6 4 3 7
Person c 5 8 1 8
Person d 7 6 9 4
Lower bound: Any solution to this problem will have total cost
at least: 2 + 3 + 1 + 4 (or 5 + 2 + 1 + 4)
Example: Assignment Problem
Example: First two levels of the state-space tree
Example (cont.)
Example: Complete state-space tree
Example: Traveling Salesman Problem
Approximation Approach
Apply a fast (i.e., a polynomial-time) approximation
algorithm to get a solution that is not necessarily
optimal but hopefully close to it
Accuracy measures:
accuracy ratio of an approximate solution sa
r(sa) = f(sa) / f(s*) for minimization problems
r(sa) = f(s*) / f(sa) for maximization problems
where f(sa) and f(s*) are values of the objective
function f for the approximate solution sa and actual
optimal solution s*
performance ratio of the algorithm A
the lowest upper bound of r(sa) on all
instances
Nearest-Neighbor Algorithm for TSP
Starting at some city, always go to the nearest unvisited city,
and, after visiting all the cities, return to the starting one
A B
D C
Note: Nearest-neighbor tour may depend on the starting city
Accuracy: RA = ∞ (unbounded above) – make the length of AD
arbitrarily large in the above example
1
6 2
3 3
1
sa : A – B – C – D – A of length 10
s* : A – B – D – C – A of length 8
Multifragment-Heuristic Algorithm
Stage 1: Sort the edges in nondecreasing order of weights.
Initialize the set of tour edges to be constructed to
empty set
Stage 2: Add next edge on the sorted list to the tour,
skipping
those whose addition would’ve created a vertex of
degree 3 or a cycle of length less than n. Repeat
this step until a tour of length n is obtained
Note: RA = ∞, but this algorithm tends to produce better
tours
than the nearest-neighbor algorithm
Twice-Around-the-Tree Algorithm
Stage 1: Construct a minimum spanning tree of the graph
(e.g., by Prim’s or Kruskal’s algorithm)
Stage 2: Starting at an arbitrary vertex, create a path that goes
twice around the tree and returns to the same vertex
Stage 3: Create a tour from the circuit constructed in Stage 2 by
making shortcuts to avoid visiting intermediate vertices
more than once
Note: RA = ∞ for general instances, but this algorithm tends to
produce better tours than the nearest-neighbor algorithm
Example
a
d
b
e
4
12
7
8
9 9
c
6 10
8 11
a
d
b
e
c
Walk: a – b – c – b – d – e – d – b – a Tour: a – b – c – d – e – a
Christofides Algorithm
Stage 1: Construct a minimum spanning tree of the graph
Stage 2: Add edges of a minimum-weight matching of all the odd
vertices in the minimum spanning tree
Stage 3: Find an Eulerian circuit of the multigraph obtained in
Stage 2
Stage 3: Create a tour from the path constructed in Stage 2 by
making shortcuts to avoid visiting intermediate vertices
more than once
RA = ∞ for general instances, but it tends to produce better
tours than the twice-around-the-minimum-tree alg.
Example: Christofides Algorithm
a
d
b
e
4
12
7
8
9 9
c
6 10
8 11
a
d
b
e
4 7
8
c
6
11
4
a
d
b
e
7
c
6
11
4 9
Euclidean Instances
Theorem If P ≠ NP, there exists no approximation algorithm
for TSP with a finite performance ratio.
Definition An instance of TSP is called Euclidean, if its
distances satisfy two conditions:
1. symmetry d[i, j] = d[j, i] for any pair of cities i and j
2. triangle inequality d[i, j] ≤ d[i, k] + d[k, j] for any cities i, j, k
For Euclidean instances:
approx. tour length / optimal tour length ≤ 0.5(⌈log2 n⌉ + 1)
for nearest neighbor and multifragment heuristic;
approx. tour length / optimal tour length ≤ 2
for twice-around-the-tree;
approx. tour length / optimal tour length ≤ 1.5
for Christofides
Local Search Heuristics for TSP
Start with some initial tour (e.g., nearest neighbor). On each
iteration, explore the current tour’s neighborhood by exchanging a
few edges in it. If the new tour is shorter, make it the current tour;
otherwise consider another edge change. If no change yields a
shorter tour, the current tour is returned as the output.
Example of a 2-change
C1 C2
C4 C3
C1 C2
C4 C3
Example of a 3-change
C1 C2
C5 C4
C3
C6
C1 C2
C5 C4
C3
C6
C1 C2
C5 C4
C3
C6
Empirical Data for Euclidean Instances
Greedy Algorithm for Knapsack Problem
Step 1: Order the items in decreasing order of relative values:
v1/w1…  vn/wn
Step 2: Select the items in this order skipping those that don’t
fit into the knapsack
Example: The knapsack’s capacity is 16
item weight value v/w
1 2 $40 20
2 5 $30 6
3 10 $50 5
4 5 $10 2
Accuracy
• RA is unbounded (e.g., n = 2, C = m, w1=1, v1=2, w2=m, v2=m)
• yields exact solutions for the continuous version
Approximation Scheme for Knapsack Problem
Step 1: Order the items in decreasing order of relative values:
v1/w1…  vn/wn
Step 2: For a given integer parameter k, 0 ≤ k ≤ n, generate all
subsets of k items or less and for each of those that fit
the
knapsack, add the remaining items in decreasing
order of their value to weight ratios
Step 3: Find the most valuable subset among the subsets
generated in Step 2 and return it as the algorithm’s
output
• Accuracy: f(s*) / f(sa) ≤ 1 + 1/k for any instance of size n
• Time efficiency: O(knk+1)
• There are fully polynomial schemes: algorithms with
polynomial running time as functions of both n and k
Bin Packing Problem: First-Fit Algorithm
First-Fit (FF) Algorithm: Consider the items in the order given and
place each item in the first available bin with enough room for it; if
there are no such bins, start a new one
Example: n = 4, s1 = 0.4, s2 = 0.2, s3 = 0.6, s4 = 0.7
Accuracy
• Number of extra bins never exceeds optimal by more than
70% (i.e., RA ≤ 1.7)
• Empirical average-case behavior is much better. (In one
experiment with 128,000 bins, the relative error was found
to be no more than 2%.)

More Related Content

What's hot

Algorithm chapter 1
Algorithm chapter 1Algorithm chapter 1
Algorithm chapter 1chidabdu
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquerKrish_ver2
 
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWERUndecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWERmuthukrishnavinayaga
 
Algorithm chapter 2
Algorithm chapter 2Algorithm chapter 2
Algorithm chapter 2chidabdu
 
Dynamic programming - fundamentals review
Dynamic programming - fundamentals reviewDynamic programming - fundamentals review
Dynamic programming - fundamentals reviewElifTech
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programminghodcsencet
 
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsDivide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsAmrinder Arora
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part IIAmrinder Arora
 
01. design & analysis of agorithm intro & complexity analysis
01. design & analysis of agorithm intro & complexity analysis01. design & analysis of agorithm intro & complexity analysis
01. design & analysis of agorithm intro & complexity analysisOnkar Nath Sharma
 
Backtracking & branch and bound
Backtracking & branch and boundBacktracking & branch and bound
Backtracking & branch and boundVipul Chauhan
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of AlgorithmsArvind Krishnaa
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAmrinder Arora
 
Algorithm Design and Complexity - Course 3
Algorithm Design and Complexity - Course 3Algorithm Design and Complexity - Course 3
Algorithm Design and Complexity - Course 3Traian Rebedea
 

What's hot (18)

Algorithm chapter 1
Algorithm chapter 1Algorithm chapter 1
Algorithm chapter 1
 
Greedy Algorithms
Greedy AlgorithmsGreedy Algorithms
Greedy Algorithms
 
5.2 divide and conquer
5.2 divide and conquer5.2 divide and conquer
5.2 divide and conquer
 
algorithm Unit 3
algorithm Unit 3algorithm Unit 3
algorithm Unit 3
 
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWERUndecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
 
Algorithm chapter 2
Algorithm chapter 2Algorithm chapter 2
Algorithm chapter 2
 
Divide and Conquer
Divide and ConquerDivide and Conquer
Divide and Conquer
 
Dynamic programming - fundamentals review
Dynamic programming - fundamentals reviewDynamic programming - fundamentals review
Dynamic programming - fundamentals review
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programming
 
algorithm Unit 2
algorithm Unit 2 algorithm Unit 2
algorithm Unit 2
 
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of PointsDivide and Conquer - Part II - Quickselect and Closest Pair of Points
Divide and Conquer - Part II - Quickselect and Closest Pair of Points
 
Dynamic Programming - Part II
Dynamic Programming - Part IIDynamic Programming - Part II
Dynamic Programming - Part II
 
Analysis of Algorithm
Analysis of AlgorithmAnalysis of Algorithm
Analysis of Algorithm
 
01. design & analysis of agorithm intro & complexity analysis
01. design & analysis of agorithm intro & complexity analysis01. design & analysis of agorithm intro & complexity analysis
01. design & analysis of agorithm intro & complexity analysis
 
Backtracking & branch and bound
Backtracking & branch and boundBacktracking & branch and bound
Backtracking & branch and bound
 
Design and Analysis of Algorithms
Design and Analysis of AlgorithmsDesign and Analysis of Algorithms
Design and Analysis of Algorithms
 
Asymptotic Notation and Data Structures
Asymptotic Notation and Data StructuresAsymptotic Notation and Data Structures
Asymptotic Notation and Data Structures
 
Algorithm Design and Complexity - Course 3
Algorithm Design and Complexity - Course 3Algorithm Design and Complexity - Course 3
Algorithm Design and Complexity - Course 3
 

Similar to Unit 5

Undecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation AlgorithmsUndecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation AlgorithmsMuthu Vinayagam
 
bcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptx
bcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptxbcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptx
bcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptxB.T.L.I.T
 
Dynamic programming class 16
Dynamic programming class 16Dynamic programming class 16
Dynamic programming class 16Kumar
 
Sienna 13 limitations
Sienna 13 limitationsSienna 13 limitations
Sienna 13 limitationschidabdu
 
Algorithm review
Algorithm reviewAlgorithm review
Algorithm reviewchidabdu
 
Module 2 Design Analysis and Algorithms
Module 2 Design Analysis and AlgorithmsModule 2 Design Analysis and Algorithms
Module 2 Design Analysis and AlgorithmsCool Guy
 
Analysis and design of algorithms part 4
Analysis and design of algorithms part 4Analysis and design of algorithms part 4
Analysis and design of algorithms part 4Deepak John
 
Combinatorial optimization CO-1
Combinatorial optimization CO-1Combinatorial optimization CO-1
Combinatorial optimization CO-1man003
 
teteuueieoeofhfhfjffkkkfkfflflflhshssnnvmvvmvv,v,v,nnxmxxm
teteuueieoeofhfhfjffkkkfkfflflflhshssnnvmvvmvv,v,v,nnxmxxmteteuueieoeofhfhfjffkkkfkfflflflhshssnnvmvvmvv,v,v,nnxmxxm
teteuueieoeofhfhfjffkkkfkfflflflhshssnnvmvvmvv,v,v,nnxmxxmzoobiarana76
 
dynamic programming Rod cutting class
dynamic programming Rod cutting classdynamic programming Rod cutting class
dynamic programming Rod cutting classgiridaroori
 
Lecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrencesLecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrencesjayavignesh86
 

Similar to Unit 5 (20)

Unit7
Unit7Unit7
Unit7
 
Undecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation AlgorithmsUndecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation Algorithms
 
bcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptx
bcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptxbcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptx
bcfbedbf-6679-4d5d-b8a5-7d4c9c48dba4.pptx
 
Dynamic programming class 16
Dynamic programming class 16Dynamic programming class 16
Dynamic programming class 16
 
Sienna 13 limitations
Sienna 13 limitationsSienna 13 limitations
Sienna 13 limitations
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
AA ppt9107
AA ppt9107AA ppt9107
AA ppt9107
 
Chap12 slides
Chap12 slidesChap12 slides
Chap12 slides
 
Algorithm review
Algorithm reviewAlgorithm review
Algorithm review
 
Daa chapter6
Daa chapter6Daa chapter6
Daa chapter6
 
DAA.pdf
DAA.pdfDAA.pdf
DAA.pdf
 
DAA.pdf
DAA.pdfDAA.pdf
DAA.pdf
 
Module 2 Design Analysis and Algorithms
Module 2 Design Analysis and AlgorithmsModule 2 Design Analysis and Algorithms
Module 2 Design Analysis and Algorithms
 
lect5-1.ppt
lect5-1.pptlect5-1.ppt
lect5-1.ppt
 
Analysis and design of algorithms part 4
Analysis and design of algorithms part 4Analysis and design of algorithms part 4
Analysis and design of algorithms part 4
 
Combinatorial optimization CO-1
Combinatorial optimization CO-1Combinatorial optimization CO-1
Combinatorial optimization CO-1
 
teteuueieoeofhfhfjffkkkfkfflflflhshssnnvmvvmvv,v,v,nnxmxxm
teteuueieoeofhfhfjffkkkfkfflflflhshssnnvmvvmvv,v,v,nnxmxxmteteuueieoeofhfhfjffkkkfkfflflflhshssnnvmvvmvv,v,v,nnxmxxm
teteuueieoeofhfhfjffkkkfkfflflflhshssnnvmvvmvv,v,v,nnxmxxm
 
Complexity theory
Complexity theory Complexity theory
Complexity theory
 
dynamic programming Rod cutting class
dynamic programming Rod cutting classdynamic programming Rod cutting class
dynamic programming Rod cutting class
 
Lecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrencesLecture 5 6_7 - divide and conquer and method of solving recurrences
Lecture 5 6_7 - divide and conquer and method of solving recurrences
 

Recently uploaded

ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 

Recently uploaded (20)

ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 

Unit 5

  • 1. Unit 5 LIMITATION OF ALGORITHM POWER Dr.S.Gunasundari Associate Professor CSE Dept
  • 2. Lower Bounds Lower bound: an estimate on a minimum amount of work needed to solve a given problem Examples: • number of comparisons needed to find the largest element in a set of n numbers • number of comparisons needed to sort an array of size n • number of comparisons necessary for searching in a sorted array • number of multiplications needed to multiply two n-by-n matrices
  • 3. Lower Bounds (cont.) • Lower bound can be – an exact count – an efficiency class () • Tight lower bound: there exists an algorithm with the same efficiency as the lower bound Problem Lower bound Tightness sorting (nlog n) yes searching in a sorted array (log n) yes element uniqueness (nlog n) yes n-digit integer multiplication (n) unknown multiplication of n-by-n matrices (n2) unknown
  • 4. Methods for Establishing Lower Bounds • trivial lower bounds • information-theoretic arguments (decision trees) • adversary arguments • problem reduction
  • 5. Trivial Lower Bounds Trivial lower bounds: based on counting the number of items that must be processed in input and generated as output Examples • finding max element • polynomial evaluation • sorting • element uniqueness • Hamiltonian circuit existence Conclusions • may and may not be useful • be careful in deciding how many elements must be processed
  • 6. Decision Trees Decision tree — a convenient model of algorithms involving comparisons in which: • internal nodes represent comparisons • leaves represent outcomes Decision tree for 3-element insertion sort a < b b < c a < c y es y es no no y es no a < c b < c a < b < c c < a < b b < a < c b < c < a no y es abc abc bac bca acb y es a < c < b c < b < a no
  • 7. Decision Trees and Sorting Algorithms • Any comparison-based sorting algorithm can be represented by a decision tree • Number of leaves (outcomes)  n! • Height of binary tree with n! leaves  log2n! • Minimum number of comparisons in the worst case  log2n! for any comparison-based sorting algorithm • log2n!  n log2n • This lower bound is tight (mergesort)
  • 8. Adversary Arguments Adversary argument: a method of proving a lower bound by playing role of adversary that makes algorithm work the hardest by adjusting input Example 1: “Guessing” a number between 1 and n with yes/no questions Adversary: Puts the number in a larger of the two subsets generated by last question Example 2: Merging two sorted lists of size n a1 < a2 < … < an and b1 < b2 < … < bn Adversary: ai < bj iff i < j Output b1 < a1 < b2 < a2 < … < bn < an requires 2n-1 comparisons of adjacent elements
  • 9. Lower Bounds by Problem Reduction Idea: If problem P is at least as hard as problem Q, then a lower bound for Q is also a lower bound for P. Hence, find problem Q with a known lower bound that can be reduced to problem P in question. Example: P is finding MST for n points in Cartesian plane Q is element uniqueness problem (known to be in (nlogn))
  • 10. Classifying Problem Complexity Is the problem tractable, i.e., is there a polynomial-time (O(p(n)) algorithm that solves it? Possible answers: • yes (give examples) • no – because it’s been proved that no algorithm exists at all (e.g., Turing’s halting problem) – because it’s been be proved that any algorithm takes exponential time • unknown
  • 11. Problem Types: Optimization and Decision • Optimization problem: find a solution that maximizes or minimizes some objective function • Decision problem: answer yes/no to a question Many problems have decision and optimization versions. E.g.: traveling salesman problem • optimization: find Hamiltonian cycle of minimum length • decision: find Hamiltonian cycle of length  m Decision problems are more convenient for formal investigation of their complexity.
  • 12. Class P P: the class of decision problems that are solvable in O(p(n)) time, where p(n) is a polynomial of problem’s input size n Examples: • searching • element uniqueness • graph connectivity • graph acyclicity • primality testing (finally proved in 2002)
  • 13. Class NP NP (nondeterministic polynomial): class of decision problems whose proposed solutions can be verified in polynomial time = solvable by a nondeterministic polynomial algorithm A nondeterministic polynomial algorithm is an abstract two-stage procedure that: • generates a random string purported to solve the problem • checks whether this solution is correct in polynomial time By definition, it solves the problem if it’s capable of generating and verifying a solution on one of its tries Why this definition? • led to development of the rich theory called “computational complexity”
  • 14. Example: CNF satisfiability Problem: Is a boolean expression in its conjunctive normal form (CNF) satisfiable, i.e., are there values of its variables that makes it true? This problem is in NP. Nondeterministic algorithm: • Guess truth assignment • Substitute the values into the CNF formula to see if it evaluates to true Example: (A | ¬B | ¬C) & (A | B) & (¬B | ¬D | E) & (¬D | ¬E) Truth assignments: A B C D E 0 0 0 0 0 . . . 1 1 1 1 1 Checking phase: O(n)
  • 15. What problems are in NP? • Hamiltonian circuit existence • Partition problem: Is it possible to partition a set of n integers into two disjoint subsets with the same sum? • Decision versions of TSP, knapsack problem, graph coloring, and many other combinatorial optimization problems. (Few exceptions include: MST, shortest paths) • All the problems in P can also be solved in this manner (but no guessing is necessary), so we have: P  NP • Big question: P = NP ?
  • 16. NP-Complete Problems A decision problem D is NP-complete if it’s as hard as any problem in NP, i.e., • D is in NP • every problem in NP is polynomial-time reducible to D Cook’s theorem (1971): CNF-sat is NP-complete NP-complete problem NP problems
  • 17. NP-Complete Problems (cont.) Other NP-complete problems obtained through polynomial- time reductions from a known NP-complete problem Examples: TSP, knapsack, partition, graph-coloring and hundreds of other problems of combinatorial nature known NP-complete problem NP problems candidate f or NP - completeness
  • 18. P = NP ? Dilemma Revisited • P = NP would imply that every problem in NP, including all NP- complete problems, could be solved in polynomial time • If a polynomial-time algorithm for just one NP-complete problem is discovered, then every problem in NP can be solved in polynomial time, i.e., P = NP • Most but not all researchers believe that P  NP , i.e. P is a proper subset of NP NP-complete problem NP problems
  • 19. Tackling Difficult Combinatorial Problems There are two principal approaches to tackling difficult combinatorial problems (NP-hard problems): • Use a strategy that guarantees solving the problem exactly but doesn’t guarantee to find a solution in polynomial time • Use an approximation algorithm that can find an approximate (sub-optimal) solution in polynomial time
  • 20. Exact Solution Strategies • exhaustive search (brute force) – useful only for small instances • dynamic programming – applicable to some problems (e.g., the knapsack problem) • backtracking – eliminates some unnecessary cases from consideration – yields solutions in reasonable time for many instances but worst case is still exponential • branch-and-bound – further refines the backtracking idea for optimization problems
  • 21. Backtracking • Construct the state-space tree – nodes: partial solutions – edges: choices in extending partial solutions • Explore the state space tree using depth-first search • “Prune” nonpromising nodes – dfs stops exploring subtrees rooted at nodes that cannot lead to a solution and backtracks to such a node’s parent to continue the search
  • 22. Example: n-Queens Problem Place n queens on an n-by-n chess board so that no two of them are in the same row, column, or diagonal
  • 23. State-Space Tree of the 4-Queens Problem
  • 24. Example: Hamiltonian Circuit Problem d a b e c f 0 0 0 5 11 5 3 3 8 3 with 3 with 5 with 6 w/o 3 w/o 5 w/o 6 with 6 w/o 6 w/o 5 with 5 X X X X X 14+7>15 3+7<15 11+7>14 5+7<15 0+13<15 with 6 X 9+7>15 14 9 8 8 w/o 7 w/o 6 X 8<15 solution with 7 15
  • 25. Branch-and-Bound • An enhancement of backtracking • Applicable to optimization problems • For each node (partial solution) of a state-space tree, computes a bound on the value of the objective function for all descendants of the node (extensions of the partial solution) • Uses the bound for: – ruling out certain nodes as “nonpromising” to prune the tree – if a node’s bound is not better than the best solution seen so far – guiding the search through state-space
  • 26. Select one element in each row of the cost matrix C so that: • no two selected elements are in the same column • the sum is minimized Example Job 1 Job 2 Job 3 Job 4 Person a 9 2 7 8 Person b 6 4 3 7 Person c 5 8 1 8 Person d 7 6 9 4 Lower bound: Any solution to this problem will have total cost at least: 2 + 3 + 1 + 4 (or 5 + 2 + 1 + 4) Example: Assignment Problem
  • 27. Example: First two levels of the state-space tree
  • 31. Approximation Approach Apply a fast (i.e., a polynomial-time) approximation algorithm to get a solution that is not necessarily optimal but hopefully close to it Accuracy measures: accuracy ratio of an approximate solution sa r(sa) = f(sa) / f(s*) for minimization problems r(sa) = f(s*) / f(sa) for maximization problems where f(sa) and f(s*) are values of the objective function f for the approximate solution sa and actual optimal solution s* performance ratio of the algorithm A the lowest upper bound of r(sa) on all instances
  • 32. Nearest-Neighbor Algorithm for TSP Starting at some city, always go to the nearest unvisited city, and, after visiting all the cities, return to the starting one A B D C Note: Nearest-neighbor tour may depend on the starting city Accuracy: RA = ∞ (unbounded above) – make the length of AD arbitrarily large in the above example 1 6 2 3 3 1 sa : A – B – C – D – A of length 10 s* : A – B – D – C – A of length 8
  • 33. Multifragment-Heuristic Algorithm Stage 1: Sort the edges in nondecreasing order of weights. Initialize the set of tour edges to be constructed to empty set Stage 2: Add next edge on the sorted list to the tour, skipping those whose addition would’ve created a vertex of degree 3 or a cycle of length less than n. Repeat this step until a tour of length n is obtained Note: RA = ∞, but this algorithm tends to produce better tours than the nearest-neighbor algorithm
  • 34. Twice-Around-the-Tree Algorithm Stage 1: Construct a minimum spanning tree of the graph (e.g., by Prim’s or Kruskal’s algorithm) Stage 2: Starting at an arbitrary vertex, create a path that goes twice around the tree and returns to the same vertex Stage 3: Create a tour from the circuit constructed in Stage 2 by making shortcuts to avoid visiting intermediate vertices more than once Note: RA = ∞ for general instances, but this algorithm tends to produce better tours than the nearest-neighbor algorithm
  • 35. Example a d b e 4 12 7 8 9 9 c 6 10 8 11 a d b e c Walk: a – b – c – b – d – e – d – b – a Tour: a – b – c – d – e – a
  • 36. Christofides Algorithm Stage 1: Construct a minimum spanning tree of the graph Stage 2: Add edges of a minimum-weight matching of all the odd vertices in the minimum spanning tree Stage 3: Find an Eulerian circuit of the multigraph obtained in Stage 2 Stage 3: Create a tour from the path constructed in Stage 2 by making shortcuts to avoid visiting intermediate vertices more than once RA = ∞ for general instances, but it tends to produce better tours than the twice-around-the-minimum-tree alg.
  • 37. Example: Christofides Algorithm a d b e 4 12 7 8 9 9 c 6 10 8 11 a d b e 4 7 8 c 6 11 4 a d b e 7 c 6 11 4 9
  • 38. Euclidean Instances Theorem If P ≠ NP, there exists no approximation algorithm for TSP with a finite performance ratio. Definition An instance of TSP is called Euclidean, if its distances satisfy two conditions: 1. symmetry d[i, j] = d[j, i] for any pair of cities i and j 2. triangle inequality d[i, j] ≤ d[i, k] + d[k, j] for any cities i, j, k For Euclidean instances: approx. tour length / optimal tour length ≤ 0.5(⌈log2 n⌉ + 1) for nearest neighbor and multifragment heuristic; approx. tour length / optimal tour length ≤ 2 for twice-around-the-tree; approx. tour length / optimal tour length ≤ 1.5 for Christofides
  • 39. Local Search Heuristics for TSP Start with some initial tour (e.g., nearest neighbor). On each iteration, explore the current tour’s neighborhood by exchanging a few edges in it. If the new tour is shorter, make it the current tour; otherwise consider another edge change. If no change yields a shorter tour, the current tour is returned as the output. Example of a 2-change C1 C2 C4 C3 C1 C2 C4 C3
  • 40. Example of a 3-change C1 C2 C5 C4 C3 C6 C1 C2 C5 C4 C3 C6 C1 C2 C5 C4 C3 C6
  • 41. Empirical Data for Euclidean Instances
  • 42. Greedy Algorithm for Knapsack Problem Step 1: Order the items in decreasing order of relative values: v1/w1…  vn/wn Step 2: Select the items in this order skipping those that don’t fit into the knapsack Example: The knapsack’s capacity is 16 item weight value v/w 1 2 $40 20 2 5 $30 6 3 10 $50 5 4 5 $10 2 Accuracy • RA is unbounded (e.g., n = 2, C = m, w1=1, v1=2, w2=m, v2=m) • yields exact solutions for the continuous version
  • 43. Approximation Scheme for Knapsack Problem Step 1: Order the items in decreasing order of relative values: v1/w1…  vn/wn Step 2: For a given integer parameter k, 0 ≤ k ≤ n, generate all subsets of k items or less and for each of those that fit the knapsack, add the remaining items in decreasing order of their value to weight ratios Step 3: Find the most valuable subset among the subsets generated in Step 2 and return it as the algorithm’s output • Accuracy: f(s*) / f(sa) ≤ 1 + 1/k for any instance of size n • Time efficiency: O(knk+1) • There are fully polynomial schemes: algorithms with polynomial running time as functions of both n and k
  • 44. Bin Packing Problem: First-Fit Algorithm First-Fit (FF) Algorithm: Consider the items in the order given and place each item in the first available bin with enough room for it; if there are no such bins, start a new one Example: n = 4, s1 = 0.4, s2 = 0.2, s3 = 0.6, s4 = 0.7 Accuracy • Number of extra bins never exceeds optimal by more than 70% (i.e., RA ≤ 1.7) • Empirical average-case behavior is much better. (In one experiment with 128,000 bins, the relative error was found to be no more than 2%.)