7224066-Algorithmic-Problem-Solving-by-Roland-Backhouse.pdf
February 14, 2017 | Author: מוחמד טאהא | Category: N/A
Short Description
problem solving using an algorthims...
Description
Contents 1 Introduction 2 Invariants " " # % & ' " "
( " ) %' *
3 Crossing a River + ,
-. / %' 0 - 1 " 2 3 " ( 3 ) 4 ( . 5 )
&
1 5 ! ! $ ) $ 21
) * ! ! $ ( ) $
4 Games ( # , ( - ( ( 6 ( + 5 ( / , (( . , (( &
& (( 7 8 &
9 (( # ((( " #%: + (() ; #%: + ()
& (*
5 Knights and Knaves ) 6 & 5 5 +4 " ? "
9 Knight’s Circuit $ /# $ 5 $ $( 3 $) . > . .& & + 4 % . + ' & 6
4 4 Abstraction " & 4 - p
. 4 c
. " . . " A
- K L . . G K LH & . 8 > . & 4
9 " & & "
5& 4 . . " K L .
K/4L /4 & . I
& & & > 5 .
&
' 4 .
" ./ &
& " . & 4 . 4
" & & S0 5 S1 S2 S3 { 3C || } S1 { 3H || 3W } , { 3H || 3W } S2 { 3W || 3H } ,
{ 3W || 3H } S3 { || 3C } .
" 5 S1 . 4 4 . " 5 S2 . S1 4 . 4 +& 5 S3 . S2 4 & S1 .4 & S2 .4 & S3 4 4 & S1 ; S2 ; S3 4 D . . G& . H A G& H " 4 4 ' &
&
&
. 4 & &
& &
. . S3 & &
. . S1 8. 4 . S3 . 4 . . . 4 S1 S3 & . - 4 . S1 S2 4 . & G8 & . . &H = 4
{
3C ||
}
1C,2H |2W| ;
{
1C,2H || 2W
}
1C,2H |1W| 1W ;
{
2C,1H || 1W
}
3H |2W| 1W {
3H || 3W
} .
" { 3C || } 1C,2H |2W| ; 1C,2H |1W| 1W ; 3H |2W| 1W
{ 3H || 3W } .
5 S3 . S1 J {
3W || 3H
}
1W |2W| 3H ;
{
1W || 2C,1H }
1W |1W| 1C,2H ;
{
2W || 1C,2H }
|2W| 1C,2H {
|| 3C
}
.
- 4 . 4 . S2 - &
? . S2 . A . " 5 . S2 .4 S1 .4 & S3 " . S2 4 . 5 8. &
& .4 . J {
3H || 3W
}
T1 ;
1C |1C| 1C
;
T2 {
3W || 3H
} .
$
? & C 1C |1C| 1C C " & .// //. I 4
& " 4 &
5 . T1 T2 8. . . & 1C || 2C 2C || 1C @/ . . . & 2C || 1C 1C || 2C " /. & 4 +& T1 8 . D 4 J {
3H || 3W
}
3H |1W| 2W ;
{
1C,2H || 2W
}
1C |2H| 2W {
1C || 2C }
.
&
& . T2 4 J {
2C || 1C }
2W |2H| 1C ;
{
2W || 1C,2H }
2W |1W| 3H {
3W || 3H
} .
+& & 4 D/ J {
3C ||
}
1C,2H |2W| ; 1C,2H |1W| 1W ; 3H |2W| 1W ;
{
3H || 3W
}
3H |1W| 2W ; 1C |2H| 2W ;
{
1C || 2C }
1C |1C| 1C ;
{
2C || 1C }
2W |2H| 1C ; 2W |1W| 3H
(
;
{
3W || 3H
}
1W |2W| 3H ; 1W |1W| 1C,2H ; |2W| 1C,2H {
|| 3C
}
.
G8 4 " & & "
H
3.3.5
A Review
4 4 D/ & .& 4 F /. " ' &
& 4 .
. 4 & / 5 4 A K L ? 4 5 . & .& . { p } S { q } .& 4 " A " 1 & . &
& 4 &
. & # ' + . . .4 J Exercise 3.1 (Five-couple Problem) " A D & ' . 3 4 2 Exercise 3.2 (Four-couple Problem) ;.& &
& 4 . & / &
" . D & '/ . &
3 " .4 & . + A & 4 & 4 . A G' H &
.& . A . . B A 4 4& . & .
% &'
)
G8 &
. &
" . . . &
. . .H 2 Exercise 3.3 4 . ' . 4 . 4 . ' . ' =J " J
. . " & 2
3.4
Rule of Sequential Composition
" { p } S { q } 4 . D/ . .& 8 !
G "& = 4 5 . . & .& . I 4 . A H A & 4 " 4 A & / p A & q . 8. S p q .
pSq
. .& & p . ' . S ' . S .4 4 .& & q + ' r d .
M &
N 4 N = 0 ,
*
G & 0 4H M = N×d + r ∧ 0 ≤ r < N .
8. S A . { N = 0 } S { M = N×d + r ∧ 0 ≤ r < N } .
. & 5I ' . & 5 " . S1 S2 S3 S1 ; S2 ; S3 ' & A ' S1 ' S2 ' S3 " " . S1 S2 S3 5 4 8 . 4 p q r & " . S .& A
pSq & S S1 ; S2 S1 S2 .& A
pS r 1
rS q 2
.
" r . S1 . S2 8. 4 " 4 4 D/ "
3C || || 3C " 3H || 3W 3W || 3H 4 A " F 4& . . 5 " . & & & S1 I .& A S2 & & A S2 I . .& r S1 J
% &'
+ 4 8 & 4 & & 4 " 4 & 4 & " . F . I 4 4 & . 4 " A 1 2 5 . 10 " . . 4& 4 4 . 4 17 8 & A . " A 4 4 4 4 4 4 & 4 . 4 & 4 4 D& " 5 4 & & " ' 4 4 4 G8 1 4& & 4 4 ' (H ; A . 4 . . p q . .
p |5,10| q
' &
& . 5 . S1 S2 p q { 1,2,5,10 || } S1 { p,5,10 || q } { p,5,10 || q } p |5,10| q { p || q,5,10 }
{ p || q,5,10 } S2 { || 1,2,5,10 } .
- & Exercise 3.4 (The Torch Problem) . . . A t1 t2 t3 . t4 t1 ≤ t2 ≤ t3 ≤ t4 + . .
B & & .4 4 & & & .4 4 J
!
(a) " 1 1 3 3 (b) " 1 4 4 5
=J 8 A G4 t1 t2 t3 t4 1 2 5 10 &H & 4 4 =4 1 4& & & . & . B 4 . 4 . 8 & 4 .4 G? GH G H 4 & H (a) =4 & . 2 G8 H =4 & . 2 (b)
. D& 4
. 4 & &
. 4 2 - . . 4 & 2 G, & H
(c) ?4 . 4 4
- F 2 % . = . . . (d) , ; 4 &
? ' A " D & & 4 & " 4 .& 4 4 5 2 Exercise 3.5 /. G' ( H " 4 F 4& . . =4 & 4& 2 2
& (
3.5
$
Summary
8 4 /. 4 /. & # &
. / / ' . 4 4. '& & 4 & 4 & . I 4
. & 4 L " 4 '
. K>L F . '
. KL " G 3 2 H 4 & KL 4 '
K>L " . 4 '
F . 2 " A & & . '
5 & . ? . . . 4 15 . . 11 . '
. 8 . 4
& % )
*
0
+ (J
1
4
5
'
" '
2
26 F D G . 4H . 15 11 165 " F # 4
View more...
Comments