Вы находитесь на странице: 1из 3

Nama:I Wayan Boby Ramayudha

Nim:1705552014
Matakuliah:Algorima
Kelas:TI Pararel A

1. Apply quicksort to sort the list E, X, A,M, P, L, E in alphabetical order.


Draw the tree of the recursive calls made.

2. Sort the list E, X, A, M, P, L, E in alphabetical order by selection sort.

3. Battleship game Write a program based on a version of brute-force pattern


matching for playing the game Battleship on the computer. The rules of the
game are as follows. There are two opponents in the game (in this case,
a human player and the computer). The game is played on two identical
boards (10 × 10 tables of squares) on which each opponent places his or her
ships, not seen by the opponent. Each player has five ships, each of which
occupies a certain number of squares on the board: a destroyer (two squares),
a submarine (three squares), a cruiser (three squares), a battleship (four
squares), and an aircraft carrier (five squares). Each ship is placed either
horizontally or vertically, with no two ships touching each other. The game
is played by the opponents taking turns “shooting” at each other’s ships. The result of
every shot is displayed as either a hit or a miss. In case of a hit, the
player gets to go again and keeps playing until missing. The goal is to sink all
the opponent’s ships before the opponent succeeds in doing it first. To sink a
ship, all squares occupied by the ship must be hit.
1. Apply quicksort to sort the list E, X, A,M, P, L, E in alphabetical order.
Draw the tree of the recursive calls made.
0 1 2 3 4 5 6
i j
E X A M P L E
j i
E E A M P L X
A E E M P L X
ij
A E
j i
A E
A E
E
i j
M P L X
i j
M P L X
i j
M L P X
j i
M L P X
L M P X
L

ij
P X
j i
P X
P X
X

l =l=0,
0, rr=6
=6
sS = 22

l = 0, r = 1 l = 3, r = 6
s=0 s=4

l = 0, r = -1 l =1, r = 1 l = 3, r = 3 l = 5, r = 6
s=5

l = 5, r = 4 l = 6, r = 6
2. Sort the list E, X, A, M, P, L, E in alphabetical order by selection sort.

E X A M P L E
A X E M P L E
A E X M P L E
A E E M P L X
A E E L P M X
A E E L M P X
A E E L M P X

3.

Вам также может понравиться