You are on page 1of 1

Searching Algorithm

1. Sequential Searching (Berturutan)


contoh : 4 7 2 5 1 9 cari 5 berarti terus mencari sampai nilai 5 tertemu

2. Binnary Seaching (Data Sudah Diurutkan)


- Tentukan nilai tengah
- Data menjadi 2 kelompok
- Bandingan yang dicari dengan nilai tengah

int [] data= new unt []


{9,7,5,8,3,4,1};
int n=3:
for (int i=o; i<data.length; i++){
if (data[i]==n){
System.out.println ("Data Ditemukan pada Indeks = "+i);
}
}

CONTOH

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication15;

/**
*
* @author Lenovo
*/
public class JavaApplication15 {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int[] dataAwal = new int[]{9, 7, 5, 8, 3, 4, 1};
int cari = 10;
String HasilPencarian = SequentialSearching(cari, dataAwal);
System.out.println(HasilPencarian);
}

public static String SequentialSearching(int n, int[] data) {


String hasil = "data tidak ditemukan";
for (int i = 0; i < data.length; i++) {
if (data[i] == n) {
System.out.println("Data Ditemukan pada Indeks = " + i);
break;
}
}
return hasil;
}
}

sorting
3. bubble sort

You might also like