You are on page 1of 11

CHAPTER I

INTRODUCTION
I.1. Background
Algorithm is a set of instructions used to solve a problem. In general, algorithm is more
or less the same as a procedure that is done every day, such as a procedure for using the phone,
cooking procedures, and so on. In the field of computer science, algorithms are also used. For
example, a programmer needs an algorithm to create an effective and efficient program. There
are many algorithms used in the field, for example, the sorting sort algorithm.

Since the beginning of computing, this sort of problem has attracted serious research,
possibly because of the complexity of the settlement efficiently as well as the ease with which
we understand the statement. We take the example of the banking application. The app is
capable of displaying the list of active accounts. Almost all users on the system will select the
ascending list view sequentially for convenience in data retrieval. This is what keeps the
authors interested in discussing the sorting sort algorithm, especially the sorting sort algorithm.

I.2. Writing Objective


Based on the problem domain, the following is the purpose of writing ISAS entitled
"Implementing Insertion Sort Algorithm":

1. To know the definition of Insertion sort algorithm.


2. To know the history of Insertion sort algorithm.
3. To know how the Insertion sort algorithm.
4. To find out cases using Insertion sort algorithm.
5. Implementing insertion sort algorithm.

I.3. Problem Domain


Things that will be discussed in this ISAS is the definition, history, work mechanism,
example of use, and implementation of the type of insertion sort algorithm.

I.4. Writing Methodology


Writing methodology used is to find sources of information and reference from internet,
journals, and books from various media.

I.5. Writing Framework


The following is the systematics of ISAS writing entitled " Implementing Insertion Sort
Algorithm ":

1. CHAPTER I INTRODUCTION

a. Background
b. Writing Objective
c. Problem Domain

1
d. Writing Methodology
e. Writing Framework

2. CHAPTER II BASIC THEORY

a. Algorithm
b. What Is Data Structure
c. Sorting Sort Algorithm

3. CHAPTER III PROBLEM ANALYSIS

a. Understanding Insertion Sort


b. Implementation of Insertion Sort
c.

4. CHAPTER IV CONCLUSION AND SUGGESTION

a. Conclusion
b. Suggestion

5. BIBLIOGRAPHY

2
CHAPTER II

BASIC THEORY

II.1. Algorithm
The origin of the word algorithm comes from the name Abu Ja'far Mohammed ibn
Musa al-Khowarizmi, Persian scientist who wrotes the book al-jabr w'al-muqabala (Rules of
Restoration and Reduction) around the year 825 AD.

II.1.1. The Definition of Algorithm


Algorithm is an instruction to solve a problem. It can be a simple process, like
multiplying two numbers, or a complex operation, like playing a compressed video file.
Search engines use algorithms to display relevant results from their search index. In
non-technical terms, algorithms are used in everyday activities. Like a recipe for
making a cake or a guidebook.

In computer programming, algorithms are often created as functions. This


function is presented as a small program that can be referenced by a larger program.
For example, an image viewer application consists of a library of functions that each
uses an algorithm to render a different image file formats. An image editing program
consists of algorithms designed to process image data. Examples of image processing
algorithms are cropping, resizing, sharpening, blurring, red-eye reduction, and color
enhancement.

II.1.2. Algorithm Criteria by Donald E. Knuth


1. Input : Algorithm can have zero or more input from outside.
2. Output : Algorithm must have at least one output.
3. Definiteness : Algorithm has clear and unambiguous instructions.
4. Finiteness : Algorithm must have stopping role.
5. Effectiveness : Algorithm as much as possible should be executable
and effective

II.1.3. Type of Algorithm Process


1. Sequence Process : Instruction is done sequentially.
2. Selection Process : Instruction is done if it meets certain criteria.
3. Iteration Process : Instruction is done during a certain condition.
4. Concurrent Process : Several instructions are done together.

II.2. What Is Data Structure


Data structure, in the simplest term is a scheme for organizing related data in
computer’s memory logically. As long as data structure is a scheme for data organization so
functional definition of a data structure must be independent of its implementation. The
functional definition of a data structure as known as ADT (Abstract Data Type). The part of
implementation left on developers who decide which technology is right for their project needs.
3
Data structure is foundation of a program; rightly chosen a data structure then the
program becomes efficient.

II.3. Sorting Sort Algorithm

Sorting algorithm is an algorithm that puts elements of a list in a certain order. The
most-used orders are numerical order and lexicographical order. Efficient sorting is important
for optimizing the use of other algorithms (such as search and merge algorithms) that require
sorted lists to work correctly; it is also often useful for canonicalizing data and for producing
human-readable output. More formally, the output must satisfy two conditions:

1. The output is in nondecreasing order (each element is no smaller than the previous element
according to the desired total order);
2. The output is a permutation, or reordering, of the input.

4
CHAPTER III
PROBLEM ANALYSIS

III.1 Understanding Insertion Sort


Insertion Sort is a sorting algorithm that compares the first two data elements, sorting
them, then checking the next data element one by one and comparing it with the sorted data
element. Insertion sort iterates, consuming one input element each repetition, and growing a
sorted output list. At each iteration, insertion sort removes one element from the input data,
finds the location it belongs within the sorted list, and inserts it there. It repeats until no input
elements remain. Sorting is typically done in-place, by iterating up the array, growing the sorted
list behind it. At each array-position, it checks the value there against the largest value in the
sorted list (which happens to be next to it, in the previous array-position checked). If larger, it
leaves the element in place and moves to the next. If smaller, it finds the correct position within
the sorted list, shifts all the larger values up to make a space, and inserts into that correct
position.

Insertion Sort as the name implies this sorting inserts the data to where it should, one
by one each step. If the analogy in everyday life, Insertion Sort method is like when playing
cards (playing cards). Each turn, a player will pick up a card from the deck that has been shaken
/ random The idea of the algorithm of the insertion sort method can be analogous to the order
of cards, where if a card is moved according to its position, the other card will move backward
or forward according to the condition of the transfer of the card.

Figure 1 Illustration of Insertion Sort with Cards

5
III.2 Implementation of Insertion Sort

Figure 2 Illustration of Insertion Sort

From the description of the process of sorting / sorting the data above can be known
how the data move position from one index to another index in one array. For detail the above
sorting process, can be listened through the following simulation details.

Initial data: 5, 2, 4, 6, 1, 3

Number of Index = 6 starts from 0 s / d 5

Suppose the index is 'I',

For each data sorting process, the data comparison starts from the second index (in this case i
= 1)

Process I: Process II:

i = 1, x = 1; j = 0 i = 2, j = 1, x = 2

x <j à2 <5? - true = 2, 5, 4, 6, 1, 3 x <j à 4 <5 - true = 2, 4, 5, 6, 1, 3 j = j-1, If true x


= x-1

x <j à4 <2 - false = 2, 4, 5, 6, 1, 3

6
Process III:

I = 3, j = 2, x = 3

x <j à6 <5 - false = 2, 4, 5, 6, 1, 3 j = j-1 if a process is false, then the process will not proceed,
because automatically the data on the left is all ordered correct.

Process IV:

i = 4, j = 3, x = 4

x <j à1 <6 - true = 2, 4, 5, 1, 6, 3 j = j-1, if true then x = x-1

x <j à 1 <5 - true = 2, 4, 1, 5,6, 3 j = j-1, if true then x = x-1

x <j à1 <4 - true = 2, 1, 4, 5,6, 3 j = j-1, if true then x = x-1

x <j à 1 <2 - true = 1, 2, 4, 5,6, 3

Process V:

i = 5, j = 4, x = 5

x <j à3 <6 - true = 1, 2, 4, 5,3, 6 j = j-1, if true then x = x-1

x <j à3 <5 - true = 1, 2, 4, 3, 5, 6 j = j-1, if true then x = x-1

x <j à3 <4 - true = 1, 2, 3, 4, 5, 6 j = j-1, if true then x = x-1

x <jà3 <2 - false = 1, 2, 3, 4, 5, 6 j = j-1

III.2.1. Implements on Java Program

package insertsortalgorithm;

public class InsertsortAlgorithm {

public static void main(String[] args) {

int [] data = {3,0,1,8,7,2,5,4,9,6};

int b,j,x, data_sisip;

System.out.println("====SEBELUM DIURUTKAN====");

for (int a=0; a<data.length;a++){

7
System.out.println(data[a]+","); }

System.out.println("");

for(b=0; b<data.length;b++){

x=b;

for(j=b; j<data.length;j++)

if (data[j] < data[x])

x=j;

if (x!= b){

data_sisip = data [b];

data[b]=data[x];

data[x]=data_sisip;

System.out.println("");

System.out.println("====SETELAH DIURUTKAN====");

for(int i = 0 ; i< data.length; i++){

System.out.println(data[i]+",");

8
Figure 3 System Out Print of Insertion Sort Java
Code

III.3 Advantage and Disadvantage of Insertion Sort


There are 6 Advantages that Insertion Sort had, there are:

1. Simple in its application.


2. If the list is sorted or partially sorted then Insertion Sort will be faster than Quicksort.
3. Mangkus in partially sorted data.
4. Mangkus than Bubble Sort and Selection Sort.
5. Inserion Sort's inner loop is very fast, making it one of the fastest sorting algorithms on
a small number of elements.
6. Stable.

And there are 4 Disadvantages of Insertion Sort :

1. The number of operations required in finding the right position for the array elements.
2. For a large number of arrays this is not practical.
3. If the list is sequentially reversed so that every execution of the command must scan
and replace all parts before inserting the next element.
4. It takes O (n2) time on unordered data, so it does not fit in sorting of large amounts of
elements.

9
CHAPTER IV
CONCLUSION AND SUGGESTION

IV.1. Conclusion

Sorting is the most common operation on a table. There are many methods for
performing sorting of values with varying degrees of effectiveness for each case.
Insertion sort is a less complex sorting algorithm compared to bubble sort and selection sort
algorithms.

IV.1. Suggestion

Because this paper only discusses Insertion Sort algorithm theory in brief, it is
recommended that readers also have other references to get the complete material.

10
BIBLIOGRAPHY

1. http://www.academia.edu/11748619/Makalah_Algoritma_Sorting_Binary_Insertion_Sort
2. https://penamisterius.wordpress.com/2011/03/22/insertion-sort/
3. https://www.khanacademy.org/computing/computer-science/algorithms/insertion-
sort/a/insertion-sort
4. https://www.geeksforgeeks.org/insertion-sort/

11

You might also like