46
CSE202: Algorithm Design and Analysis Ragesh Jaiswal, CSE, UCSD Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

CSE202: Algorithm Design and Analysiscseweb.ucsd.edu/~rajaiswal/cse202/Notes/Week-10/lec-1.pdf · 2015. 11. 24. · An algorithm is said to be e cient if it runs in time polynomial

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

  • CSE202: Algorithm Design and Analysis

    Ragesh Jaiswal, CSE, UCSD

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Network Flow: Applications of Network Flow

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Network FlowImage Segmentation

    You are given an image as a 2-D matrix of pixels.We want to determine the foreground and the backgroundpixels.Each pixel i , has an integer a(i) associated with it denotinghow likely it is to be a foreground pixel.Similarly, each pixel i , has an integer b(i) associated with itdenoting how likely it is to be a foreground pixel.For neighboring pixels, i and j , there is an associated penaltyp(i , j) with putting i and j in different sets.

    Problem

    Find a partition of the pixels into F and B such that:∑i∈F

    a(i) +∑i∈B

    b(i)−∑

    i and j are neighbors but in different sets

    p(i , j)

    is maximized.Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Network FlowImage Segmentation

    Problem

    Find a partition of the pixels into F and B such that:∑i∈F

    a(i) +∑i∈B

    b(i)−∑

    i and j are neighbors but in different sets

    p(i , j)

    is maximized.

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Network FlowImage Segmentation

    Problem

    Find a partition of the pixels into F and B such that:∑i∈F

    a(i) +∑i∈B

    b(i)−∑

    i and j are neighbors but in different sets

    p(i , j)

    is maximized.

    Consider the network below:

    Figure: Idea: The s-t min-cut in the above network gives the optimalpartition.

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Network FlowImage Segmentation

    Let C =∑

    i a(i) +∑

    i b(i).Claim 1: Consider a partition (F ,B) of the set of pixels. Let S = F ∪ {s},T = B ∪{t}. Then the capacity of the s-t cut (S ,T ) in the network is given by

    C (S ,T ) = C−

    ∑i∈F

    a(i) +∑i∈B

    b(j)−∑

    i and j are neighbors but in different sets

    p(i , j)

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Network FlowImage Segmentation

    Let C =∑

    i a(i) +∑

    i b(i).Claim 1: Consider a partition (F ,B) of the set of pixels. Let S = F ∪ {s},T = B ∪{t}. Then the capacity of the s-t cut (S ,T ) in the network is given by

    C (S ,T ) = C−

    ∑i∈F

    a(i) +∑i∈B

    b(j)−∑

    i and j are neighbors but in different sets

    p(i , j)

    Claim 2: Consider an s-t cut (S ,T ) in the network. Let F = A \ {s},B = T \ {t}. Then

    C (S ,T ) = C−

    ∑i∈F

    a(i) +∑i∈B

    b(j)−∑

    i and j are neighbors but in different sets

    p(i , j)

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Network FlowImage Segmentation

    Let C =∑

    i a(i) +∑

    i b(i).Claim 1: Consider a partition (F ,B) of the set of pixels. Let S = F ∪ {s},T = B ∪{t}. Then the capacity of the s-t cut (S ,T ) in the network is given by

    C (S ,T ) = C−

    ∑i∈F

    a(i) +∑i∈B

    b(j)−∑

    i and j are neighbors but in different sets

    p(i , j)

    Claim 2: Consider an s-t cut (S ,T ) in the network. Let F = A \ {s},B = T \ {t}. Then

    C (S ,T ) = C−

    ∑i∈F

    a(i) +∑i∈B

    b(j)−∑

    i and j are neighbors but in different sets

    p(i , j)

    Form Claims 1 and 2, we get that if (S ,T ) is a s-t min-cut in the network,then F = S \ {s},B = T \ {t} is an optimal solution to the ImageSegmentation problem

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Network FlowEdge-disjoint paths

    Definition (Edge-disjoint path)

    Two paths P1 and P2 between from vertex s to vertex t are callededge-disjoint if P1 and P2 do not share any edges.

    Problem

    Given an unweighted directed graph G , find the maximum number ofedge-disjoint paths between s and t in G .

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Network FlowEdge-disjoint paths

    Problem

    Given an unweighted directed graph G , find the maximum number ofedge-disjoint paths between s and t in G .

    How many paths from s to t are present in this graph?How many edge-disjoint paths from s to t are present in thisgraph?

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Network FlowEdge-disjoint paths

    Problem

    Given an unweighted directed graph G , find the maximum number ofedge-disjoint paths between s and t in G .

    Consider the network G ′ below:

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Network FlowEdge-disjoint paths

    Problem

    Given an unweighted directed graph G , find the maximum number ofedge-disjoint paths between s and t in G .

    Claim 1: If there are k edge-disjoint paths in G , then here is ans-t flow in the network with value at least k .

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Network FlowEdge-disjoint paths

    Problem

    Given an unweighted directed graph G , find the maximum number ofedge-disjoint paths between s and t in G .

    Claim 1: If there are k edge-disjoint paths in G , then here is ans-t flow in the network with value at least k .Claim 2: If there is an s-t flow in G ′ of value k , then there are atleast k edge-disjoint paths in G .

    Idea: Use induction on the number of edges with non-zero flowvalue.

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Course Overview

    Basic graph algorithms

    Algorithm Design Techniques:

    Greedy AlgorithmsDivide and ConquerDynamic ProgrammingNetwork Flow

    Computational Intractability

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational Intractability

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityIntroduction

    Definition (Efficient Algorithms)

    An algorithm is said to be efficient if it runs in time polynomial inthe input size. Such algorithms are also called polynomial-timealgorithms.

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityIntroduction

    Definition (Efficient Algorithms)

    An algorithm is said to be efficient if it runs in time polynomial inthe input size. Such algorithms are also called polynomial-timealgorithms.

    Question 1: Given a problem, does there exist an efficientalgorithm to solve the problem?

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityIntroduction

    Definition (Efficient Algorithms)

    An algorithm is said to be efficient if it runs in time polynomial inthe input size. Such algorithms are also called polynomial-timealgorithms.

    Question 1: Given a problem, does there exist an efficientalgorithm to solve the problem?

    There are lots of problems arising in various fields for whichthis question is unresolved.

    Question 2: Are these problems related in some manner?

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityIntroduction

    Definition (Efficient Algorithms)

    An algorithm is said to be efficient if it runs in time polynomial inthe input size. Such algorithms are also called polynomial-timealgorithms.

    Question 1: Given a problem, does there exist an efficientalgorithm to solve the problem?

    There are lots of problems arising in various fields for whichthis question is unresolved.

    Question 2: Are these problems related in some manner?

    Question 3: If someone discovers an efficient algorithm to oneof these difficult problems, then does that mean that there areefficient algorithms for other problems? If so, how do weobtain such an algorithm.

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    NP-complete problems: This is a large class of problems suchthat all problems in this class are equivalent in the followingsense:

    The existence of a polynomial-time algorithm forany one problem in this class implies the existence ofpolynomial-time algorithm for all of them.

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    NP-complete problems: This is a large class of problems suchthat all problems in this class are equivalent in the following sense:

    The existence of a polynomial-time algorithm for anyone problem in this class implies the existence ofpolynomial-time algorithm for all of them.

    Polynomial-time reduction:

    Consider two problems X and Y .Suppose there is a black box that solves arbitrary instances ofproblem X .Suppose any arbitrary instance of problem Y can be solved usinga polynomial number of standard computational steps and apolynomial number of calls to the black box that solves instanceof problem X .If the previous statement is true, then we say that Y ispolynomial-time reducible to X . A short notation for this isY ≤p X .

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Polynomial-time reduction:

    Consider two problems X and Y .Suppose there is a black box that solves arbitrary instances ofproblem X .Suppose any arbitrary instance of problem Y can be solved usinga polynomial number of standard computational steps and apolynomial number of calls to the black box that solves instanceof problem X .If the previous statement is true, then we say that Y ispolynomial-time reducible to X . A short notation for this isY ≤p X .

    Claim 1: BIPARTITE-MATCHING ≤p MAX-FLOW.

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Polynomial-time reduction:

    Consider two problems X and Y .Suppose there is a black box that solves arbitrary instances ofproblem X .Suppose any arbitrary instance of problem Y can be solved usinga polynomial number of standard computational steps and apolynomial number of calls to the black box that solves instanceof problem X .If the previous statement is true, then we say that Y ispolynomial-time reducible to X . A short notation for this isY ≤p X .

    Claim 2: Suppose Y ≤p X . If X can be solved in polynomialtime, then Y can be solved in polynomial time.

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Polynomial-time reduction:

    Consider two problems X and Y .Suppose there is a black box that solves arbitrary instances ofproblem X .Suppose any arbitrary instance of problem Y can be solved usinga polynomial number of standard computational steps and apolynomial number of calls to the black box that solves instanceof problem X .If the previous statement is true, then we say that Y ispolynomial-time reducible to X . A short notation for this isY ≤p X .

    Claim 2: Suppose Y ≤p X . If X can be solved in polynomialtime, then Y can be solved in polynomial time.Claim 3: Suppose Y ≤p X . If Y cannot be solved inpolynomial time, then X cannot be solved in polynomial time.

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Definition (Independent Set)

    Given a graph G = (V ,E ), a subset I ⊆ V of vertices is called anindependent set of G if there are no edges between any pair ofvertices in I .

    Problem

    INDEPENDENT-SET: Given a graph G = (V ,E ) and an integer k ,check if there is an independent set of size at least k in G .

    Problem

    MAXIMUM-INDEPENDENT-SET: Given a graph G = (V ,E ),output the size of independent set of G of maximum cardinality.

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Definition (Independent Set)

    Given a graph G = (V ,E ), a subset I ⊆ V of vertices is called anindependent set of G if there are no edges between any pair ofvertices in I .

    Problem

    INDEPENDENT-SET: Given a graph G = (V ,E ) and an integer k ,check if there is an independent set of size at least k in G .

    Problem

    MAXIMUM-INDEPENDENT-SET: Given a graph G = (V ,E ),output the size of independent set of G of maximum cardinality.

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Definition (Independent Set)

    Given a graph G = (V ,E ), a subset I ⊆ V of vertices is called anindependent set of G if there are no edges between any pair of verticesin I .

    Problem

    INDEPENDENT-SET: Given a graph G = (V ,E ) and an integer k ,check if there is an independent set of size at least k in G .

    Problem

    MAXIMUM-INDEPENDENT-SET: Given a graph G = (V ,E ), outputthe size of independent set of G of maximum cardinality.

    Claim 1: MAXIMUM-INDEPENDENT-SET ≤p INDEPENDENT-SET.

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Definition (Independent Set)

    Given a graph G = (V ,E ), a subset I ⊆ V of vertices is called anindependent set of G if there are no edges between any pair of verticesin I .

    Problem

    INDEPENDENT-SET: Given a graph G = (V ,E ) and an integer k ,check if there is an independent set of size at least k in G .

    Problem

    MAXIMUM-INDEPENDENT-SET: Given a graph G = (V ,E ), outputthe size of independent set of G of maximum cardinality.

    Claim 1: MAXIMUM-INDEPENDENT-SET ≤p INDEPENDENT-SET.Claim 2: INDEPENDENT-SET ≤p MAXIMUM-INDEPENDENT-SET.

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Definition (Vertex Cover)

    Given a graph G = (V ,E ), a subset S ⊆ V of vertices is called avertex cover of G if for any edge (u, v) in the graph at least one ofu, v is in S .

    Problem

    VERTEX-COVER: Given a graph G = (V ,E ) and an integer k,check if there is a vertex cover of size at most k in G .

    Problem

    MINIMUM-VERTEX-COVER: Given a graph G = (V ,E ), outputthe size of vertex cover of G of minimum cardinality.

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Definition (Vertex Cover)

    Given a graph G = (V ,E ), a subset S ⊆ V of vertices is called avertex cover of G if for any edge (u, v) in the graph at least one ofu, v is in S .

    Problem

    VERTEX-COVER: Given a graph G = (V ,E ) and an integer k,check if there is a vertex cover of size at most k in G .

    Problem

    MINIMUM-VERTEX-COVER: Given a graph G = (V ,E ), outputthe size of vertex cover of G of minimum cardinality.

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Definition (Vertex Cover)

    Given a graph G = (V ,E ), a subset S ⊆ V of vertices is called avertex cover of G if for any edge (u, v) in the graph at least one ofu, v is in S .

    Problem

    VERTEX-COVER: Given a graph G = (V ,E ) and an integer k, checkif there is a vertex cover of size at most k in G .

    Problem

    MINIMUM-VERTEX-COVER: Given a graph G = (V ,E ), output thesize of vertex cover of G of minimum cardinality.

    Claim 3: MINIMUM-VERTEX-COVER ≤p VERTEX-COVER.

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Definition (Vertex Cover)

    Given a graph G = (V ,E ), a subset S ⊆ V of vertices is called avertex cover of G if for any edge (u, v) in the graph at least one ofu, v is in S .

    Problem

    VERTEX-COVER: Given a graph G = (V ,E ) and an integer k, checkif there is a vertex cover of size at most k in G .

    Problem

    MINIMUM-VERTEX-COVER: Given a graph G = (V ,E ), output thesize of vertex cover of G of minimum cardinality.

    Claim 3: MINIMUM-VERTEX-COVER ≤p VERTEX-COVER.Claim 4: VERTEX-COVER ≤p MINIMUM-VERTEX-COVER.

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Claim 5: INDEPENDENT-SET ≤p VERTEX-COVER.

    Proof of Claim 5

    Claim 5.1: Let I be an independent set of G , then V − I is avertex cover of G .

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Claim 5: INDEPENDENT-SET ≤p VERTEX-COVER.

    Proof of Claim 5

    Claim 5.1: Let I be an independent set of G , then V − I is avertex cover of G .Claim 5.2: Let S be a vertex cover of G , then V − S is anindependent set of G .

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Claim 5: INDEPENDENT-SET ≤p VERTEX-COVER.

    Proof of Claim 5

    Claim 5.1: Let I be an independent set of G , then V − I is avertex cover of G .Claim 5.2: Let S be a vertex cover of G , then V − S is anindependent set of G .Claim 5.3: G has an independent set of size at least k if and onlyif G has a vertex cover of size at most n − k.

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Claim 5: INDEPENDENT-SET ≤p VERTEX-COVER.

    Proof of Claim 5

    Claim 5.1: Let I be an independent set of G , then V − I is avertex cover of G .Claim 5.2: Let S be a vertex cover of G , then V − S is anindependent set of G .Claim 5.3: G has an independent set of size at least k if and onlyif G has a vertex cover of size at most n − k.Given an instance (G , k) of the independent set problem, createan instance (G , n − k) of the vertex cover problem, make a singlequery to the block box for solving the vertex cover problem andreturn the answer that is returned by the black box.

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Claim 6: MINIMUM-VERTEX-COVER ≤pMAXIMUM-INDEPENDENT-SET.

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Claim 6: MINIMUM-VERTEX-COVER ≤pMAXIMUM-INDEPENDENT-SET.

    Proof of Claim 6

    Claim 6.1: G has an independent set of size k if and only if Ghas a vertex cover of size n − k.Make a single call to the black box for the maximum independentproblem with input G . If the black box returns k , then returnn − k .

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Claim 6: MINIMUM-VERTEX-COVER ≤pMAXIMUM-INDEPENDENT-SET.

    Proof of Claim 6

    Claim 6.1: G has an independent set of size k if and only if Ghas a vertex cover of size n − k.Make a single call to the black box for the maximum independentproblem with input G . If the black box returns k , then returnn − k .

    Another proof of Claim 6

    MINIMUM-VERTEX-COVER ≤p VERTEX-COVERVERTEX-COVER ≤p INDEPENDENT-SETINDEPENDENT-SET ≤p MAXIMUM-INDEPENDENT-SET

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Theorem

    If X ≤p Y and Y ≤p Z , then X ≤p Z .

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Problem

    DEG-3-INDEPENDENT-SET: Given a graph G = (V ,E ) of boundeddegree 3 (i.e., all vertices have degree ≤ 3) and an integer k , check ifthere is an independent set of size at least k in G .

    Claim 1: INDEPENDENT-SET ≤p DEG-3-INDEPENDENT-SET

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Problem

    DEG-3-INDEPENDENT-SET: Given a graph G = (V ,E ) of boundeddegree 3 (i.e., all vertices have degree ≤ 3) and an integer k , check ifthere is an independent set of size at least k in G .

    Claim 1: INDEPENDENT-SET ≤p DEG-3-INDEPENDENT-SETIdea: “Split” all vertices.

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Claim 1: INDEPENDENT-SET ≤p DEG-3-INDEPENDENT-SET

    Proof of Claim 1

    Consider graph G ′ constructed by “splitting” a vertex of G .Claim 1.1: G has an independent set of size at least k if and onlyif G ′ has an independent set of size at least (k + 1).

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Problem

    SET-COVER: Given a set U of n elements, a collection S1, ...,Smof subsets of U, and an integer k, determine if there exist acollection of at most k of these sets whose union is equal to U.

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • Computational IntractabilityPolynomial-time reduction

    Problem

    SET-COVER: Given a set U of n elements, a collection S1, ...,Smof subsets of U, and an integer k, determine if there exist acollection of at most k of these sets whose union is equal to U.

    Claim 1: VERTEX-COVER ≤p SET-COVER.

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis

  • End

    Ragesh Jaiswal, CSE, UCSD CSE202: Algorithm Design and Analysis