0% found this document useful (0 votes)
26 views

Sequential Search

The document discusses two search algorithms: sequential search and binary search. [1] Sequential search iterates through an array linearly and checks each element until the target value is found. [2] Binary search works by dividing the search space in half at each step and focusing only on one half, based on whether the target value is greater or less than the middle element. [3] The document provides code examples to demonstrate implementing both sequential and binary search algorithms.

Uploaded by

MohIrfanIrawan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Sequential Search

The document discusses two search algorithms: sequential search and binary search. [1] Sequential search iterates through an array linearly and checks each element until the target value is found. [2] Binary search works by dividing the search space in half at each step and focusing only on one half, based on whether the target value is greater or less than the middle element. [3] The document provides code examples to demonstrate implementing both sequential and binary search algorithms.

Uploaded by

MohIrfanIrawan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

1.

SEQUENTIAL SEARCH

#include <stdio.h>
#include <conio.h>
main ()
{
int nilai [10],x;
int cari,ketemu;
printf ("Masukan data :\n");
for (x=0;x<10;x++)
{
printf ("nilai : ");
scanf ("%d", &nilai [x]);
}
printf("\n");
printf("membaca data :\n");
for (x=0;x<10;x++)
{
printf ("%d ", nilai [x]);
}
printf("\n\n");
printf ( "program sequential search : \n");

{
cari = 8;
x= 0;
ketemu = 0;
while ((x<10)&&(ketemu == 0))
{
if (nilai [x] == cari)
ketemu = 1;
else
x= x+1;
}
if(ketemu == 1)
printf ("data ada di larik \n");
else
printf ("data tidak ada di larik \n");
}
getch();
}




2. BINARY SEARCH

#include <stdio.h>
#include <conio.h>
main ()
{
int nilai [10],x;
int cari,ketemu,xx,k,j,swap,d,g;
printf ("Masukan data :\n");
for (x=0;x<10;x++)
{
printf ("nilai : ");
scanf ("%d", &nilai [x]);
}
printf("\n");
printf("membaca data :\n");
for (x=0;x<10;x++)
{
printf ("%d ", nilai [x]);
}
for (x=0;x<10-1;x++)
{
k = x;
for (j=x+1; j<10 ; j++)
{
if(nilai [k] > nilai [j])
{
k= j;
swap = nilai [x];
nilai [x] = nilai [k];
nilai [k] = swap;

}
}
}
printf("\n\n");
printf ("data setelah diurutkan \n\n");
for (int xx=0;xx<10;xx++)
{
printf ("%d ", nilai[xx]);
}
printf("\n\n");
printf ( "program Binary search : \n");

{
d= 0;
cari = 8;
xx= 0;
ketemu = 0;
while ((ketemu == 0)&&(xx<=cari))
{
g= (xx+cari)/2;
if (nilai [g] == cari)
ketemu = 1;
else
{
if(nilai [g] > cari)
cari= g-1;
else
xx= g+1;

}
}
if(ketemu == 1)
printf ("data ada di larik \n");
else
printf ("data tidak ada di larik \n");
}
getch();
}



LAPORAN PRAKTIKUM


SEARCHING









Oleh:
MOH IRFAN IRAWAN
H1B008015










KEMENTERIAN PENDIDIKAN NASIONAL
UNIVERSITAS JENDERAL SOEDIRMAN
FAKULTAS SAINS DAN TEKNIK
JURUSAN MATEMATIKA & ILMU PENGETAHUAN ALAM
PROGRAM STUDI MATEMATIKA
PURWOKERTO
2014

You might also like