sorting

14
Structure Data Sorting

Upload: arfan-almukaddas

Post on 31-Jan-2016

219 views

Category:

Documents


0 download

DESCRIPTION

Statistika

TRANSCRIPT

Page 1: Sorting

Structure DataSorting

Page 2: Sorting

Sorting

• Sorting defined as some sort data based on certain key values.

Page 3: Sorting

Type of Sorting

• Bubble Sorting

• Merge Sorting

• Heap Sorting

• Insertion Sorting

Page 4: Sorting

Bubble Sorting

• Bubble Sort is a simple way of sorting. The concept of the basic idea is like "water bubble" to elements of the data structure that should be in the starting position. It works by repeatedly doing traversal (looping process) for the structural elements of data that has not been sorted.

Page 5: Sorting

Algorithm

• Comparing the data I with the data (i + 1) . If it does not fit then exchange ( data i = data (i + 1) and the data (i + 1) = the data i ).

• Comparing the data (i + 1) with the data (i + 2). We do this comparison until recent data.

• After completion of the iteration we continue again next iteration by repeating the first and the second step.

• The process will stop if there is no exchange in an iteration.

Page 6: Sorting

Insertion Sorting

• Insertion sort algorithm is a simple algorithm that is efficient enough to sort a list that is almost sorted.

• The algorithm can also be used as part of a more sophisticated algorithms. The workings of this algorithm is to take the list elements one-by-one and put it in the correct position as the name suggests. In the array, the new list and the remaining elements can share a place in the array, although it is quite complicated. To save memory, use the sorting implementation in place that compares the current element to the previous element that has been sorted, and then exchange it continued until the proper position. This continues until there are no remaining elements in the input.

Page 7: Sorting

Algorithm

• Save the value of Ti into a temporary variable, with i = 1

• This compares with a previous element.

• If the previous element (Ti-1) is greater in value than Ti, the Ti values overlap with the value of Ti-1.

• Do continue to the third point, until Ti-1 ≤ Ti.

• If Ti-1 ≤ Ti fulfilled, overlap value in Ti with temporary variables stored previously.

Page 8: Sorting

Algorithm

Page 9: Sorting

Heap Sorting

• heap is a tree-shaped data structure that satisfies the properties of the heap that is, if B is a child of A, then the value stored in the node A is greater than or equal to the value stored in the node B. This results in the element with the largest value is always located at root position, and the heap is called max heap. When the comparison is reversed ie smallest element has always been at the root node, the heap is called is a min heap.

Page 10: Sorting

Algorithm

• heapify main algorithm is do internal node iteration starting from the bottom right (on the array representation, are elements that are in the greatest index) to root, then head left and go up to the upper level, and so on until it reaches the root (as array [0 ..N-1]). Therefore, the iteration is started from j = N / 2 and decreases one by one until it reaches j = 0. On the internal node, the examination is only done on the direct child nodes (not the other levels below). At the time of iterations is at a higher level, subtreesubtree always have formed the heap. Thus, the worst case is the restructuring of the node will only drain downward. Thus, this version heapify do as much as N / 2 iterations, and in the worst case will do as many iterations ²log (N) times.

Page 11: Sorting

Algorithm

Page 12: Sorting

Merge Sorting

• Merge Sort algorithm invented by John von Neumann in 1945.

• Merge Sort including divide and conquer algorithm paradigm. This is because the algorithm is simply dividing the data structure before the operation one by one.

Page 13: Sorting

Algorithm

1. Step DivideArray A is divided into two parts arrays, namely A1 and A2. If the division is still too large, then each section was divided into two other parts becomes smaller.

2. Step RecursionEach section are sorted by a recursive manner.

3. Step Conquer

Setelah diurutkan, masing-masing bagian array digabungkan dan diurutkan sehingga menjadi satu array (Array A) yang utuh dan telah disusun secara urut

Page 14: Sorting

Algorithm