1.buatlah algoritma pengurutan secara ascending (dari angka terkecil ke yang

Berikut ini adalah pertanyaan dari netanyasembiring11 pada mata pelajaran TI untuk jenjang Sekolah Menengah Atas

1.buatlah algoritma pengurutan secara ascending (dari angka terkecil ke yang terbesar) dari data 5,11,7,3,9,2,5,13,23,20 dengan metode insertion short!2.buatlah algoritma pengurutan secara ascending data 17,9,12,8,10,6,13,20,11,21 dengan metode selection short​!​

Jawaban dan Penjelasan

Berikut ini adalah pilihan jawaban terbaik dari pertanyaan diatas.

Jawaban:

1. buatlah algoritma pengurutan secara ascending (dari angka terkecil ke yang terbesar) dari data 5,11,7,3,9,2,5,13,23,20 dengan metode insertion short!

code in python:
def insertionSort(arr):

   for i in range(1, len(arr)):

       element = arr[i]

       j = i-1

       while j >= 0 and element < arr[j] :

               arr[j + 1] = arr[j]

               j -= 1

               print('pergeseran iterasi ke', i - 1, arr)

       arr[j + 1] = element

       print('iterasi', i-1,arr)

arr = [5,11,7,3,9,2,5,13,23,20]

insertionSort(arr)

Output code python:
iterasi 0 [5, 11, 7, 3, 9, 2, 5, 13, 23, 20]

pergeseran iterasi ke 1 [5, 11, 11, 3, 9, 2, 5, 13, 23, 20]

iterasi 1 [5, 7, 11, 3, 9, 2, 5, 13, 23, 20]

pergeseran iterasi ke 2 [5, 7, 11, 11, 9, 2, 5, 13, 23, 20]

pergeseran iterasi ke 2 [5, 7, 7, 11, 9, 2, 5, 13, 23, 20]

pergeseran iterasi ke 2 [5, 5, 7, 11, 9, 2, 5, 13, 23, 20]

iterasi 2 [3, 5, 7, 11, 9, 2, 5, 13, 23, 20]

pergeseran iterasi ke 3 [3, 5, 7, 11, 11, 2, 5, 13, 23, 20]

iterasi 3 [3, 5, 7, 9, 11, 2, 5, 13, 23, 20]

pergeseran iterasi ke 4 [3, 5, 7, 9, 11, 11, 5, 13, 23, 20]

pergeseran iterasi ke 4 [3, 5, 7, 9, 9, 11, 5, 13, 23, 20]

pergeseran iterasi ke 4 [3, 5, 7, 7, 9, 11, 5, 13, 23, 20]

pergeseran iterasi ke 4 [3, 5, 5, 7, 9, 11, 5, 13, 23, 20]

pergeseran iterasi ke 4 [3, 3, 5, 7, 9, 11, 5, 13, 23, 20]

iterasi 4 [2, 3, 5, 7, 9, 11, 5, 13, 23, 20]

pergeseran iterasi ke 5 [2, 3, 5, 7, 9, 11, 11, 13, 23, 20]

pergeseran iterasi ke 5 [2, 3, 5, 7, 9, 9, 11, 13, 23, 20]

pergeseran iterasi ke 5 [2, 3, 5, 7, 7, 9, 11, 13, 23, 20]

iterasi 5 [2, 3, 5, 5, 7, 9, 11, 13, 23, 20]

iterasi 6 [2, 3, 5, 5, 7, 9, 11, 13, 23, 20]

iterasi 7 [2, 3, 5, 5, 7, 9, 11, 13, 23, 20]

pergeseran iterasi ke 8 [2, 3, 5, 5, 7, 9, 11, 13, 23, 23]

iterasi 8 [2, 3, 5, 5, 7, 9, 11, 13, 20, 23]

2. buatlah algoritma pengurutan secara ascending data 17,9,12,8,10,6,13,20,11,21 dengan metode selection short​!​

code in python:

def Selection_Sort(A):

  for i in range(len(A)):

      print('iterasi', i, A)

      min_idx = i

      for j in range(i+1, len(A)):

          if A[min_idx] > A[j]:

              min_idx=j

      A[i], A [min_idx] = A[min_idx], A[i] # proses pertukaran di python

A = [17,9,12,8,10,6,13,20,11,21]

Selection_Sort(A)

Output code python:

iterasi 0 [17, 9, 12, 8, 10, 6, 13, 20, 11, 21]

iterasi 1 [6, 9, 12, 8, 10, 17, 13, 20, 11, 21]

iterasi 2 [6, 8, 12, 9, 10, 17, 13, 20, 11, 21]

iterasi 3 [6, 8, 9, 12, 10, 17, 13, 20, 11, 21]

iterasi 4 [6, 8, 9, 10, 12, 17, 13, 20, 11, 21]

iterasi 5 [6, 8, 9, 10, 11, 17, 13, 20, 12, 21]

iterasi 6 [6, 8, 9, 10, 11, 12, 13, 20, 17, 21]

iterasi 7 [6, 8, 9, 10, 11, 12, 13, 20, 17, 21]

iterasi 8 [6, 8, 9, 10, 11, 12, 13, 17, 20, 21]

iterasi 9 [6, 8, 9, 10, 11, 12, 13, 17, 20, 21]

maaf klo salah

Semoga dengan pertanyaan yang sudah terjawab oleh agustinacahyani5 dapat membantu memudahkan mengerjakan soal, tugas dan PR sekolah kalian.

Apabila terdapat kesalahan dalam mengerjakan soal, silahkan koreksi jawaban dengan mengirimkan email ke yomemimo.com melalui halaman Contact

Last Update: Tue, 11 Jul 23