Mencari Kompleksitas Waktu Tmin, Tmax dan Tavg
1. Procedure Beberapa_Bil_Genap ( input n = integer; output x = integer)
Kamus
x = integer
n = integer
Algoritma
Input(n)
x := 1
while x <= n do
if (x mod 2) = 0 then
output(x)
x := x + 1
endif
endwhile
-------------------------------------------------------------------------------------------------------
output
Tmin = 1
Tmax = n
Tavg = (1+2+3+...+n)/n = 1/2(n(n+1) = (n+1)/2
2. Program Beberapa_Bil_Ganjil
Kamus
a = integer
Algoritma
a := 1
repeat
if (a mod 2) = 1
output(a)
a := a + 1
endif
until a = 20
-------------------------------------------------------------------------------------------------------
output
Tmin = 1
Tmax = n
Tavg = (1+2+3+...+n)/n = 1/2(n(n+1) = (n+1)/2
3.
Procedure Tampilkan_derat_angka(input baris = integer, kolom = integer;
output baris = integer)
Algoritma
Input (baris,kolom)
Akhir := 4
for baris := 1 to akhir do
for kolom := 1 to baris do
output(baris);
endfor
for baris := 1 to akhir do
for kolom := 1 to baris do
output(baris);
endfor
Endfor
-------------------------------------------------------------------------------------------------------
output
Tmin = 1
Tmax = n
Tavg = (1+2+3+...+n)/n = 1/2(n(n+1) = (n+1)/2
4.
Procedure
CariMaks (input a1,a2,...,an
: integer, output maks : integer)
Kamus
i, n : integer
Algoritma
input(n)
i := 1
While i <= n do
If ai > maks then
maks := ai
endif
i := i +1
endwhile
-------------------------------------------------------------------------------------------------------
>
Tmin = 1
Tmax = n
Tavg = (1+2+3+...+n)/n = 1/2(n(n+1) = (n+1)/2
5. Procedure Menentukan_JumBil
(input y : integer; output jumlah : real)
Kamus
x = integer
Algoritma
Input (y)
x := 1
for x := 1 to y do
Jumlah := Jumlah
+ x
endfor
Output (Jumlah)
-------------------------------------------------------------------------------------------------------
+
Tmin = 1
Tmax = n
Tavg = (1+2+3+...+n)/n = 1/2(n(n+1) = (n+1)/2
Tidak ada komentar:
Posting Komentar