STRATEGI ALGORITMA
SELECTION
1. c + max(p1,p2)
= 3 + max(1,0)
= 3 + 1
= 4
2. (akhir - awal + 2) + (akhir - awal + 1) (p + 1)
(n - 1 - i + 1 + 2) + (n - 1 - i + 1 + 1) (langkah 1 + 1)
(n - i + 2) + (n - i + 1) (4 + 1)
(n - i + 2) + (n - i + 1) (5)
(n - i + 2) + (5n - 5i + 5)
n - i + 2 + 5n - 5i + 5
6n - 6i + 7
3. (akhir - awal + 2) + (akhir - awal + 1) (p + 1)
(n - 2 - 0 + 2) + (n - 2 - 0 + 1) (1 + langkah 2 + 3 + 1)
(n) + (n - 1) (langkah 2 + 5)
(n) + (n - 1).5 + E(langkah 2)
n + 5n - 5 + (E(6n - 6i + 7))
6n - 5 + (E6n - E6i + E7)
6n - 5 + (6n2) - (6((n2 + n)/2)) + (7n)
6n2 + 20n - 10
O(n2)
----------------------------------------------------------------------------------------
BUBBLE
1. c + max(p1,p2)
= 4 + max(4,0)
= 4 + 4
= 8
2. (akhir - awal + 2) + (akhir - awal + 1) (p + 1)
(n - 2 - i - 0 + 2) + (n - 2 - i - 0 + 1) (8 + 1)
(n - i) + (n - 1 - i) (9)
(n - i) + (9n - 9 - 9i)
n - i + 9n - 9 - 9i
10n - 10i - 9
3. (akhir - awal + 2) + (akhir - awal + 1) (langkah 2 + 1)
(n - 2 - 0 + 2) + (n - 2 - 0 + 1).1 + E(langkah 2)
n + n - 1 + (E(10n - 10i - 9))
2n - 1 + (E10n - E10i + E9)
2n - 1 + (10n2) - (10((n2 + n)/2)) + (9n) --> X2 SMUA
10n2 + 12n - 2
O(n2)
------------------------------------------------------------------------------------------
SEQUENTIAL SEARCH
void lsearch(int list[],int n,int element)
{
int i, flag = 0;
for(i=0;i
{
printf(" Elemen yang dicari : %d ada di posisi %d\n",element,i);
flag =1;
break;
}
if( flag == 0)
printf("Elemen yang dicari : %d Tidak ada\n",element);
}
1. c + max(p1,p2)
= 2 + max(3,0)
= 2 + 3
= 5
2. (akhir - awal + 2) + (akhir - awal + 1) (p + 1)
(n - 1 - 0 + 2) + (n - 1 - 0 + 1) (langkah 1 + 1)
(n + 1) + (n) (5 + 1)
(n + 1) + (n) (6)
n + 1 + 6n
7n + 1
3. c + max(p1,p2)
= 1 + max(1,0)
= 1 + 1
= 2
4. langkah 2 + langkah 3
= 7n + 1 + 2
= 7n + 3
O(n)
--------------------------------------------------------------------------
MATRIK
1. (akhir - awal + 2) + (akhir - awal + 1) (p + 1)
(n - 1 + 2) + (n - 1 + 1) (18 + 1)
(n + 1) + (n) . 19
n + 1 + 19n
20n + 1
2. (akhir - awal + 2) + (akhir - awal + 1) (p + 1)
(n - 1 + 2) + (n - 1 + 1) (5 + langkah 1 + 1)
(n + 1) + (n) (langkah 1 + 6)
(n + 1) + (n) (20n + 1 + 6)
(n + 1) + (n) (20n + 7)
(n + 1) + 20n2 + 7n
20n2 + 8n + 1
3. (akhir - awal + 2) + (akhir - awal + 1) (p + 1)
(n - 1 + 2) + (n - 1 + 1) (langkah 2 + 1)
(n + 1) + (n) (20n2 + 8n + 1 + 1)
(n + 1) + 20n3 + 8n2 + 2n
20n3 + 8n2 + 3n + 1
O(n3)
----------------------------------------------------