Professional Documents
Culture Documents
ALGORITHM
Data Structure
By. Erwin D. Marcelo
SORTING
• Sorting is a process of ordering or placing a list of elements from a
collection in some kind of order.
• Sorting can be done in increasing(ascending) and decreasing
(descending) order.
• By sorting data, it is easier to search through it quickly and easily.
• Decreasing Order
A sequence of values is said to be in decreasing order, if the successive element is less than the
current one. For example, 9, 8, 6, 4, 3, 1 are in decreasing order, as every next element is less
than the previous element.
• Non-Increasing Order
A sequence of values is said to be in non-increasing order, if the successive element is less than
or equal to its previous element in the sequence. This order occurs when the sequence contains
duplicate values. For example, 9, 8, 6, 3, 3, 1 are in non-increasing order, as every next element is
less than or equal to (in case of 3) but not greater than any previous element.
• Non-Decreasing Order
A sequence of values is said to be in non-decreasing order, if the successive element is greater
than or equal to its previous element in the sequence. This order occurs when the sequence
contains duplicate values. For example, 1, 3, 3, 6, 8, 9 are in non-decreasing order, as every next
element is greater than or equal to (in case of 3) but not less than the previous one.
Sorting Algorithm/Technique
• Sorting algorithm specifies the way to arrange data in a particular order.
• BALLOON Sort
• INSERTION Sort
• SELECTION Sort
swap
• Exchange the value
swap(a, b){
temp = a
a= b
b = temp
}
BUBBLE SORT
Bubble sort is a simple
sorting algorithm. This
sorting algorithm is
comparison-based
algorithm in which each
pair of adjacent
elements is compare and
the elements are
swapped if they are not
in order.
BALLOON SORT
The balloon sort is similar to the bubble
sort, in that it compares elements of the
array and swaps those that are not in their
proper positions. The difference between
these two sorts is the manner in which
they compare the elements. The balloon
sort compares the first element with each
following element of the array, making
any necessary swap. When the first pass
through the array is complete, the balloon
sort then takes the second element and
compares it with each following element
of the array swapping elements that are
out of order. This sorting process
continues until the entire array is ordered.
BALLOON SORT
27 70 19 9 3
0 1 2 3 4
BALLOON SORT
70 19 27 9 3
0 1 2 3 4
19 70 27 9 3
0 1 2 3 4
19 70 27 9 3
0 1 2 3 4
9 70 27 19 3
0 1 2 3 4
3 70 27 19 9
0 1 2 3 4
BALLOON SORT
3 70 27 19 9
0 1 2 3 4
3 27 70 19 9
0 1 2 3 4
3 19 70 27 9
0 1 2 3 4
3 9 70 27 19
0 1 2 3 4
BALLOON SORT
3 9 70 27 19
0 1 2 3 4
3 9 27 70 19
0 1 2 3 4
3 9 19 70 27
0 1 2 3 4
3 9 19 70 27
0 1 2 3 4
3 9 19 27 70
0 1 2 3 4