Selection Sort 6 7 Selection Sort C void
- Slides: 108
Selection. Sort 6
7 Selection Sort )ภาษา C( void selection. Sort(int d[], int n) { int k, i; for (k = n - 1; k > 0; k--) { int max. I =1; for (i = 0; i <= k; i++) if (d[i]> d[max. I]) max. I = i; int t = d[k]; d[k] = d[max. I]; d[max. I] = t; } }
#include <stdio. h> 8 #include <stdlib. h> #include <windows. h> int main(int argc, char *argv[]) { int i, k, n, repeat = 10; for( n = 0; n<=20000; n+=2000) { int *d = malloc( n * sizeof(int) ); long sum = 0; for (k=0; k<repeat; k++) { for (i=0; i<n; i++) d[i] = i; long start = Get. Tick. Count(); selection. Sort(d, n); sum += Get. Tick. Count() - start; } printf("%d t %f n", n, (float)sum/repeat); } system("PAUSE"); return 0; }
9 Selection Sort (ภาษา Java)
public class Test. Selection. Sort { public static void main(String[] args) { 10 int repeat = 10; for (int n = 0; n <= 20000; n += 2000) { int[]d = new int[n]; long sum = 0; for (int k = 0; k < repeat; k++) { for (int i = 0; i <n; i++) d[i] = i; { long start = System. current. Time. Millis(); selection. Sort(d); sum += System current. Time. Millis() - start; } System. out. printf("%d t %f n", (double)sum/repeat); } }
public class Test. Selection. Sort { public static void main(String[] args) { 11 int repeat = 10; for (int n = 0; n <= 20000; n += 2000) { int[]d = new int[n]; long sum = 0; for (int k = 0; k < repeat; k++) { for (int i = 0; i <n; i++) d[i] = i; { long start = System. current. Time. Millis(); selection. Sort(d); sum += System current. Time. Millis() - start; } System. out. printf("%d t %f n", (double)sum/repeat); } } for (int i = 0; i < 10000; i++) selection. Sort(new int[1]);
12 สงทำงาน พรอมบนทกผล ภาษา C : ใช GNU-C Compiler (3. 4. 2) ภาษา Java : ใช Java 6 (build 1. 6. 0_14 -b 08) Interpreted-only mode (option –Xint ตอนทำงาน ) Compilation to native code (บงคบ compile ดวยการเรยกเมทอดวำ ๆ สก 10 000 ครง ) Intel Core 2 Duo P 8400 2. 26 Ghz Ram 3 GB Windows XP
ใชจำนวนการทำงานของคำสงแทนเวลา 14 static int counter= 0; static void selection. Sort(int[] d) { counter = 1+d. length-1; for (int k = d. length-1; k > 0; k--) { int max. I =1; counter += 2 + k+1; for (int i = 0; i <= k; i++) { counter += 1; if (d[i] > d[max. I]) { max. I=i; counter+=1; } } counter += 3; int t = d[k]; d[k] = d[max. I]; d[max. I] = t; } }
15 เขยนโปรแกรมทดลองนบคำสง public class Test. Selection. Sort { public static void main(String[] args) { int repeat = 10; for (int n = 0; n <= 20000; n += 2000) { int[]d = new int[n]; long sum = 0; for (int k = 0; k < repeat; k++) { for (int i = 0; i <n; i++) d[i] = i; ; counter = 0; selection. Sort(d); sum += counter; } System. out. printf("%d t %f n", n, (double)sum/repeat); } }
17 นบเฉพาะคำสงตวแทน static intcounter= 0; static voidselection. Sort(int[] d) { for (int k = d. length-1; k > 0; k--) { int max. I =1; for (int i = 0; i <= k; i++) { counter += 1; if (d[i] > d[max. I]) { max. I = i; } } int t d[k]; d[k] = d[max. I]; d[max. I]=t; } }
27
29
30
31
32
33
35
36
37
38
39
41 f(n) vs. g(n)
43
44 L'Hôpital's rule
45
47
49 สญกรณเชงเสน กำกบ (Asymptotic Notations) • little-o • little – omega • Big – Omega • Big - Theta
50 little-o
51 little – omega
52 Big - Theta
53 Big – O
54 Big – Omega
62
67
68
69
72
73
74
75
76 ตวอยาง Insertion Sort
78
81
82 ตวอยาง : Tower of Hanoi
83 dki
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
- Bubble sort vs selection sort
- Bubble sort and selection sort
- Topological sort can be implemented by?
- Quick sort vs selection sort
- Pseudo code for bubble sort
- Difference between bubble sort and selection sort
- Difference between selection and insertion sort
- Void loop
- Void main(void)
- Void main(void)
- Quick sort merge sort
- Counting sort animation
- Bucket sort vs radix sort
- Quick sort merge sort
- Sort popular
- Replacement sort
- Insertion sort in mips
- Bubble sort mips
- Quicksort invariant
- Selection sort
- Insertion sort proof by induction
- Gerbang warna putih
- Selection sort best case
- Selection sort python recursive
- Selection sort best case
- Selection sort matlab
- Recurrence relation of recursive selection sort
- Cmpt 225
- Insertion sort recurrence relation
- Mips selection sort
- Selection sort algoritmo
- Urutkan
- Difference between selection and insertion sort
- Mass selection
- Natural selection vs artificial selection
- Natural selection vs artificial selection
- Balancing selection vs stabilizing selection
- Artificial selection vs natural selection
- Two way selection and multiway selection in c
- Artificial selection vs natural selection
- What is artificial selection
- Multiway selection
- K selection r selection
- Clumped dispersion
- Funcion void en c++
- Mainstring
- Public void int
- #include iostream.h void main()
- Void sender
- Croton
- C# async void vs async task
- Void bloodstain pattern
- Public static void main int args
- Public class x public static void main
- Define prim
- атомарные операции java
- Projected blood
- Negative filter
- Void main() int i j charval='j'
- Void* to int
- Private void
- #include stdio.h void main()
- Voidable
- Interface foo
- Int ival char cval void *ptr
- Arterial gushing definition
- Void interrupt
- Const table
- Void set
- Public void
- Formula for void ratio
- Empower 3 custom field calculation
- Javalab.org
- Lang
- Public void drawsquare(int x, int y, int len)
- Consider the following c function void swap
- Public class prg public static void main
- Void setup() {
- Async void c#
- Public static void main
- Void insert
- What is void setup in arduino
- Klein leap into the void
- Void main int main
- Mainstring
- Void loop()
- #include stdio.h int main(void)
- Kav chromatography
- Void amadeus
- Void inspection
- Null and void definition
- Strlen int
- Void main() int i j charval='j'
- The statement "public: virtual void draw( )=0;" is
- The statement "public: virtual void draw( )=0;" is
- Void setup() {
- Class a void foo() throws exception
- Blood spatter direction of travel
- композиция java
- #include stdio.h void main()
- Public class x public static void main
- Void swap
- Private void
- Void func(int num)
- Int (*)(bool, char)
- Void barrier