Posts Tagged ‘Algoritma’

algoritma deret fibonacci

nih mumpung masih hangat, salah satu algoritma deret fibonacci :
flowchart :

contoh program :

$limit = 10;
$fibonacci = "";
for($i=1;$i<=$limit;$i++){
if($i == 1){
$value[$i]=1;
}else{
$value[$i]=$value[$i-2] + $value[$i-1];
}
$fibonacci .= $value[$i]." ";
}
echo $fibonacci;

output :
1 1 2 3 5 8 13 21 34 55

Bookmarks:

Bookmarks:
  • Facebook
  • Google Bookmarks
  • Digg
  • LinkedIn
  • Twitter
Read the rest of this entry »

algoritma segi tiga pascal

mumpung masih hangat, berikut ini salah satu contoh algoritma segitiga pascal beserta contoh codingnya di php
flowchart :

contoh program :

$limit = 6;
$pascal = "";
for($i=1;$i<=$limit;$i++){
for($j=1;<=$i;$j++){
if($j==1 || $j==$i){
$value[$i][$j] = 1;
}else{
$value[$i][$j] = $value[$i-1][$j] + $value[$i-1][$j-1];
}
$pascal .= $value[$i][$j]." ";
}
$pascal .= "
\n";
}
echo $pascal;

output :

Bookmarks:

Bookmarks:
  • Facebook
  • Google Bookmarks
  • Digg
  • LinkedIn
  • Twitter
Read the rest of this entry »

linked list

hitung jumlah simpul :

Q = FIRST;
Jum = 1;
while (Q != LAST)
{ Q = Q-&gt;LINK;
Jum = Jum + 1;
}
printf("%i", JUM);

atau

Q = FIRST;
Jum = 1;
while (Q-&gt;LINK != NULL)
{ Q = Q-&gt;LINK;
Jum = Jum + 1;
}
printf("%i", JUM);

atau

Q = FIRST;
Jum = 0;
while (Q [...]

Bookmarks:
  • Facebook
  • Google Bookmarks
  • Digg
  • LinkedIn
  • Twitter
Read the rest of this entry »

double ended queue

ciri2 double ended queue :

kosong : L = R + 1
penuh kanan : R = n – 1
penuh kiri : L = 0
penuh kanan dan kiri : R = n – 1 && L = 0
bisa diisi dari kanan : R < n
bisa diisi dari kiri : L > 0
ada isinya : L < R [...]

Bookmarks:
  • Facebook
  • Google Bookmarks
  • Digg
  • LinkedIn
  • Twitter
Read the rest of this entry »

circular queue

ciri2 circular queue :

kosong : counter = 0
penuh : counter = n
bisa diisi : counter < n
ada isinya : counter > 0

kondisi awal :

f = 0;
r = -1;
counter = 0;

algoritma dasar circular queue :

INSERT

R = (R+1) % n;
Q[R] = X;
Counter++;

DELETE

X = Q[F];
[...]

Bookmarks:
  • Facebook
  • Google Bookmarks
  • Digg
  • LinkedIn
  • Twitter
Read the rest of this entry »

double stack

ciri2 double stack :

stack 1 kosong : top1 = -1
stack 2 kosong : top2 = n
stack penuh (stack 1 dan stack 2 tidak bisa diisi) : top2 – top1 = 1
stack bisa diisi (stack 1 dan stack 2 tidak bisa diisi) : top2 – top1 > 1
stack 1 ada isinya : top1 > -1
stack 2 [...]

Bookmarks:
  • Facebook
  • Google Bookmarks
  • Digg
  • LinkedIn
  • Twitter
Read the rest of this entry »