Title: Data Structures for dealing with permutations
1Data Structures for dealing with permutations
- Based on a paper by Fredman, Johnson, McGeoch and
Ostheimer
2Talk Outline
- We Define the TSP problem and consider the 2-opt
algorithm - We present the modified splay tree an
interesting DS for implementing 2-opt. - We show the connection to another problem on
permutations
3TSP is cool
Taken from the TSP Homepage
4TSP Of Ireland
Taken from the TSP Homepage
5TSP
- Given a complete graph with weights on the edges,
find a minimum-weight hamiltonian tour - A tour can be viewed as a
- permutation of the vertices
6Local Improvement Heuristics
- A nice approach to get a heuristic is to use
local improvements - Start with a random tour
- Repeatedly find a local improvement, and perform
it - Return the tour when there are no more local
improvements
7A 2-move
- (a, v1,v2,,vi,c,d,u1,,uj,b)
- (a, v1,v2,,vi,c,b,uj,uj-1,,u1,d)
82-opt
- Repeatedly performing 2-moves is called the 2-opt
heuristic. - What is its running time?
- O(nlogn) for producing the first tour
- O(1) to draw a random improvement and check if it
is good - O(n) for generating the new tour
9Requirements from the DS
- Operations we want to perform
- Reverse part of the permutation
- Return the successor of an element in the
permutation
10Data Structure for holding the tour
- Tour in linked list performing a 2-move is
easy. Accessing the vertices is hard. - Tour in array Access is easy, performing a
2-move is hard. - Solution Hold the tour in the nodes of a
balanced search tree!
11The Modified Splay Tree
- Each node of the tree can be marked as flipped
- The tour is an in-order traversal of the tree,
altered by the flipped markers
IFJCG A DHBE
12Requirements from the DS
- Operations we want to perform
- Reverse part of the permutation
- Return the successor of an element in the
permutation - op 2 is trivially done in O(logn) in a balanced
search tree (even with flipped markers) - op 1 can be done in O(logn) time if we use AVL
trees or splay trees
13(No Transcript)
14Splay Trees
- Invented by Sleator Tarjan
- Support
- Search
- Insert, Delete
- Splitting and Concatenation
- all in logarithmic amortized time
15Splay Trees
- To perform an operation on an element we first
splay it. - Splaying a node Performing (composite) rotations
until it gets to the root - Rotations
x
y
x
y
A
C
B
C
A
B
16Splay Trees With flipped markers
- Observe that we can push the
- flipped markers down
A
B
B
A
So, before performing any operation (even
rotation) just push the markers down, and were
O.K.
17Reversing a Segment
x
- If we want to reverse between x and y (non
inclusive) - Splay y
- Splay x
- Then we can do the flip using O(1) operations
y
A
B
C
x
y
A
B
C
18Signed Sorting by reversals
Given a signed permutation, find a shortest
sequence of reversals that transforms it to (1
2 n)
(
-
-
-
(3 4 -2 -5 1)
3
4
2
5
1)
19Example
- (3 4 -2 -5 1)
- (-4 -3 -2 -5 1)
- (-4 -3 -2 -1 5)
- ( 1 2 3 4 5)
20In SBR
- We want to maintain a (signed) permutation under
reversals this is the Modified Splay Tree (with
signs) - More involved version We want to actually solve
the problem. We maintain some reversals in a
similar, but more involved, way.
21Conclusions
- We showed a Data Structure for holding
permutations under reversals that is usefull both
for TSP and for SBR - The idea of the flipped markers has further
uses.