Anda di halaman 1dari 5

Nama: Sadam Zuan Nopandra

NPM: 213510479

Kelas: 4D

Mencari elemen terbesar

max = array[0]

for i = 1 to n-1

if array[i] > max

max = array[i]

end if

end for

print max

Kompleksitas waktu: O(n)

Pencarian beruntun (sequential search)

for i = 0 to n-1

if array[i] == target

print "Target ditemukan di indeks ", i

break

end if

end for

if target tidak ditemukan

print "Target tidak ditemukan"

Kompleksitas waktu: O(n)

Menghitung nilai pangkat

result = 1

for i = 1 to b

result *= a
end for

print result

Kompleksitas waktu: O(b)

Mengalikan 2 buah matriks

Pseudocode:

css

Copy code

for i = 0 to r1-1

for j = 0 to c2-1

temp = 0

for k = 0 to c1-1

temp += mat1[i][k] * mat2[k][j]

end for

hasil[i][j] = temp

end for

end for

print hasil

Kompleksitas waktu: O(r1c2c1)

Bubble Sort dan Selection Sort

Pseudocode Selection Sort:

for i = 0 to n-2

minIndex = i

for j = i+1 to n-1

if array[j] < array[minIndex]

minIndex = j

end if

end for
swap(array[i], array[minIndex])

end for

print array

1.

2.

3.
4.
5.

Anda mungkin juga menyukai