Greedy Method 16-11-2013

Embed Size (px)

Citation preview

  • 8/12/2019 Greedy Method 16-11-2013

    1/72

    Greedy Strategy

  • 8/12/2019 Greedy Method 16-11-2013

    2/72

    Most of these problems have n inputs and require us to obtain a

    subset that satisfies some constraints

    Greedy Strategy :

    Any Subset that satisfies the given constraints is called a feasible

    solution

    We are required to find a feasible solution that either maximizes or

    minimizes a given objective function

    A feasible solution that does this is called an

    OPTIMAL SOLUTION

  • 8/12/2019 Greedy Method 16-11-2013

    3/72

    For Greedy Strategy :

    We can suggest a two stage algorithm :

    1. Arrange the input in the best possible sequence

    i.ethe most appropriate elements would be available

    starting from the beginning of the list with the most deserving / the

    most meritoriouselement appearing as the first element

    2. Test element by element whether to include the current element

    into the SOLUTION set or not.

    Preprocessing

    Solving

    Greedy Sequencing

    Creating the solution

    set

  • 8/12/2019 Greedy Method 16-11-2013

    4/72

    For Greedy Strategy :

    Control abstract of greedy strategy based algorithm is given below :

    Procedure greedy (A, n)

    {

    Solution for i 1 to n

    { x Select(A)

    If feasible(solution , x) then solution U(Solution,x)

    }

    }

  • 8/12/2019 Greedy Method 16-11-2013

    5/72

  • 8/12/2019 Greedy Method 16-11-2013

    6/72

    O/1 Knapsack: Maximizepixiwhere xi= 0 or 1Subject to wixiM

    O/multiple 1 Knapsack: Maximizepixiniif xi= 1, then ni= 1, 2, 3, 4, . . . . N pieces of objects

    Subject to wixiniM

  • 8/12/2019 Greedy Method 16-11-2013

    7/72

    Illustration :

    Consider M = 20 , n = 3 (I, II, III)

    (p1,p2,p3) = (25, 24, 15)

    (w1,w2,w3) = (18, 15, 10)

    Some four feasible solutions

    S.No (x1, x2, x3) wixi pixi1 ( 1/2, 1/3,1/4)

    18 *(1/2) + 15 * (1/3) + 10 *(1/4)

    = 9 + 5 + 2.5 = 16.5

    25 *(1/2) + 24 * (1/3) + 15 *(1/4)

    = 12.5 + 8 + 3.75 = 24.25

    2 (1, 2/15, 0)18 * 1 + 15 * (2/15) + 10 * 0

    = 18 + 2 = 20

    25 * 1 + 24 * (2/15) + 15 * 0

    = 25 + 3.2 = 28.2

    3 (0, 2/3, 1)

    18 * 0 + 15 * (2/3) + 10 * 1

    = 0 + 10 + 10 = 20

    25 * 0 + 24 * (2/3) + 15 * 1

    = 0 + 16 + 15 = 31

    4 (0, 1, 1/2 )18 * 0 + 15 * 1 + 10 * (1/2)

    = 0 + 15 + 5 = 20

    25 * 0 + 24 * 1 + 15 * (1/2)

    = 0 + 24 + 7.5 = 31.5

    Observation 1 :Surely Solution 1 is sub optimal because wixi < MObservation 2 :Solution 4 appears to be an OPTIMALsolution

  • 8/12/2019 Greedy Method 16-11-2013

    8/72

    Let us try different possible greedy sequencing strategy

  • 8/12/2019 Greedy Method 16-11-2013

    9/72

    Strategy 1 : ( Profit based greedy sequencing)

    We are interested in the largest profit.

    Hence we shall fill the largest profit payable object as much

    as possible ( 1)Sequence (p1, p2, p3) = (25, 24, 15)

    is (I, II, III) (w1, w2, w3) = (18, 15, 10)

    S.No Consider How Much ? Occupancy

    wixi

    Cumulative

    Occupancy wixiM - wixi Profitpixi Cumulative

    Profitpixi1 I 1 18 * 1 = 18 18 2018 = 2 25 * 1 = 25 25

    2 II 2/15 (2/15) * 15= 2

    20 0 24 * (2/15)=3.2

    28.2

    3 III Cannot be included as M = 0 [Profit = 28.2]

  • 8/12/2019 Greedy Method 16-11-2013

    10/72

    S.No Consider How Much ? Occupancy

    wixi

    Cumulative

    Occupancy wixiM - wixi Profitpixi Cumulative

    Profitpixi1 I 1 18 * 1 = 18 18 2018 = 2 25 * 1 = 25 25

    2 II 15 (2/15) * 15

    = 2

    20 0 24 * (2/15)

    =3.2

    28.2

    3 III Cannot be included as M = 0 [Profit = 28.2]

    Solution is ( I 1, II 2/15, III 0 ) = (1, 2/15, 0)

    Profit = 28.2

    From the earlier table it is clear that this profit is not the best profit

    WHY ?

    Even though the objective function value took on large increases at

    each step, the number of steps was few, as the knapsack capacity was

    used up at a rapid rate

  • 8/12/2019 Greedy Method 16-11-2013

    11/72

    Strategy 2 : Filling more objects by conserving more capacity

    Greedy Sequencing : Objects in order of non decreasing weights

    (III, II, I) (10, 15, 18) (w3, w2, w1)

    (15, 24, 25) (p3, p2, p1)

    S.No Consider wi Occupancy

    wixi

    Cumulative

    Occupancy wixiM - wixi Profitpixi Cumulative

    Profitpixi1 III 1 10 10 2010

    = 10

    15 15

    2 II 10/15 = 2/3 15 * (2/3)

    = 10

    20 0 (2/3) * 24

    =16

    31

    3 I Cannot be included as M = 0 [Profit = 31]

    Solution is ( I 0, II 2/3, III 1) (0 , 2/3, 1) PROFIT = 31

    Even this solution is not the best solution

    WHY ?

    This time even though the capacity was used slowly, profits were not

    coming rapidly enough

  • 8/12/2019 Greedy Method 16-11-2013

    12/72

    Strategy 2 : A balanced strategy

    Balance between the rate at which profit increases and the

    rate at which capacity is used.

    Sequence (II, III, I) (15, 10, 18) [w]

    (24, 15, 25) [p]

    Index is profit per unit capacity

    Greedy Sequencing :Starting from that object which gives

    maximum profit per unit capacity

    [pi/wi] = [p1/w1, p2/w2, p3/w3] = [25/18, 24/15, 15/10]

    = (1.389, 1.6, 1.5)

  • 8/12/2019 Greedy Method 16-11-2013

    13/72

    S.No Consider wi Occupancy

    wixi

    Cumulative

    Occupancy wixiM - wixi Profitpixi Cumulative

    Profitpixi1 II 1 15 15 5 24 24

    2 III 5/10 = 1/2 (1/2) * 10

    = 5

    20 0 (1/2) * 15

    =7.5

    31.5

    3 I Cannot be included as M = 0 [Profit = 31.5]

    Solution is (0, 1, 1/2) PROFIT = 31.5

    This is the optimal solution

    Sequence (II, III, I) (15, 10, 18) [w]

    (24, 15, 25) [p]

    [pi/wi] = [p1/w1, p2/w2, p3/w3] = [25/10, 24/15, 15/10]

    = (1.389, 1.6, 1.5)

  • 8/12/2019 Greedy Method 16-11-2013

    14/72

    Algorithm :

    1. Greedy sequence the i/p data based on pi/wiratio

    2. Fill up the knapsack considering object by object filling up

    as much as possible (1) till wixi = M

    Filling up the knapsack O(n) - (1)

    Most important is Greedy Sequencing the input

    Arriving at the greedy policy

  • 8/12/2019 Greedy Method 16-11-2013

    15/72

    3. Job Sequencing with deadlines

    One Object / Unit time

    The job cannot exceed beyond the Maximum dead line

    Let n be the number of jobs & d1, d2, d3. . . ., dn be the maximum

    deadlines for completing the jobs J1, J2, J3. . ., Jn

    Therefore, Max no. of jobs that can be taken up =Max no. of time units available = Min(n, max(di))

    If ( p1, p2, . . . , pn) are the profits brought by the

    jobs (J1, J2, J3. . ., Jn) then what should be the sequence of jobs to be

    executed to maximize the profit ?

    Jobs should be sequenced in the order of profits to maximize the

    profit

  • 8/12/2019 Greedy Method 16-11-2013

    16/72

    N = 5

    (p1, p2, p3, p4, p5) = (20, 15, 10, 5, 1)

    deadlines (d1, d2, d3, d4,d5) = ( 2, 2, 1, 3, 3 )

    Max.no of time units available = Min(n, max(di)) = Min(5,3) = 3

    This decides the available slots

    [01] [ 12] [23]

    S.No.

    Jobs

    considered

    in the

    sequence of

    profit

    Deadline

    Allocation Made

    Remark pi pi[0-1] [1,2] [2,3]

    1 1 2 1 Allocate in the

    latest slot becauseearlier slot can be

    useful for an object

    with higher profit

    and lower deadline

    20 20

    2 2 2 2 1 15 35

    3 3 1 x Not possible - 35

    4 4 3 2 1 4 5 40

    J b

  • 8/12/2019 Greedy Method 16-11-2013

    17/72

    S.No.

    Jobs

    considered

    in the

    sequence of

    profit

    Deadline

    Allocation Made

    Remark pi pi[0-1] [1,2] [2,3]

    1 1 2 1

    Allocate in the

    latest slot because

    earlier slot can be

    useful for an object

    with higher profit

    and lower deadline

    20 20

    2 2 2 2 1 15 35

    3 3 1 x Not possible - 35

    4 4 3 2 1 4 5 40

    All slots filled up

    Hence allocation process is completed

    Solution set (1, 1, 0, 1, 0) with the system slots (2, 1, X, 3, X)

    (1, 2, 4) ( II, I, III)THINK:1. If execution of a job is a prerequisite to execute some other job

    2. If duration of job execution is also a specification

  • 8/12/2019 Greedy Method 16-11-2013

    18/72

    Transportation Problem

    Demand

    P4

    P3

    P2

    Cost of transport from pito ci

    Goods should be moved such that transportation

    cost is minimized

    P1

    CapacityC5C4C3C2C1

    Consumer

    P

    roducer

  • 8/12/2019 Greedy Method 16-11-2013

    19/72

    J1 J2 J3 .. ..

    E1 Efficiency of employee Eiin executing job Ji

    One job to be allocated to one employee such

    that overall efficiency is maximized

    E2

    E3

    :

    :

    Assignment Problem

    G d St t

  • 8/12/2019 Greedy Method 16-11-2013

    20/72

    Greedy Strategy :

    5. Minimum Spanning Tree - MST

    Consider a weighted graph G(n, e, ) where wkis the

    weight of edge ek ek (vi, vj)

    10

    11

    10

    10

    12

    12

    10

    9

    9

    88

    7

    1

    2

    3

    4

    5

    6

    7

    ek

    wk

    vi

    vj

    W May correspond to traversal time if it is a road network

    May correspond to volume of flow if it is a flow network

    P bl

  • 8/12/2019 Greedy Method 16-11-2013

    21/72

    Problem :

    If one of the nodes can be chosen as the pump then

    choose the edges such that total distance traversed by the

    fluid to various nodes is minimum

    If such a minimal distance network can be obtained, then

    which node should be the pump ?

    Such a minimum distance network should span through all

    vertices.

    In such a network there should not be a circuit, because it

    provides alternate path to reach any vertex and ambiguity

    exists

  • 8/12/2019 Greedy Method 16-11-2013

    22/72

    Such a network should consist of minimum number of

    edges.

    Since the pump has to reach all vertices such a networkshould still remain connected

    Hence such a network should be a TREE

    Recall :

    A tree is a circuit less connected graph

    A tree has one and only one path between every pair ofvertices

    In a tree there are (n-1) edges if n represents the total

    number of vertices

  • 8/12/2019 Greedy Method 16-11-2013

    23/72

    A erte in the tree ith minim m eccentricit is called the

  • 8/12/2019 Greedy Method 16-11-2013

    24/72

    A vertex in the tree with minimum eccentricity is called the

    treecentre.

    What is eccentricity e(vi) ?

    Eccentricity of a vertex vi, e(vi) is defined as the distance of

    the vertex to the farthest vertex from it.

    11

    10

    109

    8

    7

    1

    2

    3

    4

    5

    6

    7

    e(1) = 5

    e(3) = 4

    e(2) = 3

    e(4) = 3

    e(5) = 4

    e(7) = 5

    e(6) = 4

    Algorithm :

  • 8/12/2019 Greedy Method 16-11-2013

    25/72

    Algorithm :

    Compute the path length from the vertex to all pendant

    vertices in the tree

    Choose the max path length This gives the eccentricity of the vertex

    Path Length Should it be theoretically 1 for every edge ?

    Or Should it be cost of the edge ? (Practically)

    In this example e(4) = 3 is the minimum

    IIy e(2) = 3 is also minimum

    Therefore , Vertex 4 can be the tree centre or even vertex 2

    i.e. PUMP can be located in vertex 4 or in 2

  • 8/12/2019 Greedy Method 16-11-2013

    26/72

    Can there be a simpler algorithm to locate the tree centre ?

    YES!!

    11

    10

    109

    8

    7

    1

    2

    3

    4

    5

    6

    7

    Remove all pendant vertices

    10

    9 7

    2

    3

    4

    6

    Continue the process

    of removing pendant

    vertices

    9

    2

    4Algorithm terminates

    giving the tree centres

    ICASE 2:

  • 8/12/2019 Greedy Method 16-11-2013

    27/72

    D

    A

    E

    X C

    B

    H

    I

    F

    G

    A

    X C

    B

    XAssignment :

    1. Why should this method of peeling pendant vertices work?

    Justify!!

    2. Can a tree be unicentred or bicentred and if bicentred then

    should the centers be adjacent

    CASE 2:

    Problem :

  • 8/12/2019 Greedy Method 16-11-2013

    28/72

    Problem :

    Given a graph G(n,e),

    we have to choose (n-1) edges out of e edges [(n-1) < e]

    such that

    the resultant graph is connected and circuit less

    and the sum of the weights of the participating edges should

    be minimum.

    Solution Set : is a subset of dataset

    Objective Function :Minimize wi i = 1,2, . . .(n-1)Such that resulting graph is connected and circuit less

    Can we sequence the edges in the most appropriate way ?

    Greedy Sequencing KRUSKAL ALGORITHM

    KRUSKALs Algorithm :

  • 8/12/2019 Greedy Method 16-11-2013

    29/72

    KRUSKAL s Algorithm :

    STEP 1 : Arrange the edges in the non-decreasing sequence

    of edge weightsgreedy sequencing

    STEP 2 : Insert the next edge iff it doesnt make a circuit, with

    the edges already present.

    Step 2 is (n-1)O(e) algorithm

    What about overall algorithm?

    Got to consider STEP 1

    What can be max e ?

  • 8/12/2019 Greedy Method 16-11-2013

    30/72

    What can be max e ?

    Note:

    (i) Loop edges & Parallel edges should be eliminated.

    (ii) If parallel edges have to be replaced by an edge

    which should be replaced ? Min Weighted edge

    (iii) Then max_e n(n-1)/2

    Therefore, (n-1) - O(n(n-1)/2) for step 2

    But e < n(n-1)/2

    Step 1 O(n2) - Sorting

    Step 2 O(n2

    ) - Subset Creation

    - HOW?

    why?

    Illustration :

  • 8/12/2019 Greedy Method 16-11-2013

    31/72

    Illustration :

    Consider

    A

    B

    E

    D

    FC

    5

    5

    4

    4

    4

    4

    6

    2

    1

    3

    3

    6

    D

    B

    A E

    FC

    5

    5

    4

    4

    4

    4

    6

    23

    3

    A General graph is

    reduced to a simp le

    graph (w ithout paral lel

    edges and self loop )

    Greedy Sequencing :

  • 8/12/2019 Greedy Method 16-11-2013

    32/72

    Greedy Sequencing :

    Sequence Edge Weight

    9 (A,B) 5

    8 (A,E) 5

    7 (A,C) 4

    6 (B,D) 4

    5 (C,D) 4

    4 (E,F) 4

    3 (B,C) 3

    2 (C,E) 3

    1 (D,F) 2

    B

    A E

    FC

    5

    5

    4

    4

    4

    4

    6

    23

    3

    D

  • 8/12/2019 Greedy Method 16-11-2013

    33/72

  • 8/12/2019 Greedy Method 16-11-2013

    34/72

  • 8/12/2019 Greedy Method 16-11-2013

    35/72

    Sequence Edge Weight

  • 8/12/2019 Greedy Method 16-11-2013

    36/72

    n = 6 n-1 = 5 |mst| = 3

    B

    A E

    FC

    23

    3

    D

    9 (A,B) 5

    8 (A,E) 5

    7 (A,C) 4

    6 (B,D) 4

    5 (C,D) 4

    4 (E,F) 4

    3 (B,C) 3

    2 (C,E) 3

    1 (D,F) 2

    Sequence Edge Weight

  • 8/12/2019 Greedy Method 16-11-2013

    37/72

    n = 6 n-1 = 5 |mst| = 4

    B

    A E

    FC

    4

    23

    3

    D

    9 (A,B) 5

    8 (A,E) 5

    7 (A,C) 4

    6 (B,D) 4

    5 (C,D) 4

    4 (E,F) 4

    3 (B,C) 3

    2 (C,E) 3

    1 (D,F) 2

    Sequence Edge Weight

  • 8/12/2019 Greedy Method 16-11-2013

    38/72

    n = 6 n-1 = 5 |mst| = 4

    4

    B

    A E

    FC

    4

    23

    3

    D4 Cannot be insertedbecause a circui t is

    formed

    9 (A,B) 5

    8 (A,E) 5

    7 (A,C) 4

    6 (B,D) 4

    5 (C,D) 4

    4 (E,F) 4

    3 (B,C) 3

    2 (C,E) 3

    1 (D,F) 2

    Sequence Edge Weight

  • 8/12/2019 Greedy Method 16-11-2013

    39/72

    n = 6 n-1 = 5 |mst| = 4

    B

    A E

    FC

    4

    23

    3

    D

    9 (A,B) 5

    8 (A,E) 5

    7 (A,C) 4

    6 (B,D) 4

    5 (C,D) 4

    4 (E,F) 4

    3 (B,C) 3

    2 (C,E) 3

    1 (D,F) 2

    Sequence Edge Weight

  • 8/12/2019 Greedy Method 16-11-2013

    40/72

    n = 6 n-1 = 5 |mst| = 5

    4

    B

    A E

    FC

    4

    23

    3

    D

    9 (A,B) 5

    8 (A,E) 5

    7 (A,C) 4

    6 (B,D) 4

    5 (C,D) 4

    4 (E,F) 4

    3 (B,C) 3

    2 (C,E) 3

    1 (D,F) 2

    MST is formed

    Wi= 2 + 3 + 3 + 4 + 4

    = 16

    PRIMs Algorithm : STEP 1: Transfo rm a

  • 8/12/2019 Greedy Method 16-11-2013

    41/72

    PRIM s Algorithm : STEP 1: Transfo rm a

    general graph to a

    simple graph.

    A

    B

    E

    D

    FC

    5

    5

    4

    4

    4

    4

    6

    2

    1

    3

    3

    6

    DB

    A E

    FC

    5

    5

    4

    4

    4

    4

    6

    23

    3

    PRIMs Algorithm : STEP 2: Create

  • 8/12/2019 Greedy Method 16-11-2013

    42/72

    PRIM s Algorithm : STEP 2: Create

    distance matr ix

    (Adjacency Matrix )

    B

    A E

    FC

    5

    5

    4

    4

    4

    4

    6

    23

    3

    A B C D E F

    A - 5 4 5 B 5 - 3 4 C 4 3 - 4 3 D 4 4 - 6 2E 5 3 - 4F 2 4 -

    PRIMs Algorithm : STEP 3: Start w ith tw o

  • 8/12/2019 Greedy Method 16-11-2013

    43/72

    g

    sets

    MST set

    |nm| = 0

    B

    A E

    FC

    D

    RESIDUAL set

    |nr| = 6

    PRIMs Algorithm : Bring A into mst-set

  • 8/12/2019 Greedy Method 16-11-2013

    44/72

    g g

    MST set RESIDUAL set

    |nm| = 1 |nr| = 5

    B

    A E

    FC

    D

    PRIMs Algorithm : STEP 3: Bring A in to

  • 8/12/2019 Greedy Method 16-11-2013

    45/72

    g

    B

    E

    FC

    D

    g

    mst-set

    MST set RESIDUAL set

    |nm| = 1 |nr| = 5

    A

    There are many edges that connect these two sets :

    Like (A,B) = 5, (A,C) = 4, (A,E) = 5

    PRIMs Algorithm : Choose the m inimum of al l

  • 8/12/2019 Greedy Method 16-11-2013

    46/72

    g

    B

    E

    FC

    D

    these connected edges

    (A,B) = 5, (A,C) = 4, (A,E) = 5

    MST set RESIDUAL set

    |nm| = 1 |nr| = 5

    A

    Therefore, C moves into the MST set along with the edge AC

    PRIMs Algorithm : Choose the m inimum of al l

  • 8/12/2019 Greedy Method 16-11-2013

    47/72

    g

    B

    E

    F

    D

    these connected edges

    (A,B) = 5, (A,C) = 4, (A,E) = 5

    MST set RESIDUAL set

    |nm| = 2 |nr| = 4

    A

    Therefore, C moves into the MST set along with the edge AC

    C

    4

    |nm| = 2 |nr| = 4

  • 8/12/2019 Greedy Method 16-11-2013

    48/72

    B

    E

    F

    D

    MST set RESIDUAL set

    | m| | r|

    A

    C

    4

    A B C D E F

    A 5 5 B - 4 C 3 4 3 D 4 - 6 2

    E 3 - 4F 2 4 -

    This amounts to

    deriving the following

    residual distance

    matrix

  • 8/12/2019 Greedy Method 16-11-2013

    49/72

    Repeat the previou s operat ions

    PRIMs Algorithm :Th d th t

  • 8/12/2019 Greedy Method 16-11-2013

    50/72

    B

    E

    F

    D

    RESIDUAL set

    |nr| = 4

    MST set

    |nm| = 2

    A

    C

    4

    (A,B) = 5

    (A,E) = 5

    (C,B) = 3

    (C,D) = 4

    (C,E) = 3

    There are many edges that

    connect these two sets

    Choose the minimum i.e (C,B) or (C,E)

    Say (C,B)

    PRIMs Algorithm :

  • 8/12/2019 Greedy Method 16-11-2013

    51/72

    E

    F

    D

    RESIDUAL set

    |nr| = 3

    MST set

    |nm| = 3

    A

    C

    4

    PRIM s Algorithm :

    (A,B) = 5

    (A,E) = 5

    (C,B) = 3

    (C,D) = 4

    (C,E) = 3

    There are many edges that

    connect these two sets

    Choose the minimum i.e (C,B) or (C,E)

    Say (C,B)

    B

    3

    |nr| = 4|nm| = 2

  • 8/12/2019 Greedy Method 16-11-2013

    52/72

    E

    F

    D

    RESIDUAL setMST set

    | m|

    A

    C

    4

    B3

    A B C D E F

    A 5 B 4 C 4 3 D - 6 2

    E 3 - 4

    F 2 4 -

    Reduced distance

    matr ix

    PRIMs Algorithm :

  • 8/12/2019 Greedy Method 16-11-2013

    53/72

    PRIM s Algorithm :There are many edges that

    connect these two sets

    Choose the minimum i.e. (C,E)

    E

    F

    D

    RESIDUAL set

    |nr| = 3

    MST set

    |nm| = 3

    A

    C

    4

    (A,E) = 5

    (B,D) = 4

    (C,D) = 4

    (C,E) = 3B

    3

    PRIMs Algorithm :

  • 8/12/2019 Greedy Method 16-11-2013

    54/72

    PRIM s Algorithm :There are many edges that

    connect these two sets

    Choose the minimum i.e. (C,E)

    F

    D

    RESIDUAL set

    |nr| = 2

    MST set

    |nm| = 4

    A

    C

    4

    (A,E) = 5

    (B,D) = 4

    (C,D) = 4

    (C,E) = 3B

    3

    E

    3

  • 8/12/2019 Greedy Method 16-11-2013

    55/72

    PRIMs Algorithm :

  • 8/12/2019 Greedy Method 16-11-2013

    56/72

    PRIM s Algorithm :There are many edges that

    connect these two sets

    Choose the minimum i.e. Say (B,D)

    F

    D

    RESIDUAL set

    |nr| = 2

    MST set

    |nm| = 4

    A

    C

    4

    (B,D) = 4

    (C,D) = 4

    (E,F) = 4B

    3

    E

    3

    PRIMs Algorithm :

  • 8/12/2019 Greedy Method 16-11-2013

    57/72

    PRIM s Algorithm :There are many edges that

    connect these two sets

    Choose the minimum i.e. Say (B,D)

    F

    RESIDUAL set

    |nr| = 1

    MST set

    |nm| = 5

    A

    C

    4

    (B,D) = 4

    (C,D) = 4

    (E,F) = 4B

    3

    E

    D4

    3

    |nr| = 1|nm| = 5

  • 8/12/2019 Greedy Method 16-11-2013

    58/72

    F

    RESIDUAL setMST set

    m

    A

    C

    4

    B3

    E

    D

    A B C D E F

    A B C D 2

    E 4

    F -

    Reduced distance

    matr ix

    4

    3

    PRIMs Algorithm :

  • 8/12/2019 Greedy Method 16-11-2013

    59/72

    PRIM s Algorithm :There are many edges that

    connect these two sets

    Choose the minimum i.e. (D,F)

    F

    RESIDUAL set

    |nr| = 1

    MST set

    |nm| = 5

    A

    C

    4

    (C,F) = (D,F) = 2

    (E,F) = 4B

    3

    E

    D4

    (B,F) = (A,F) =

    3

    PRIMs Algorithm :

  • 8/12/2019 Greedy Method 16-11-2013

    60/72

    s go tThere are many edges that

    connect these two sets

    Choose the minimum i.e. (D,F)

    RESIDUAL set

    |nr| = 0

    MST set

    |nm| = 6

    A

    C

    4

    (C,F) = (D,F) = 2

    (E,F) = 4B

    3

    E

    D4

    (B,F) = (A,F) =

    F2

    Since nr= the algorithm terminates

    Wi = 4 + 3 + 3 + 4 + 2 = 16

    3

  • 8/12/2019 Greedy Method 16-11-2013

    61/72

    6. Compare and contrast Prims algorithm & Kruskalss algorithm.

  • 8/12/2019 Greedy Method 16-11-2013

    62/72

    7. Show that a mst shall always contain the most minimum weighted

    edge and the pendant edge irrespective of its weight (if present).

    8. If the signal level falls while reaching different vertices from PUMP

    vertex (tree centre) then BOOSTERS have to be inserted atappropriate nodes (vertices). This requires Tree-Vertex-Splitting.

    Tree Vertex Splitting is also a greedy algorithm. Study this algorithm

    (HSR)

    9. Implement tree-centre locating algorithms

    10.How do you argue that Prims algorithm is also a Greedy Strategy

    based ?

    11.There is one more algorithm to generate mst called randomized mst

    algorithm. Study this.

    12.Propose a solution

    In a locality a closed circuit cable TV connection has to be provided.

    Propose the layout. Which should be the transmitter nodes? Where

    should the amplifier (boosters) be placed ?

    Additional Reference : N.DEO, Graph Theory

    Extension to Clustering

  • 8/12/2019 Greedy Method 16-11-2013

    63/72

    Zahns Algorithm

    STEP 1 :Given m samples in n-d space. Obtain the adjacencyor distance matrix

    1 2 . . m

    1

    2

    :

    m

    STEP 2 Obt i MST ( ll P i l ith i d)

  • 8/12/2019 Greedy Method 16-11-2013

    64/72

    STEP 2 :Obtain MST (generally Prims algorithm is used)

    STEP 3 :Define the Undesiredbranches in the MST

    whose weights are more than some threshold

    (Perhaps average of all branch weights)

    STEP 4 :Remove these undesiredbranches. A MST breaks

    into a forest of connected components. Each

    connected component is a cluster.

    6 Single Source Shortest Paths:

  • 8/12/2019 Greedy Method 16-11-2013

    65/72

    6. Single Source Shortest Paths:

    Given a network find the shortest path from a source point to

    a destination point. (Dijkstras Algorithm)Illustration :

    V0

    V2

    V1

    V3

    V4

    V5

    50 10

    1020

    15

    20

    15 35

    30

    3

    45

    Source: V0 ( V1, V2, V3, V4, V5) Shortest Path ?

    STEP 1 : 45

  • 8/12/2019 Greedy Method 16-11-2013

    66/72

    DISTANCE MATRIX

    V0 V1 V2 V3 V4 V5

    V0 - 50 10 45 V1 - 15 10 V2 20 - 15 V3 20 - 35 V4 30 - V

    5 3 -

    V0

    V2

    V1

    V3

    V4

    V5

    50 10

    10

    20

    15

    2015 35

    30

    3

    45

  • 8/12/2019 Greedy Method 16-11-2013

    67/72

    From V0to

    V1 V2 V3 V4 V5

    50 10 45

    Min is V0 V2 = 10

    V0

    V2

    V1

    V3

    V4

    V5

    50 10

    10

    20

    15

    2015 35

    30

    3

    STEP 2 :

  • 8/12/2019 Greedy Method 16-11-2013

    68/72

    From V0to

    to V1 V3 V4 V5

    V0 Vw 50 45 V0 Vw

    Via V2

    V0 V2 Vw

    10 + =

    10 + 15

    = 25

    10 + =

    10 + =

    Choose the

    minimum

    50 25 45

    Therefore , The minimum is 25 V0 V3

    Which is V0 V2 V3

    STEP 3 : V5V4V1to

  • 8/12/2019 Greedy Method 16-11-2013

    69/72

    From V0to

    Choose the minimum 45

    Shortest Path V0 V3 V1 i.e 45

    25 + =

    25 + 35

    = 60

    25 + 20

    = 45V0 V3 Vw

    V0 V2 Vw

    4550V0 Vw

    4545Choose theminimum

    V0

    V2

    V1

    V3

    V4

    V5

    50 10

    1020

    15

    2015 35

    30

    3

    45

    STEP 4 : to V4 V5

  • 8/12/2019 Greedy Method 16-11-2013

    70/72

    From V0to

    Min_Path V0 V4

    Min_Cost 45

    V0 Vw 45 V0 V2 Vw V0 V3 Vw 60 V0 V1 Vw

    45 + 10

    = 55

    45 + =

    Choose the

    minimum45

    V0

    V2

    V1

    V3

    V4

    V5

    50 10

    1020

    15

    2015 35

    30

    3

    45

    STEP 5 : to V5

  • 8/12/2019 Greedy Method 16-11-2013

    71/72

    From V0to

    Min V0 V5

    V0 Vw V0 V2 Vw V0 V3 Vw V0 V1 Vw V0 V4 Vw

    Hence the shortest paths from vo :

    V1 V2 V3 V4 V5

    45 10 25 45

    V0

    V2

    V1

    V3

    V4

    V5

    50 10

    1020

    15

    2015 35

    30

    3

    45

  • 8/12/2019 Greedy Method 16-11-2013

    72/72

    1. Formulate the algorithm. Implement it. Estimate the timeand space required.

    2. Obtain different paths covering all vertices from V0

    3. Obtain all paths from every vertex to all other vertices

    4. Obtain different paths from every vertex to one destination

    vertex

    5. Check what would happen if the weight of one edge isve?