3. X → Y
Possible solutions:
S1: Go by feet (walking)
S2: Go by bus
S3: Go by train
S4: Go by flight
….
….
Sn: There may be n solutions
3
4. X → Y
Possible solutions:
S1: Go by feet (walking)
S2: Go by bus
S3: Go by train
S4: Go by flight
….
….
Sn: There may be n solutions
Feasible solutions:
S3: Go by train
S4: Go by flight
8 hours
4
5. X → Y
Possible solutions:
S1: Go by feet (walking)
S2: Go by bus
S3: Go by train
S4: Go by flight
….
….
Sn: There may be n solutions
Feasible solutions:
S3: Go by train
S4: Go by flight
Optimal Solution:
S3: Go by train (Costs less)
5
6. Optimal merge pattern
A B
3 5
8 9
12 11
20 16
C
3
5
8
9
11
12
16
20
m n
4 4
Complexity: ϴ(m+n) = 8
6
7. List A B C D
Size 6 5 2 3
A
6
B
5
C
2
D
3
11
13
16
Cost = 11+13+16 = 40
7
8. List A B C D
Size 6 5 2 3
A
6
B
5
C
2
D
3
11 5
16
Cost = 11+5+16 = 32
8
9. List A B C D
Size 6 5 2 3
A
6
B
5
C
2
D
3
16
10
5
Cost = 5+10+16 = 31
9
10. List A B C D E
Size 6 5 2 3 7
C
2
D
3
B
5
A
6
E
7
Sorted in ascending order
10
11. List A B C D E
Size 6 5 2 3 7
C
2
D
3
B
5
A
6
E
7
5
10
23
13
11
12. List A B C D E
Size 6 5 2 3 7
C
2
D
3
B
5
A
6
Cost
5+10+13+23 = 51
E
7
5
10
23
13
2*3+3*3+5*2+6*2+7*2 = 51
12