Click here to load reader

# การจัดเรียงข้อมูล (sorting)

• View
217

• Download
0

Embed Size (px)

### Text of การจัดเรียงข้อมูล (sorting)

• (Sorting)

COSC2202 (Data Structure)

• (Sorting) (Sorting) 2 1. (Internal sorting) (main memory) , 2. (External sorting) ,

• Sort Order 1. Ascending Order --> 2. Descending Order -->

• Insertion Sort

• Insertion Sort

• Shell Sort

• Shell Sort Segment K=3

• Shell Sort K 10 K = n/2 = 10/2 = 5 K ( K K1 = 5; K2 = 5/2 = 2) K > 1 K = 1

• Shell Sort K

• Shell Sort

• Shell Sort

• Selection Sort

• Selection Sort//

• Heap Sort

• Heap Sort

• Bubble Sort 2

• Bubble Sort

• Quick Sort divide-and-conquer 2 2

• Quick Sort Pivot Pivot Pivot

• Quick Sort Picking the pivot

• Quick Sort < Pivot SortLeft=SortLeft+1 Pivot SortLeft-1 >= Pivot SortRight=SortRight-1

• Quick Sort

• Merge Sort (Merge Sort ) -- Merge Sort divide-and-conquer Quick Sort Quick sort Quick sort merge sort

• Merge Sort

• Radix Sort -- 1. 2. 3. 4.

• Radix Sort Linked List

• Big-O

n

Number of Loops

Straight Insertion

Straight Selection

Bubble

Shell

Heap

Quick

25

625

55

116

100

10,000

316

664

500

250,000

2,364

4,482

1,000

1,000,000

5,623

9,965

2,000

4,000,000

13,374

10,985

• void insertion_sort(int data[], int num_elts){ int i, j; for (i=0; i0) && (data[j] < data[j-1]); j--) swap(data, j, j-1);} /* insertion_sort */

void swap(int data[], int a, int b) {int temp;temp = data[a];data[a] = data[b];data[b] = temp;} /* swap */Big-O = n2

• void selection_sort(int data[], int num_elts){int i, j, lowindex;

for (i=0; i

• void bubble_sort(int data[], int num_elts){int i, j;for (i=0; ii; j--) if (data[j] < data[j-1]) swap(data, j, j-1); } /* bubble_sort */

void swap(int data[], int a, int b) {int temp;temp = data[a];data[a] = data[b];data[b] = temp;} /* swap */Big-O = n2

• least significant digit (LSD) most significant digit (MSD) k, the size of each key s, the chunk size used by the implementation.

Documents
Education
Technology
Documents
Documents
Engineering
Documents
Documents
Documents
Documents
Documents
Education
Documents
Documents
Documents
Documents
Education
Documents
Documents
Design
Documents
Documents
Engineering
Documents
Education
Documents
Education
Documents
Documents
Documents