Anda di halaman 1dari 9

TUGAS MATA KULIAH

DESAIN DAN ANALISIS


ALGORITMA – 3 sks

SOAL

Sebagai seorang junior programmer, Saudara diminta untuk membuat


algoritma untuk menampilkan angka 1 s.d 10 dalam beberapa bentuk cara
dengan minimal 10 cara. Kemudian implementasikan algoritma-algoritma
tersebut dalam bahasa pemrograman yang diminati dengan penerapan pada
penampilan angka 1 s.d. 1.000. Berikan analisis dari rancangan algoritma
tersebut terkait penggunaan variable memori dan waktu. Penggunaan waktu
dicatat berasarkan lama waktu eksekusi sesuai penerapan pada Bahasa
program masing-masing untuk setiap algoritma yang di eksekusi.

JAWABAN

No. Algoritma Implementasi dengan Bahasa… Tampilan Hasil,Analisis


Memori
dan Waktu Eksekusi
1 Output 1 Import numpy as np
Output 2 From memory_profile rimport
Output 3 profile from time import time
Output 4
Output 5 now = time
Output 6 ()@ profile
Output 7 def number(): Analisis Memori :
Output 8 d=np.ones ((100,1000,1000)) 815.9 MiB Waktu
Output 9 for i in [1,2,3,4,5,6,7,8,9,10]: Eksekusi:
Output 10 print (i) -0.2766733169555664 ms
returnd

if name =='main':number
()
print (f "Time taken : {now-time ()}
ms")
2 Variable1- Import numpy as np
10 From memory_profile rimport profile
from time import time
Output
Variable now = time
1 =1 ()@ profile
Output def number ():
Variable d=np.ones ((100,1000,1000)) Analisis Memori :
2=2 52.7 MiB Waktu
a= 1 Eksekusi:
Output
b= 2
Variable
3=3
Output
Variable
4=4
Output c= 3 -0.2600116729736328
Variable d= 4
e= 5
5=5
f= 6
Output g= 7
Variable 6 h= 8
=6 i=9
Output print (a)
Variable 7 print
=7 (a+a)
Output print
Variable 8 (a+b)
=8 print
Output (a+c)
Variable 9 print
=9 (a+d)
Output print
Variable (a+e)
10=10 print (a+f)
print
(a+g)
print
(a+h)
print (a+i)
returnd
If name =='main':number
()
Print (f "Time taken: {now-time ()}
ms")
3 a=1 Import numpy as np
while From memory_profile rimport
(a<11): profile from time import time
output
(a)a+=1 now = time
()@ profile
def numbe r(): Analisis Memori :
d=np.ones ((100,1000,1000)) 815.7 MiB Waktu
a = 1 while Eksekusi:
(a<11): -0.2845613956451416 ms
print
(a)a+=1
returnd
If name =='main':number
()
Print (f "Time taken:{now-time ()}
ms")
4 For i in Import numpy as np
[1,2,3,4,5,6, From memory_profile rimport
7,8,9,10]: profile from time import time
output(i)
now = time Analisis Memori :
()@ profile 815.6 MiB Waktu
def number ():
Eksekusi:
d=np.ones ((100,1000,1000))
-0.29025888442993164 ms
for i in[1,2,3,4,5,6,7,8,9,10]:
print (i)
returnd

if name =='main':number
()
print (f "Time taken:{now-time ()}
ms")
5 for i Import numpy as np
inrange From memory_profile rimport
1,11): profile from time import time
output(i)
now = time Analisis Memori :
()@ profile 815.7 MiB Waktu
def number (): Eksekusi:
d = np.ones -0.30426025390625 ms
((100,1000,1000))
for i inrange
(1,11):print (i)
returnd
If name =='main':number
()
Print (f "Time taken:{now-time ()}
ms")
6 for i Import numpy as np
inrange from memory_profiler import
(1,11,1): profile from time import time
Output (i)
now = time Analisis Memori :
()@ profile 815.8 MiB Waktu
def number(): Eksekusi:
d=np.ones ((100,1000,1000))
-0.27593469619750977 ms
for i inrange
(1,11,1):print (i)
returnd
Ifname =='main':number()
Print (f "Time taken:{now-time ()}
ms")

7 def urutan Import numpy as np


4():for i From memory_profile rimport
inrange profile from time import time
(1,11,1):
output (i) now = time
urutan 4() ()@ profile
variable 1=1 def number():
Analisis Memori: 815.7 MiB
d=np.ones ((100,1000,1000))
variable 2=2
def urutan 4():
variable 3=3
Variable 4=4 For i in Waktu Eksekusi:
Variable 5=5 range(1,11,1): -0.30608558654785156 ms
Variable 6=6 print(i)u
Variable 7=7 rutan4()
Variable 8=8
Variable 9= urutan 1=1
urutan 2=2
9
urutan 3=3
Variable urutan 4=4
10=10 urutan 5=5
urutan 6=6
urutan 7=7
urutan 8=8
output(vari
urutan 9=9
abel
urutan 10=10
1,variable
2,variable
print (urutan 1,urutan 2,urutan
3,variable
3,urutan 4,urutan 5,urutan 6,urutan
4,variable
7,urutan 8,urutan 9,urutan 10)
5,variable
returnd
6,variable
7,variable
8,variable
9,variable
10)

If name ==
'main':number()
Print (f "Time taken:{now-time ()}
ms")
8 Def Import numpy as np
urutan( From memory_profile rimport
):a=1 profile from time import time
while
(a<11): now = time
print (a) ()@ profile Analisis Memori :
a+=1 def number(): 815.7 MiB Waktu
d=np.ones ((100,1000,1000)) Eksekusi:
uruta
def urutan (): -0.26932239532470703 ms
n () a = 1while
(a<11):
print (a)
a+=1
urutan()
returnd
If name =='main':number()
print (f "Time taken:{now-time ()}
ms")
9 def Import numpy as np
urutan From memory_profile rimport
2(): for profile from time import time
i
in now = time
()@ profile Analisis Memori :
[1,2,3,4,5,6,
def number(): 815.7 MiB Waktu
7,8,9,10]:
d=np.ones((100,1000,1000)) Eksekusi:
Output (i)
def urutan 2(): -0.2914741039276123 ms
urutan for
2() iin[1,2,3,4,5,6,7,8,9,10]:
print(i)ur
urutan 2
()
returnd

if name=='main':number ()
print (f "Time taken:{now-time ()}
ms")
10 Def Import numpy as np
urutan From memory_profile rimport
3m():fo profile from time import time
ri in
Range now = time
(1,11): ()@ profile Analisis Memori :
def number(): 815.7 MiB Waktu
d=np.ones ((100,1000,1000)) Eksekusi:
Output (i)
def urutan 3(): -0.2795584201812744 ms
urutan3() for iin
range(1,11):
print
(i)urutan 3()
returnd

if name=='main':number()
print (f "Time taken:{now-time()}
ms")

Anda mungkin juga menyukai