You are on page 1of 73

Constructive heuristics

of the TSP
(Insertion Heuristics)
:Prepeared by
Ayoub Faisal Alzabidi
Supervised by:
Prof. Mehdi Mrad
OUTLINE
Introduction

Insertion Heuristics
Random Insertion Heuristic

Nearest Insertion Heuristic

Farthest Insertion Heuristic

Cheapest Insertion Heuristic


Introduction
 Travelling Salesman Problem OR Travelling Salesperson Problem (TSP) asks the following

question: "Given a list of cities and the distances between each pair of cities, what is the
shortest possible route that visits each city exactly once and returns to the origin city?“

 It is an NP-hard problem in combinatorial optimization.

 It is important in:

 Theoretical computer science

 operations research
Introduction

• Insertion Heuristics:
- Random Insertion Heuristic
- Nearest Insertion Heuristic Improvement heuristics
-Node insertion
- Farthest Insertion Heuristic
-Exchange heuristic
- Cheapest Insertion Heuristic -Variable depth search
Heuristic - Random insertion )RI(

Random insertion for TSP


1. Start with a subgraph consisting of node i only.

2. Find node k such that cik is minimal and form the subtour i-k-i

3. )Selection) Given a subtour, randomly select node k not


in the subtour to enter the subtour..

4. (Insertion) Find the arc(i, j) in the subtour which


minimizes
cik+ckj-cij . Insert k between i and j.

5. Go to step3 unless we have a Hamiltonian cycle.


Heuristic - Random insertion )RI(
Step 1: Suppose node 1 is chose as beginning.
Step 2: The node 4 is selected such that subtour with minimal cost c(1,4)=4

2 3 3 2 3 3
2 2
2 3 4 2 3
1 4
1 4 2
4
2 4 1 42
1
5
5 3
3
Tour: 1-4-1
5
5 c(1,4)=4
Heuristic - Random insertion )RI(
Step 3: Randomly select node not in the subtour (Node 2, Node 3, or
Node 5).

)Selection(
Randomly choose one 2 3 3
Node 2 2 3 4 2
4
Node 3 1
2
4
1 2
Node 5 5
3

5
Heuristic - Random insertion )RI(
Step 3: Node 3 is selected randomly.

)Selection(
Randomly choose one 2 3 3
Node 2 2 3 4 2
4
Node 3 1
2
4
1 2
Node 5 5
3

5
Heuristic - Random insertion )RI(
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(

3 3=3+2-2 :1-3-4
2 3
2 3 4 2
1 4
2
4
1 2
5
3

5
Heuristic - Random insertion )RI(
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(

3 3=3+2-2 :1-3-4
2 3
3=3+2-2 :4-3-1
2 3 4 2
1 4
2
4
1 2
5
3

5
Heuristic - Random insertion )RI(
Step 4: Insert Node 3 between Node 1 and Node 4 with the minimal
increasing cost c(1,3,4)=3

)Insertion(
arbitrary choose one
Tour: 1-3-4-1
2 3 3 1-3-4: 3+2-2=3
Total cost = 4+3=7 4-3-1: 3+2-2=3
2 3 4 2
c(1,4)=4
1 4
c(1,3,4)=3 2
2 4
1 2
5
3

5
Heuristic - Random insertion )RI(
Step 3: Randomly select node not in the subtour (Node 2 or Node 5).

)Selection(
Randomly choose one 2 3 3
Node 2 2 3 4 2
4
Node 5 1
2 4
1
5
3

5
Heuristic - Random insertion )RI(
Step 3: Node 2 is selected randomly.

)Selection(
Randomly choose one 2 3 3
Node 2 2 3 4 2
4
Node 5 1
2 4
1
5
3

5
Heuristic - Random insertion )RI(
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(

2 3 3 2=2+3-3 :1-2-3
2 3 4 2
1 4
2 4
1
5
3

5
Heuristic - Random insertion )RI(
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(

2 3 3 2=2+3-3 :1-2-3
5=3+4-2 :3-2-4
2 3 4 2
1 4
2 4
1
5
3

5
Heuristic - Random insertion )RI(
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(

2=2+3-3 :1-2-3
2 3 3
5=3+4-2 :3-2-4
2 3 4 2
4=4+2-2 :4-2-1
1 4
2 4
1
5
3

5
Heuristic - Random insertion )RI(
Step 4: Insert Node 2 between Node 1 and Node 3 with the minimal
increasing cost c(1,2,3)=2

Tour: 1-2-3-4-1
Total cost = 4+3+2=9 (Insertion)
2 3 3 1-2-3: 2+3-3=2
c(1,4)=4 3-2-4: 3+4-2=5
2 3 4 2
c(1,3,4)=3 4-2-1: 4+2-2=4
1 4
c(1,2,3)=2 4
1 2

5
3

5
Heuristic - Random insertion )RI(

Step 3: Node 5 is the only choice, so Node 5 is selected.

)Selection(

Only Node 5 can be selected


2 3 3

2 3 4 2
1 4
2 4
1
5
3

5
Heuristic - Random insertion )RI(
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(

2 3 3 1-5-2: 3+1-2=2
2 3 4 2
1 4
2 4
1
5
3

5
Heuristic - Random insertion )RI(
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(

2 3 3 1-5-2: 3+1-2=2
2-5-3: 1+4-3=2
2 3 4 2
1 4
2 4
1
5
3

5
Heuristic - Random insertion )RI(
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(

2 3 3 1-5-2: 3+1-2=2
2-5-3: 1+4-3=2
2 3 4 2
3-5-4: 4+5-2=7
1 4
2 4
1
5
3

5
Heuristic - Random insertion )RI(
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(

2 3 3 1-5-2: 3+1-2=2
2-5-3: 1+4-3=2
2 3 4 2
3-5-4: 4+5-2=7
1 4
4-5-1: 5+3-2=6
2 4
1
5
3

5
Heuristic - Random insertion )RI(
Step 4: Insert Node 5 between Node 1 and Node 2 with the minimal
increasing cost c(1,5,2)=2

)Insertion(
Tour: 1-5-2-3-4-1
arbitrary choose one
Total cost = 4+3+2+2=11
2 3 3 1-5-2: 3+1-2=2
c(1,4)=4 2-5-3: 1+4-3=2
2 3
c(1,3,4)=3
4 2 3-5-4: 4+5-2=7
4
c(1,2,3)=2
1 4-5-1: 5+3-2=6
2 4
1
c(1,5,2)=2 5
3

5
Step 5: Stop.
Heuristic - Nearest insertion )NI(

Nearest insertion for TSP


1. Start with a subgraph consisting of node i only.

2. Find node k such that cik is minimal and form the subtour i-k-i

3. (Selection) Given a subtour, find node k not in the subtour


closest to any node in the tour.

4. (Insertion) Find the arc(i, j) in the subtour which


minimizes
cik+ckj-cij Insert k between i and j.

5. Go to step3 unless we have a Hamiltonian cycle.


Heuristic - Nearest insertion (NI)
Step 1: Suppose node 1 is chose as beginning.
Step 2: The node 4 is selected such that subtour with minimal cost c(1,4)=4

2 3 3 2 3 3
2 2
2 3 4 2 3
1 4
1 4 2
4
2 4 1 42
1
5
5 3
3
Tour: 1-4-1
5
5 c(1,4)=4
()NIHeuristic - Nearest insertion
Step 3: Node 3 and 2 are closest to node 1 and 4 respectively.

(Selection(
arbitrary choose one
1-2: 2 2 3 3
1-3: 3
2 3
1-5: 3 4 2
1 4
2
4-2: 4 4
1 2
4-3: 2 3
5
4-5: 5
5
()NIHeuristic - Nearest insertion
Step 3: Node 3 is selected arbitrarily.

(Selection(
arbitrary choose one
1-2: 2 2 3 3
1-3: 3
2 3
1-5: 3 4 2
1 4
2
4-2: 4 4
1 2
4-3: 2 3
5
4-5: 5
5
Heuristic - Nearest insertion (NI)
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(

3 3=3+2-2 :1-3-4
2 3
2 3 4 2
1 4
2
4
1 2
5
3

5
Heuristic - Nearest insertion (NI)
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(

3 3=3+2-2 :1-3-4
2 3
3=3+2-2 :4-3-1
2 3 4 2
1 4
2
4
1 2
5
3

5
Heuristic - Nearest insertion (NI)
Step 4: Insert Node 3 between Node 1 and Node 4 with the minimal
increasing cost c(1,3,4)=3

)Insertion(
arbitrary choose one
Tour: 1-3-4-1
2 3 3 1-3-4: 3+2-2=3
Total cost = 4+3=7 4-3-1: 3+2-2=3
2 3 4 2
c(1,4)=4
1 4
c(1,3,4)=3 2
2 4
1 2
5
3

5
()NIHeuristic - Nearest insertion
Step 3: Node 2 is closest to node 1 in the subtour.

)Selection(

1-2: 2 2 3 3
1-5: 3
2 3 4 2
3-2: 3 4
1
3-5: 4 2 4
1
4-2: 4 5
3
4-5: 5
5
()NIHeuristic - Nearest insertion
Step 3: Node 2 is selected.

)Selection(

1-2: 2 2 3 3
1-5: 3
2 3 4 2
3-2: 3 4
1
3-5: 4 2 4
1
4-2: 4 5
3
4-5: 5
5
Heuristic - Nearest insertion (NI)
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(

2 3 3 2=2+3-3 :1-2-3
2 3 4 2
1 4
2 4
1
5
3

5
Heuristic - Nearest insertion (NI)
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(

2 3 3 2=2+3-3 :1-2-3
5=3+4-2 :3-2-4
2 3 4 2
1 4
2 4
1
5
3

5
Heuristic - Nearest insertion (NI)
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(

2=2+3-3 :1-2-3
2 3 3
5=3+4-2 :3-2-4
2 3 4 2
4=4+2-2 :4-2-1
1 4
2 4
1
5
3

5
Heuristic - Nearest insertion (NI)
Step 4: Insert Node 2 between Node 1 and Node 3 with the minimal
increasing cost c(1,2,3)=2

Tour: 1-2-3-4-1
Total cost = 4+3+2=9 (Insertion)
2 3 3 1-2-3: 2+3-3=2
c(1,4)=4 3-2-4: 3+4-2=5
2 3 4 2
c(1,3,4)=3 4-2-1: 4+2-2=4
1 4
c(1,2,3)=2 4
1 2

5
3

5
Heuristic - Nearest insertion (NI)

Step 3: Node 5 is the only choice, so Node 5 is selected.

)Selection(

Only Node 5 can be selected


2 3 3

2 3 4 2
1 4
2 4
1
5
3

5
Heuristic - Nearest insertion (NI)
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(

2 3 3 1-5-2: 3+1-2=2
2 3 4 2
1 4
2 4
1
5
3

5
Heuristic - Nearest insertion (NI)
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(

2 3 3 1-5-2: 3+1-2=2
2-5-3: 1+4-3=2
2 3 4 2
1 4
2 4
1
5
3

5
Heuristic - Nearest insertion (NI)
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(

2 3 3 1-5-2: 3+1-2=2
2-5-3: 1+4-3=2
2 3 4 2
3-5-4: 4+5-2=7
1 4
2 4
1
5
3

5
Heuristic - Nearest insertion (NI)
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(

2 3 3 1-5-2: 3+1-2=2
2-5-3: 1+4-3=2
2 3 4 2
3-5-4: 4+5-2=7
1 4
4-5-1: 5+3-2=6
2 4
1
5
3

5
Heuristic - Nearest insertion (NI)
Step 4: Insert Node 5 between Node 1 and Node 2 with the minimal
increasing cost c(1,5,2)=2

)Insertion(
Tour: 1-5-2-3-4-1
arbitrary choose one
Total cost = 4+3+2+2=11
2 3 3 1-5-2: 3+1-2=2
c(1,4)=4 2-5-3: 1+4-3=2
2 3
c(1,3,4)=3
4 2 3-5-4: 4+5-2=7
4
c(1,2,3)=2
1 4-5-1: 5+3-2=6
2 4
1
c(1,5,2)=2 5
3

5
Step 5: Stop.
Heuristic - Farthest insertion )FI(

Farthest insertion for TSP


1. Start with a subgraph consisting of node i only.

2. Find node k such that cik is maximal and form the subtour i-k-i

3. (Selection) Given a subtour, find node k not in the subtour


farthest from any node in the tour.

4. (Insertion) Find the arc(i, j) in the subtour which


minimizes
cik+ckj-cij Insert k between i and j.

5. Go to step3 unless we have a Hamiltonian cycle.


Heuristic - Farthest insertion (FI)
Step 1: Suppose node 1 is chose as beginning.
Step 2: The node 5 is selected such that subtour with maximal cost
c(1,5)=6

2 3 3 2 3 3
2 2
2 3 4 2 3
1 4
1 4
2 4
2 4 1 4
1 3
5
5
3
3 Tour: 1-5-1
5
5 c(1,5)=6
Heuristic - Farthest insertion (FI)
Step 3: Node 4 is farthest from node 5 in the subtour.

(Selection(
2 3 3
1-2: 2 2 2
1-3: 3 3
1 4
1-4: 2 4
1 2
4
3
5-2: 1 5
5-3: 4 3
5-4: 5 5
Heuristic - Farthest insertion (FI)
Step 3: Node 4 is selected.

(Selection(
2 3 3
1-2: 2 2 2
1-3: 3 3
1 4
1-4: 2 4
1 2
4
3
5-2: 1 5
5-3: 4 3
5-4: 5 5
Heuristic - Farthest insertion (FI)
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(
2 3 3
4=2+5-3 :1-4-5
2 2
3
1 4
2 4
1 4
3
5
3
5
Heuristic - Farthest insertion (FI)
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(
2 3 3
4=2+5-3 :1-4-5
2
4=5+2-3 :5-4-1 2
3
1 4
2 4
1 4
3
5
3
5
Heuristic - Farthest insertion (FI)
Step 4: Insert Node 4 between Node 1 and Node 5 with the minimal
increasing cost c(1,4,5)=4

)Insertion(
arbitrary choose one 2 3 3
Tour: 1-4-5-1
1-4-5: 2+5-3=4 Total cost = 6+4=10 2 2
5-4-1: 5+2-3=4 3
1 4
c(1,5)=6
2 4
c(1,4,5)=4 1 4
5
3
5
Heuristic - Farthest insertion (FI)
Step 3: Node 2 and Node 3 are farthest from Node 4 and Node 5
respectively in the subtour.

)Selection(
2 3 3
1-2: 2
2 2
1-3: 3 3
1 4
4-2: 4 2 4
1 4
4-3: 2
5
5-2: 1 3
5-3: 4 5
Heuristic - Farthest insertion (FI)
Step 3: Node 3 is selected arbitrary.

)Selection(
2 3 3
1-2: 2
2 2
1-3: 3 3
1 4
4-2: 4 2 4
1 4
4-3: 2
5
5-2: 1 3
5-3: 4 5
Heuristic - Farthest insertion (FI)
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(
2 3 3
3=3+2-2 :1-3-4
2 2
3
1 4
4
2 4
1
5
3
5
Heuristic - Farthest insertion (FI)
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(
2 3 3
3=3+2-2 :1-3-4
2 2
1=2+4-5 :4-3-5
3
1 4
2 4
1 4
5
3
5
Heuristic - Farthest insertion (FI)
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(
2 3 3
3=3+2-2 :1-3-4
2 3
1=2+4-5 :4-3-5 2

4=4+3-3 :5-3-1 1
4
4
2 4
1
5
3
5
Heuristic - Farthest insertion (FI)
Step 4: Insert Node 3 between Node 4 and Node 5 with the minimal
increasing cost c(4,3,5)=1

)Insertion(
Tour: 1-4-3-5-1
2 3 3
3=3+2-2 :1-3-4 Total cost = 6+4+1=11
2 2
1=2+4-5 :4-3-5 c(1,5)=6 3
4=4+3-3 :5-3-1 1 4
c(1,4,5)=4 2 4
1 4
c(4,3,5)=1
5
3
5
Heuristic - Farthest insertion (FI)

Step 3: Node 2 is the only choice, so Node 2 is selected.

)Selection(

Only Node 2 can be selected


2 3 3
2 2
3
1 4
2 4
1 4
5
3
5
Heuristic - Farthest insertion (FI)
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(
2 3 3
1-2-4: 2+4-2=4
4 2
2
3
1 4
2 4
1
5
3
5
Heuristic - Farthest insertion (FI)
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(
2 3
3
1-2-4: 2+4-2=4
2
4-2-3: 4+3-2=5 4 2
3
1 4
2 4
1
5
3
5
Heuristic - Farthest insertion (FI)
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(
3
2 3
1-2-4: 2+4-2=4
2
4-2-3: 4+3-2=5 2
3
3-2-5: 3+1-4=0 1 4
2 4
1 4
5
3
5
Heuristic - Farthest insertion (FI)
Step 4: Insert the selected node between two nodes of the subtour to
minimize the cost.

)Insertion(
2 3 3
1-2-4: 2+4-2=4
4-2-3: 4+3-2=5 2 2
3
3-2-5: 3+1-4=0 1 4
2 4
5-2-1: 1+2-3=0 1 4
5
3
5
Heuristic - Farthest insertion (FI)
Step 4: Insert Node 2 between Node 5 and Node 1 with the minimal
increasing cost c(5,2,1)=0

)Insertion(
Tour: 1-4-3-5-2-1
arbitrary choose one 2 3 3
Total cost = 6+4+1+0=11
1-2-4: 2+4-2=4
2 2
4-2-3: 4+3-2=5 c(1,5)=6 3
1 4
3-2-5: 3+1-4=0 c(1,4,5)=4 2 4
1
5-2-1: 1+2-3=0 c(4,3,5)=1
4
5
c(5,2,1)=0
3
5

Step 5: Stop.
()CIHeuristic - Cheapest insertion

Cheapest insertion for TSP


1. Start with a subgraph consisting of node i only.

2. Find node k such that cik is minimal and form the subtour i-k-i

3. (Selection) Given a subtour, find node k not in the subtour


with minimal cost in the tour.

4. (Insertion) Find the arc(i, j) in the subtour which


minimizes
cik+ckj-cij Insert k between i and j.

5. Go to step3 unless we have a Hamiltonian cycle.


Heuristic - Cheapest insertion (CI)
Step 1: Suppose node 1 is chose as beginning.
Step 2: The node 4 is selected such that subtour with minimal cost c(1,4)=4

2 3 3 2 3 3
2 2
2 3 4 2 3
1 4
1 4 2
4
2 4 1 42
1
5
5 3
3
Tour: 1-4-1
5
5 c(1,4)=4
()CIHeuristic - Cheapest insertion
Step 3: Find node k and insert it between node i and j in the subtour,
such that the insertion cost is minimal, where k{2,3,5}.
3
2 3
)Insertion Cost( 2 44 2
Insert node 2 into arc(1,4)
3
4 with the increasing cost = 4
1-2-4: 2+4-2=4 1
1
2
2 4
5
3

5
()CIHeuristic - Cheapest insertion
Step 3: Testing every enumeration.

3 3 3 3
2 3 2 3 2
)Insertion Cost( 2 3
4 2
2 3 4 2 2 3 4 2
4 4
1-2-4: 2+4-2=4 1
1
2
2 4 4 1
1
2
2 4 1
1
2
2 4
1-3-4: 3+2-2=3 3
5
3
5
3
5

1-5-4: 3+5-2=6 5 5 5

2 3 3 2 3 3 2 3 3
4-2-1: 4+2-2=4 2 3 4
4
2 2 3 4
4
2 2 3 4
4
2
1 1 1
4-3-1: 2+3-2=3 1 2
2
4 1 2
2
4 1 2
2
4
5 5 5
4-5-1: 5+3-2=6 3 3 3

5 5 5
Heuristic - Cheapest insertion )CI(
Step 4: Node 3 is inserted into arc(1, 4) with the minimal insertion
cost=3
3
2 3
2 3 4 2
Tour: 1-3-4-1 1 4
1 2
2 4
Total cost = 4+3=7 5
Current route 3

c(1,4)=4 5

c(1,3,4)=3
Heuristic - Cheapest insertion )CI(
Step 3: Find node k and insert it between node i and j in the subtour,
such that the insertion cost is minimal, where k{2,5}.
3
2 3
)Insertion Cost( 2 3 4 2
4
3-2-4: 3+4-2=5 1
1
2 4
3
5 Insert node 2 into
5 arc(3, 4) with the
increasing cost=5
Heuristic - Cheapest insertion )CI(
Step 3: Testing every enumeration.

3 3 3 3
2 3 2 3 2
)Insertion Cost( 2 3
4 2
2 3 4 2 2 3 4 2
4 4
1-2-3: 2+3-3=2 1
1
2
4
4 1
1
2 4 1
1
2 4
3-2-4: 3+4-2=5 3
5
3
5
3
5

4-2-1: 4+2-2=4 5 5 5

2 3 3 2 3 3 2 3 3
1-5-3: 3+4-3=4 2 3 4
4
2 2 3 4
4
2 2 3 4
4
2
1 1 1
3-5-4: 4+5-2=7 1 2 4 1 2 4 1 2 4
5 5 5
4-5-1: 5+3-2=6 3 3 3

5 5 5
Heuristic - Cheapest insertion )CI(
Step 4: Node 2 is inserted into arc(1, 3) with the minimal insertion
cost=2
3
2 3
2 2
3
Tour: 1-2-3-4-1 4 4
1
Total cost = 4+3+2=9 1 2 4
5
3
c(1,4)=4
c(1,3,4)=3 5

c(1,2,3)=2
()CIHeuristic - Cheapest insertion
Step 3: Find an arc(i, j) in the subtour, which has the minimal insertion
cost after inserting node 5.
3
2 3
)Insertion Cost(
2 2
3
1-5-2: 3+1-2=2 1 4 4
2 4
1
5
3

5
Insert node 5 into arc(1, 2)
with the increasing cost=2
Heuristic - Cheapest insertion )CI(

Step 3: Testing every enumeration.

3 3
2 3 2 3
)Insertion Cost( 2 2
3 4 2 3 2
1-5-2: 3+1-2=2 1 4 4 1 4
2 4 2 4
1 1
5 5
2-5-3: 1+4-3=2 3 3

5 5
2 3 3 2 3 3
4-5-3: 5+3-2=6 2 3 4 2 2
3 4 2

1 4 1 4
2 4 2 4
1 1
3-5-4: 4+5-2=7 5 5
3 3

5 5
()CIHeuristic - Cheapest insertion
Step 4: Node 5 is inserted into arc(1, 2) with the minimal insertion
cost=2

Tour: 1-5-2-3-4-1 2 3 3
Total cost = 4+3+2+2=11
2 3 4 2
c(1,4)=4 1 4
2 4
c(1,3,4)=3 1
5
c(1,2,3)=2 3

c(1,5,2)=2 5
Thank You

You might also like