Lecture-23-CS210-2012.pptx

Embed Size (px)

Citation preview

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    1/31

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    2/31

    Outline of the lecture

    RefreshingDFS traversal

    Refreshing the problem of articulation points

    Relationship betweenarticulation points and DFS traversal

    Key insight and ideas

    Recursive nature ofDFS traversal(for efficient implementation of the ideas)

    2

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    3/31

    Depth First Search (DFS) traversal

    3

    A recursivealgorithm for traversing graphs

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    4/31

    DFS traversal ofG

    DFS(v){ Visited(v)true;

    For each neighbor wofv

    { if (Visited(w) = false)

    { DFS(w);

    }

    }

    }

    DFS-traversal(G)

    {

    For each vertex vV { Visited(v) false }

    For each vertex v V { If (Visited(v ) = false) DFS(v) }

    } 4

    ..;

    ..;You will need to add only a few extra

    statements here to obtain efficient

    algorithms for a variety of problems.

    DFN[v]dfn++;

    dfn0;

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    5/31

    Insight into DFS through an example

    5

    z

    y

    c

    db

    f

    gh

    u

    w

    v

    r

    s

    01

    23

    4

    5

    67

    8

    9

    10

    1112

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    6/31

    DFS(v) computes a tree rooted at v

    6

    z

    y

    c

    db

    f

    gh

    u

    w

    r

    s

    v

    A DFStree rooted at v

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    7/31

    Question:

    Is there anything unique about a DFStree ?

    Answer:yes.

    Every non-tree edge is between an ancestor

    and descendant in the DFStree.

    7

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    8/31

    8

    u

    xy

    It can never happen

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    9/31

    Every non tree edge is between ancestorand a descendant

    of DFS tree

    A short proof:Let (x,y) be a non-tree edge.

    Letxget visited before y.

    Question:

    If we remove all vertices visited prior tox, does y still lie in the connected

    component ofx?

    Answer:yes.

    DFSpursued fromx will have a path to yin DFStree.Hencexmust be ancestor of y in the DFStree.

    9

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    10/31

    Remember the following picture for DFS

    traversal

    non-tree edgeback edge

    10

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    11/31

    A novel application of DFS traversal

    11

    Computing all articulation points in a graph G

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    12/31

    No.

    The removal of any of {v,f,u} can destroy

    connectivity.

    v,f,u are called the articulation points of G.

    12

    z

    y

    c

    db

    f

    gh

    u

    w

    v

    r

    s

    Does the graph remain

    connected even after removal of

    any single vertex ?

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    13/31

    A formal definition of articulaton point

    Definition:A vertexxis said to be articulation point if there exist two distinct vertices

    uand vsuch that every path between uand vpasses throughx.

    Observation:A graph is biconnected if none of its vertices is an articulation point.

    AIM:

    Design an algorithmto compute all articulation points in a given graph.

    13

    vu x

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    14/31

    Articulation points and DFS traversal

    14

    Key insight and ideas

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    15/31

    Some observations

    Question:Cana leaf node be ana.p. ?

    Answer: Never

    15

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    16/31

    Some observations

    Question: Necessary condition for the rootto be an a.p. ?

    Answer: root must have more than one child in the DFS tree.

    Question: Is this condition sufficient as well ?

    Answer: Yes.

    The only case left : internal nodes (other than the root node) in the DFS tree ?

    AIM:

    To find necessary and sufficient conditions for an internal node to be articulation point.

    16

    vu x

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    17/31

    How will an internal node xlook like in DFS tree ?

    17

    x

    root

    T1

    At least one of uand v

    must be descendant ofx.

    Where will uand v

    be relative tox?

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    18/31

    Case 1:Exactly one of uand vis a descendant of x in DFS tree

    18

    x

    u

    v

    root

    w

    y

    No back edge from

    T1to ancestor ofx

    T1

    uwyv:

    a u-vpath not passing throughx

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    19/31

    Case 2:both uand vare descendants of x in DFS tree

    19

    x

    rootroot

    uv

    Can u and vbelong to

    T1simultaneously?

    T1

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    20/31

    Case 2:both uand vare descendants of x in DFS tree

    20

    x

    root

    u v

    w q

    y

    z

    T1 T2

    At least one of T1andT2have no back edge

    to ancestor ofx

    uwzyqv:

    a u-vpath not passing throughx

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    21/31

    Necessary condition for x to be articulation point

    Necessary condition:

    xhas at least one child y s.t. there is noback

    edge from subtree(y) to ancestorofx.

    Question:Is this condition sufficient also?

    Answer: yes.

    21

    x

    root

    yu

    v

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    22/31

    Articulation points and DFS

    Let G=(V,E) be a connected graph.

    Perform DFS traversal from any graph and get a DFS tree T.

    No leaf of T is an articulation point.

    root of T is an articulation pointif root has more than one child.

    For any internal node ??

    Theorem1: An internal nodexis articulation pointif and only if it has achild ysuch that there is no back edge from subtree(y) to any ancestor ofx.

    22

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    23/31

    Efficient algorithm for Articulation points

    23

    Exploitingrecursive nature of DFS

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    24/31

    Starting point

    Theorem1: An internal nodexis articulation pointif and only if it has a child ysuchthat there is no back edge from subtree(y) to any ancestor ofx.

    A new function

    High_pt(v):

    DFNof the highest ancestor of vto which there is a back edge from subtree(v).

    Question: Can we express Theorem 1in terms of High_pt?

    Answer: Yes

    A nodexis articulation pointiffit has a child, say y, such that High_pt(y) dfn(x).

    24

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    25/31

    Towards an O(m+n) time algorithm

    In order to compute all articulation points of a graph G=(V,E) , it suffices to

    know High_pt(v) for each vin V.

    So our aim is to compute High_pt(v) for each vin Vefficiently so that overall

    time complexity is O(m+n).

    For this we take a closer look at High_pt(v).

    25

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    26/31

    Acloser look atHigh_pt(v)

    Question: Can we express High_pt(v) in terms ofits childrenand proper ancestors?

    26

    v

    root

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    27/31

    Acloser look atHigh_pt(v)

    Question: Can we express High_pt(v) in terms ofits childrenand proper ancestors?

    High_pt(v) =

    min ? ?

    27

    v

    root

    If w=child(v)

    If w = proper

    ancestor ofv(v,w) E

    High_pt(w)

    DFN(w)

    Fully internalize the above equation

    and then only proceed.

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    28/31

    Thenovelalgorithm

    The algorithm will output an array AP[]such that

    AP[v]= trueif and only if vis an articulation point.

    28

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    29/31

    Algorithm for articulation points in a graph G

    DFS(v)

    { Visited(v)true; DFN[v]dfn++;

    For each neighbor wofv

    { if (Visited(w) = false)

    { DFS(w);

    }

    }

    }

    DFS-traversal(G)

    { dfn0;

    For each vertex vV { Visited(v) false; }

    For each vertex v V { If (Visited(v ) = false) DFS(v) }

    } 29

    ..;

    ..;

    Parent(w)v;

    AP[v]false

    What statements should we write here so

    that at the end of DFS(v),

    We have computed High_pt(v)

    Determined if vis articulation point and

    computed AP[v] accordingly.

    High_pt[v] ;

    ..;

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    30/31

    Algorithm for articulation points in a graph G

    DFS(v)

    { Visited(v)true; DFN[v]dfn++;

    For each neighbor wofv

    { if (Visited(w) = false)

    { DFS(w);

    }

    }

    }

    DFS-traversal(G)

    { dfn0;

    For each vertex vV { Visited(v) false; }

    For each vertex v V { If (Visited(v ) = false) DFS(v) }

    } 30

    ..;

    ..;

    Else if (parent(v) w)

    High_pt(v) min(DFN(w),High_pt(v))

    High_pt(v) min(High_pt(v),High_pt(w));

    Parent(w)v;

    AP[v]false

    High_pt[v] ;

    ..;If High_pt(w) DFN[v] AP[v] true

  • 8/11/2019 Lecture-23-CS210-2012.pptx

    31/31

    Conclusion

    Theorem2: For a given graph G=(V,E), all articulation pointscan becomputed in O(m+n) time.

    31