Вы находитесь на странице: 1из 5

ANALISIS DAN PERBANDINGAN DUA ALGORITMA SEARCHING

YAITU SEQUENTIAL SEARCH DAN BINARY SEARCH

MUHAMMAD FEBIAN FERDIANSYAH


Fakultas Teknik & Informatika, Universitas Multimedia Nusantara
Jl. Scientia Boulevard, Gading Serpong, Tangerang, Banten-15811 Indonesia
muhammad.ferdiansyah@student.umn.ac.ids

Abstract— Finding data in a in sequence with what is searched until the data
document is not an easy task. Searching is a is found or not found, Binary Search is one of the
method of finding data in an application, with search methods that handle the worst case (worst
a key. A search is needed to search for specific case) on sequential search. The binary search
data from a document when the exact location process can only be performed on data that has
of the data was previously unknown. There already been sequenced. The binary search
are many searching algorithms that have been method is to divide the two elements of the value
introduced, two of which are Sequential container and compare the values. [1] With the
Search and Binary Search. This research aims same goal, a comparison of Sequential Search
to compare the quality between Sequrential and Binary Search can be done in finding a more
Search and Binary Search. The researcher suitable method. The comparison results
compares these two algorithms using the obtained are expected to help to determine the
comparative method. Here the researchers right method and in accordance with the need to
use the data in the form of arrays as follows: overcome the problem in finding data.
1, 3, 4, 5, 6, 7, 8, 9, 0, 11, 12. In the case of The method used is a comparative
finding data number 7 from the data array method. The comparative method is a method
above, Binary Search is faster than Sequential that aims to distinguish or compare. This method
Search. The Sequential Search algorithm is is carried out in order to compare between two or
simpler and the data does not need to be more facts or properties of the object under study
sorted. But Sequential Search is very based on a particular thought. This comparative
inefficient when used with more data. method is "expost facto", which means data
Whereas Binary Search requires us to sort the collected after the event in question occurs. This
data first. But Binary Search is more efficient comparative method tends to use quantitative
than Sequential Search when using lots of data. [2]
data.
II Method
A. Research Design
I Introduction
The design used in this research is to use
Finding data in a document is not an
a comparative method of comparing Sequential
easy task. Searching is a method of finding data
Search and Binary Search algorithms, with the
in an application, with a key. A search is needed
aim to see the statistical results of each algorithm,
to search for specific data from a document when
and find which algorithm is better between the
the exact location of the data was previously
two.
unknown.
B. Method
Algorithms are fundamental to
The method used in this research is to
computers processing information. As
use a comparative method that compares the java
Thompson Susabda Ngoen said, the algorithm is
script data search algorithm in the form of integer
a computational step that converts inputs into
data including:
correct outputs.
1. Sequential Search
There are many searching algorithms
2. Binary Search
that have been introduced, two of which are
In comparing the two algorithms, based
Sequential Search and Binary Search. Sequential
on the level of speed or in the form of the length
search is a data search technique in arrays that
of time used to perform the algorithm and the
will trace all elements of the array from
sequence of data in the form of ascending or
beginning to end, where the data does not need to
descending sequential data.
be sorted first. Sequential search uses the
following principle: Data is compared one by one
The stages of the process undertaken to return arr[mid];
use this method are as follows: } else if (arr[mid] < i && arr.length > 1) {
1. Prepare an integer data in the form console.log('mid lower', arr[mid], i,c);
of an array. Here I prepare the c++;
numbers 1,3,4,5,6,7,8,9,0,11,12 to returnbinarySearch(arr.splice(mid,
be tested. Number.MAX_VALUE), i, c);
2. Conduct testing by using a java } else if (arr[mid] > i && arr.length > 1) {
script algorithm coding to console.log('mid higher', arr[mid], i);
determine which algorithm is c++;
better. return binarySearch(arr.splice(0, mid),
3. Evaluate. Evaluation is done to get i,c);
the results of the tests that have } else {
been done. To find out which console.log('not here', i);
algorithm is better and which c++;
algorithm does fewer iterations. return -1;
}
III Design }
The design of this study uses a javascript var result = binarySearch(array, 12, c);
code coding, namely: console.log(result);
1. Sequential Search : </script>
<script>
var array = [1,3,4,5,6,7,8,9,0,11,12]; Both codes will be run using Google
var c = 1; Chrome.

function sequentialSearch(arr, b, c) { IV Discussion and Results


for (var i=0; i<arr.length; i++) { A. Discussion
console.log('proses ke-'+c); 1. Sequential Search
console.log(arr[i] +'=='+b+'?'); Sequential search is a data search
if (arr[i] == b) { technique in arrays that will trace all elements of
console.log('ketemu'); the array from beginning to end, where the data
console.log('array ke-'+(i+1)); does not need to be sorted first.
return i; Worst-Case :
} Array = 1, 3, 4, 5, 6, 7, 8, 9, 0, 11, 12
c++; The data needed = 12
} return null;} Process =
sequentialSearch(array, "12", c); Process-1
11 = 1? (no)
</script> Process -2
2. Binary Search : 11 = 3? (no)
<script> Process -3
var array = [1,3,4,5,6,7,8,9,0,11,12]; 11 = 4? (no)
var c = 1; Process -4
array.sort(function (array, b) { 11 = 5? (no)
return array - b; Process -5
}); 11 = 6? (no)
console.log('array,', array); Process -6
11 = 7? (no)
function binarySearch(arr, i, c) { Process -7
var mid = Math.floor(arr.length / 2); 11 = 8? (no)
console.log('proses ke-' + c); Process -8
console.log(arr[mid], i); 11 = 9? (no)
if (arr[mid] === i) { Process -9
console.log('match', arr[mid], i,c); 11 = 0? (no)
c++; Process -10
11 = 11? (no) Worst-Case
Process-11
11 = 12? (yes)

Requires 11 processes to find 12 data.


This includes the worst-case of sequential search,
because the data sought is in the last sequence of
the array.
While the best-case of sequential search
will occur if the data sought is first in the array.
Best-Case
Array = 1, 3, 4, 5, 6, 7, 8, 9, 0, 11, 12
The data needed = 1
Process =
Process-1
1 = 1? (yes)

If we run this code in google chrome


then who will out in console logs would be like
this:

Best-Case :

From this research we can know that the


farther the sequence of data to be searched. Then
the longer the Sequential Search algorithm will
run. While the closer the sequence of data to be
searched. Then the faster the data will be found.
2. . Binary Search
Binary Search is one of the search
methods that handles the worst cases in a
sequential search. The binary search process can
only be performed on data that has already been
sequenced. The binary search method is to divide
the two elements of the value container and
compare the values.

Worst-Case
Array = 1, 3, 4, 5, 6, 7, 8, 9, 0, 11, 12
Arrays must be sorted first.
Array = 0, 1, 3, 4, 5, 6, 7, 8, 9, 11, 12 Best-Case
Array Sorted = 0 1 2 3 4 5 6 7 8 9 10
The data needed = 5

Process -1
Low = 0
High = 10
Mid = (0 + 10) / 2 = 5
Index-5 = 6
6>5
Worst-Case
Process-2
Low = 0
High = 5 – 1 = 4
Mid = (0 + 4) / 2 = 2
Index-2 = 3
3<5

Process-3
Low = 2 + 1 = 3
High = 4
Mid = (3 + 4) / 2 = 3
Index-3 = 4
4<5

Process-4
Low = 3 + 1 = 4
High = 4 From this research we can find out that
Mid = (4 + 4) / 2 = 4 Binary Search must sort the data first. If the data
Index-4 = 5 is in the middle order, the faster the data will be
5 == 5 found.
Here the researcher will search for the
Requires 4 processes to find data 5. same data using these two algorithms. Data to be
Thisincludes the worst-case of binary search, but used is 7.
it's still better than sequential search.
1. Sequential Search
While the best-case of Binary Search
will occur if the data sought is in the middle of
the array.
Best-Case
Array = 1, 3, 4, 5, 6, 7, 8, 9, 0, 11, 12
Arrays must be sorted first.
Array = 0, 1, 3, 4, 5, 6, 7, 8, 9, 11, 12
Array Sorted = 0 1 2 3 4 5 6 7 8 9 10
The data needed = 6

Process-1
Low = 0
High = 10
Mid = (0 + 10) / 2 = 5
Index-5 = 6

If we run this code in google chrome


then who will out in console logs would be like
this:
Sequential Search requires 6 References
processes to find the data sought, namely 7.
[1] R. Yudi, Searching (sequential search dan
2. Binary Search binarry search), 2018.
[2] A. Ramadhana, Metode Komparatif, 2019.
[3] Steph, Linear and Binary Search in
JavaScript, 2018.
[4] 4m1r, Binary Search in Javascript, 2014.

Binary Search requires 3 processes to


find the data sought, which is 7.
In the case of searching for 7 digit
Binary Search data faster than Sequential Search.
A. Result
In this study, we see how to implement
the Sequential Search and Binary Search
algorithms. The Sequential Search algorithm is
simpler and the data does not need to be sorted.
But Sequential Search is very inefficient when
used with more data. Whereas Binary Search
requires us to sort the data first. But Binary
Search is more efficient than Sequential Search
when using lots of data.
Worst-Case from Sequential Search is
when the data sought is in the last sequence of the
array. While the best-case of sequential search
will occur if the data sought is first in the array.
Best-Case from Binary Search is when
the data sought is in the middle of the array.

V Conclusion
This research was conducted using the
comparative method, by comparing the
Sequential Search and Binary Search algorithms.
The data used is array data. Because of this
research we can conclude that, Sequential Search
Algorithm is simpler and the data does not need
to be sorted. But Sequential Search is very
inefficient when used with more data. Whereas
Binary Search requires us to sort the data first.
But Binary Search is more efficient than
Sequential Search when using lots of data.

Вам также может понравиться