You are on page 1of 16

ic as B

or s

ng ti

al
u

ed ad to k h ich Cl c A

ah Ma td ii

s ern stla

80 01 e0 yl t01 s 21 tle i bt 2

or g

hm it

2 /1 8 /1 4

Introduction
Most of the data we work with in our day-to-day lives is sorted. We look up definitions in a dictionary by searching alphabetically. We look up a phone number by moving through the last names in the book alphabetically. The post office sorts mail in several waysby zip code, then by street address, and then by name. Sorting is a fundamental process in working with data and deserves close study.

2 /1 8 /1 4

Sorting type

2 /1 8 /1 4

Bubble Sort

The bubble sort is one of the slowest sorting algorithms available, but it is also one of the simplest sorts to understand and implement Assuming you are sorting a list of numbers in ascending order, higher values oat to the right whereas lower values oat to the left. This behavior is caused by moving through the list many times, comparing adjacent values and swapping them if the value to the left is greater than the value to the right.

2 /1 8 /1 4

Bubble Sort

2 /1 8 /1 4

Bubble Sort

2 /1 8 /1 4

Selection Sort

This sort works by starting at the beginning of the array, comparing the first element with the other elements in the array. The smallest element is placed in position 0, and the sort then begins again at position 1. This continues until each position except the last position has been the starting point for a new loop.

2 /1 8 /1 4

Selection Sort

2 /1 8 /1 4

Selection Sort

2 /1 8 /1 4

Insertion Sort
The Insertion sort is an analog to the way we normally sort things numerically or alphabetically.

2 /1 8 /1 4

Insertion Sort

2 /1 8 /1 4

Insertion Sort

2 /1 8 /1 4

TIMING COMPARISONS OF THE BASIC SORTING ALGORITHMS

100 element

1.000 element

10.000 element
2 /1 8 /1 4

Summary
In this chapter, we discussed three algorithms for sorting datathe Selection sort, the Bubble sort, and the Insertion sort. All of these algorithms are fairly easy to implement and they all work well with small data sets. The Selection sort is the most efficient of the algorithms, followed by the Bubble sort and the Insertion sort. As we saw at the end of the chapter, none of these algorithms is well suited for larger data sets (i.e., more than a few thousand elements).

2 /1 8 /1 4

Daftar pustaka
McMillan, Michael. 2007. Data Structures And Algoritm Using C#. New York : Cambridge University Press.

2 /1 8 /1 4

2 /1 8 /1 4

You might also like