Transition system Definition 1.3.1 A transition system S is a pair of the form S ( C , T = ) where C is the set of configurations and T � C � C is a relation, the transition relation . � Algorithms and Data Structures Chapter 1: Transition Systems 1
Sequences generated by a transition system Definition 1.3.3 Let S ( C , T ) be a transition system. S generates a = ( S set of sequences , S ) , defined as follows: 1. the finite sequence c 0 , c 1 , . . . , c n (for n � 0) belongs to S ( S ) if ( ι ) c 0 2 C ( ιι ) for all i with 1 � i � n : ( c i � 1 , c i 2 T ) 2. the infinite sequence c 0 , c 1 , . . . , c n , . . . belongs to ( S S ) if ( ι ) c 0 2 C ( ιι ) for all i � 1: ( c i � 1 , c i 2 T ) � Algorithms and Data Structures Chapter 1: Transition Systems 2
Processes generated by a transition system Definition 1.3.5 Let S ( C , T ) be a transition system. The set of = processes generated by S , written P ( S ) , is the subset of S ( S ) containing 1. all infinite sequences of S ( S ) 2. all finite sequences c 0 , c 1 , . . . , c n ( n � 0 ) of S ( S ) for which it holds that there is no c 2 C with ( c n , c 2 T . ) The final configuration of a finite process is called a dead configuration . � Algorithms and Data Structures Chapter 1: Transition Systems 3
Football Transition system F o otball Configurations: f [ t , X , a , b j 0 � t � 90, X 2 f A , B , R g , a , b 2 N g ℄ [ t , A , a , b [ t + 2, B , a , b if t � 88 ℄ ℄ � [ t , A , a , b [ t + 2, B , a + 1, b ℄ if t � 88 ℄ � [ t , A , a , b [ t + 1, B , a , b if t � 89 ℄ ℄ � [ t , A , a , b [ t + 1, B , a + 1, b ℄ if t � 89 ℄ � [ 90, A , a , b [ 90, R , a , b ℄ ℄ � [ t , B , a , b [ t + 2, A , a , b if t � 88 ℄ ℄ � [ t , B , a , b [ t + 2, A , a , b + 1 ℄ if t � 88 ℄ � [ t , B , a , b [ t + 1, A , a , b if t � 89 ℄ ℄ � [ t , B , a , b [ t + 1, A , a , b ℄ if t + 1 � 89 ℄ � [ 90, B , a , b [ 90, R , a , b ℄ ℄ � Algorithms and Data Structures Chapter 1: Transition Systems 4
Induction principle Induction principle Let P ( 0 ) , P ( 1 ) , . . . , P ( n ) , . . . be statements. If a) P ( 0 ) is true b) for all n � 0 it holds that P ( n ) implies P ( n + 1 ) , then P ( n ) is true for all n � 0. Algorithms and Data Structures Chapter 1: Transition Systems 5
Invariance principle Invariance principle for transition systems Let S ( C , T ) be a tran- = sition system and let c 0 2 C be a configuration. If I ( c ) is a statement about the configurations of the system, the following holds. If a) I ( c 0 ) is true b) for all ( c , c 2 T it holds that I ( c ) implies I ( c 0 0 ) ) then I ( c ) is true for any configuration c that occurs in a sequence starting with c 0 . Algorithms and Data Structures Chapter 1: Transition Systems 6
Termination principle Termination principle for transition systems Let S ( C , T ) be a = transition system and let µ : C ! N be a function. If 0 0 for all ( c , c 2 T it holds that µ ( c > µ ( c ) ) ) then all processes in P ( S ) are finite. Algorithms and Data Structures Chapter 1: Transition Systems 7
Nim Transition system Nim f A , B Configurations: g � N [ A , n [ B , n � 2 ℄ if n � 2 ℄ � [ A , n [ B , n � 1 ℄ if n � 1 ℄ � [ B , n [ A , n � 2 ℄ if n � 2 ℄ � [ B , n [ A , n � 1 ℄ if n � 1 ℄ � Algorithms and Data Structures Chapter 1: Transition Systems 8
Towers of Hanoi Transition system ( n Hanoi ) Configurations: f [ A , B , C j f A , B , C g a partition of f 1, . . . , n g g ℄ [ A , B , C [ A n f r g , B [ f r g , C ℄ if ( r = min A ^ ( r < min B ℄ ) ) � [ A , B , C [ A n f r g , B , C [ f r g ℄ if ( r = min A ^ ( r < min C ℄ ) ) � [ A , B , C [ A [ f r g , B n f r g , C ℄ if ( r = min B ^ ( r < min A ℄ ) ) � [ A , B , C [ A , B n f r g , C [ f r g ℄ if ( r = min B ^ ( r < min C ℄ ) ) � [ A , B , C [ A f r g , B , C f r ( r = min C ( r < min A [ n g ℄ if ^ ℄ ) ) � [ A , B , C [ A , B f r g , C f r ( r = min C ( r < min B [ n g ℄ if ^ ℄ ) ) � Algorithms and Data Structures Chapter 1: Transition Systems 9
Euclid’s algorithm Transition system Eu lid Configurations: f [ m , n j m , n � 1 g ℄ [ m , n [ m � n , n if m > n ℄ ℄ � [ m , n [ m , n � m ℄ if m < n ℄ � Algorithms and Data Structures Chapter 1: Transition Systems 10
Expressions Transition system Exp ressions Configurations: f 0, 1, + , E , T , ( , g � ) α E β � α T β α E β � α T + E β � α 0 β α T β α T β � α 1 β α T β ( E � α ) β Algorithms and Data Structures Chapter 1: Transition Systems 11
Expressions (context-free) Transition system Exp ressions Configurations: f 0, 1, + , E , T , ( , g � ) E � T , T + E T � 0, 1, ( E ) Algorithms and Data Structures Chapter 1: Transition Systems 12
Graph coloring Transition system GraphColo ring Configurations: Danish graphs � � if there are no pink nodes � Algorithms and Data Structures Chapter 1: Transition Systems 13
Red-black tree Definition 1.5.7 A red-black tree is binary search tree in which all internal nodes are colored either red or black, in which the leaves are black, and Invariant I 2 Each red node has a black parent. Invariant I 3 There is the same number of black nodes on all paths from the root to a leaf. � 3 2 9 5 13 7 11 17 Algorithms and Data Structures Chapter 1: Transition Systems 14
Insertion Illegitimate red node: x Invariant I 2 : Each legitimate red node has a black parent. 0 Algorithms and Data Structures Chapter 1: Transition Systems 15
Insertion: transitions 1 and 2 The illegitimate node is the root of the tree: x x � 1 2 1 2 The illegitimate node has a black father: A A x x � 3 3 1 2 1 2 Algorithms and Data Structures Chapter 1: Transition Systems 16
Insertion: transitions 3.1 and 3.2 The illegitimate node has a red father and a red uncle: A A B C B C � x x 3 4 5 3 4 5 1 2 1 2 A A B C B C � x x 1 4 5 1 4 5 2 3 2 3 Algorithms and Data Structures Chapter 1: Transition Systems 17
Insertion: transitions 4.1 and 4.2 The illegitimate node has a red father and a black uncle: A B x B C A � x C 3 4 5 1 2 3 1 2 4 5 x A B C B A � x C 1 4 5 1 2 3 2 3 4 5 Algorithms and Data Structures Chapter 1: Transition Systems 18
Deletion Illegitimate black node: Invariant I 1 The tree satisfies I 1 if we remove the illegitimate node. 0 Invariant I 2 Each red node has a legitimate black father. 0 Algorithms and Data Structures Chapter 1: Transition Systems 19
Deletion: transition 1 The illegitimate node is the root: � Algorithms and Data Structures Chapter 1: Transition Systems 20
Deletion: transitions 2 and 3 The illegitimate node has a red father and a red closer nephew: A C B A B � C 1 4 1 2 3 4 2 3 The illegitimate node has a red father and a black closer nephew: A B B A 4 � C C 1 4 1 2 3 2 3 Algorithms and Data Structures Chapter 1: Transition Systems 21
Deletion: transitions 4.1 and 4.2 The illegitimate node has a black father, a black sibling and one red nephew: A C B A B � C 1 4 1 2 3 4 2 3 A B B A C � C 1 2 1 2 3 4 3 4 Algorithms and Data Structures Chapter 1: Transition Systems 22
Deletion: transition 5 The illegitimate node has a black father, a black sibling and two black nephews A A B B � 1 C D 1 C D 2 3 4 5 2 3 4 5 Algorithms and Data Structures Chapter 1: Transition Systems 23
Deletion: transition 6 The illegitimate node has a black father and a red sibling: B A A 3 B � 2 1 2 3 1 Algorithms and Data Structures Chapter 1: Transition Systems 24
The transition system Commands Transition system Commands [ C , σ ℄ Configurations: j C a command-sequence, σ a state f g [ x 0 , σ ℄ [ C 0 , σ ℄ e ; C h x : e � i [ 0 , σ ℄ [ C 1 ; C 0 , σ ℄ ( b ) = if if if b then then then C 1 else else C 2 ; C else if σ true � [ 0 , σ ℄ [ C 2 ; C 0 , σ ℄ ( b ) = if if if b then then then C 1 else else C 2 ; C else if σ false � [ while while b do do C ; C 0 , σ ℄ [ C ; while while b do do C ; C 0 , σ ℄ if σ ( b ) = while do while do true � [ ℄ [ C ℄ ( b ) = while b while do do C ; C 0 , σ 0 , σ while do if σ false � Algorithms and Data Structures Chapter 2: Algorithm Theory 25
6 Euclid’s algorithm ( m , n ) Algorithm Eu lid Input : m , n � 1 = gcd ( m 0 , n 0 ) Output : r = n Method : while while m do while do do if if m > n then if then then m m � n else else else n n � m ; r m Algorithms and Data Structures Chapter 2: Algorithm Theory 26
Execution of Euclid(72,45) Step# Action State# m n r 0 72 45 1 m<>n 1 72 45 2 m > n 2 72 45 3 m <– m-n 3 27 45 4 m<>n 4 27 45 5 m > n 5 27 45 6 n <– n-m 6 27 18 7 m<>n 7 27 18 8 m > n 8 27 18 9 m <– m-n 9 9 18 10 m<>n 10 9 18 11 m > n 11 9 18 12 n <– n-m 12 9 9 13 m<>n 13 9 9 14 r <– m 14 9 9 9
Recommend
More recommend