 RAPTOR Syntax and Semantics - Arrays Array variable - Array variables are used to store many values (of the same type) without having to have many variable names. Instead of many variables names a count-controlled loop is used to gain access (index) the individual elements (values) of an array variable. RAPTOR has one and two dimensional arrays of numbers. A one dimensional array can be thought of as a sequence (or a list). A two dimensional array can be thought of as a table (grid or matrix). To create an array variable in RAPTOR, use it like an array variable. i.e. have an index, ex. Score, Values[x], Matrix[3,4], etc. All array variables are indexed starting with 1 and go up to the largest index used so far. RAPTOR array variables grow in size as needed. The assignment statement GPAs ŌåÉ 4.0 assigns the value 4.0 to the 24th element of the array GPAs. If the array variable GPAs had not been used before then the other 23 elements of the GPAs array are initialized to 0 at the same time. i.e. The array variable GPAs would have the following values: 1 2 3 4ŌĆ” Array variables in action- Arrays and count-controlled loop statements were made for each other. Notice in each example below the connection between the Loop Control Variable and the array index! Notice how the Length_Of function can be used in the count-controlled loop test! Notice that each example below is a count-controlled loop and has an Initialize, Test, Execute, and Modify part (I.T.E.M)! Assigning values to an array variable Reading values into an array variable Writing out an array variableŌĆÖs values Computing the total and average of an array variableŌĆÖs values Index ŌåÉ 1 Index ŌåÉ 1 Index ŌåÉ 1 Total ŌåÉ 0 Loop Loop Loop Index ŌåÉ 1 PUT ŌĆ£The value of the array at position ŌĆ£ + Index + ŌĆ£ is ŌĆ£ + GPAs[Index] Loop GPAs[Index] ŌåÉ 4.0 ŌĆ£Enter the GPA of student ŌĆ£ŌĆØ + Index + ŌĆ£: ŌĆ£ GET GPAs[Index] Index >= 24 Index >= 24 Index >= Length_Of (GPAs) Index ŌåÉ Index + 1 Index ŌåÉ Index + 1 Index ŌåÉ Index + 1 Total ŌåÉ Total + GPAs[Index] Index >= Length_Of(GPAs) Index ŌåÉ Index + 1 ŌĆ” 23 24 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4.0 The initialization of previous elements to 0 happens only when the array variable is created. Successive assignment statements to the GPAs variable affect only the individual element listed. For example, the following successive assignment statements GPAs GPAs ŌåÉ ŌåÉ 1.7 3.2 would place the value 1.7 into the 20th position of the array, and would place the value 3.2 into the 11th position of the array. i.e. GPAs ŌåÉ 1.7 GPAs ŌåÉ 3.2 1 2 3 4ŌĆ” ŌĆ” 23 24 Initialize the elements of a two dimensional array (A two dimensional array requires two loops) Row ŌåÉ 1 Loop Average ŌåÉ Total / Length_Of(GPAs) Find the largest value of all the values in an array variable Find the INDEX of the largest value of all the values in an array variable Highest_GPA ŌåÉ GPAs Highest_GPA_Index ŌåÉ1 Index ŌåÉ 1 Index ŌåÉ 1 Loop Loop GPAs[Index] > Highest_GPA GPAs[Index] >= GPAs[Highest_GPA_Index] Column ŌåÉ 1 Loop 0 0 0 0 0 0 0 0 0 0 3.2 0 0 0 0 0 0 0 0 1.7 0 0 0 4.0 An array variable name, like GPAs, refers to ALL elements of the array. Adding an index (position) to the array variable enables you to refer to any specific element of the array variable. Two dimensional arrays work similarly. i.e. Table[7,2] refers to the element in the 7 th row and 2nd column. Individual elements of an array can be used exactly like any other variable. E.g. the array element GPAs can be used anywhere the number variable X can be used. The Length_Of function can be used to determine (and return) the number of elements that are associated with a particular array variable. For example, after all the above, Length_Of(GPAs) is 24. Matrix[Row, Column] ŌåÉ 1 Column >= 20 Column ŌåÉ Column + 1 Highest_GPA ŌåÉ GPAs[Index] Highest_GPA_Index ŌåÉ Index Index >= Length_Of(GPAs) Index >= Length_Of(GPAs) Index ŌåÉ Index + 1 Index ŌåÉ Index + 1 PUT ŌĆ£The highest GPA is ŌĆ£ + Highest_GPA┬Č PUT ŌĆ£The highest GPA is ŌĆ£ + GPAs[Highest_GPA_Index] + ŌĆ£ it is at position ŌĆ£ + Highest_GPA_Index┬Č Row >= 20 Row ŌåÉ Row + 1
View full slide show RC4 Encryption ’āś encryption continues shuffling array values ’āś sum of shuffled pair selects "stream key" value from permutation ’āś XOR S[t] with next byte of message to en/decrypt i = j = 0 for each message byte Mi i = (i + 1) (mod 256) j = (j + S[i]) (mod 256) swap(S[i], S[j]) t = (S[i] + S[j]) (mod 256) Ci = Mi XOR S[t]
View full slide show createconfigs script in src/mpp-mpred-3.2.0/p95/mu11 #!/bin/bash for g in .1 .2 .4 .7 .9 do sed -i -e "s/dMNsdsThr=[^ ]*/dMNsdsThr=\$g/" t.config for h in .1 .2 .4 .7 .9 do sed -i -e "s/dMNsdsExp=[^ ]*/dMNsdsExp=\$h/" t.config cp t.config configs/a\$g\$h.config submit script run in scr/mpp-mpred-3.2.0 produces subdirs in mpp-mpred-3.2.0 : drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x drwxr-xr-x creates in src.mpp-mpred-3.2.0/p95/mu11/configs: -rw-r--r-- 1 a.1.1.config -rw-r--r-- 1 a.1.2.config -rw-r--r-- 1 a.1.4.config -rw-r--r-- 1 a.1.7.config -rw-r--r-- 1 a.1.9.config -rw-r--r-- 1 a.2.1.config -rw-r--r-- 1 a.2.2.co -rw-r--r-- 1 a.2.4.co submit in src/mpp-mpred-3.2.0 produces’é» here -rw-r--r-- 1 a.2.7.co #!/bin/bash -rw-r--r-- 1 a.2.9.co -rw-r--r-- 1 a.4.1.co for g in .1 .2 .4 .7 .9 do; for h in .1 .2 .4 .7 .9 do -rw-r--r-- 1 a.4.2.co ./mpp-submit -S -i Data/p95test.txt -c p95/mu11/configs -rw-r--r-- 1 a.4.4.co a\$g\$h.out -t .05 -d ./p95/mu11 -rw-r--r-- 1 a.4.7.co -rw-r--r-- 1 a.4.9.co -rw-r--r-- 1 a.7.1.co .predictions -rw-r--r-- 1 a.7.2.co p95test.txt.rmse 12641: Movie: 12641: -rw-r--r-- 1 a.7.4.co 1.22 0: Ans: 1 Pred: 1.22 Error: -rw-r--r-- 1 a.7.7.co 3.65 0.04840 -rw-r--r-- 1 a.7.9.co 1: Ans: 4 Pred: 3.65 Error: 2.55 -rw-r--r-- 1 a.9.1.co 0.12250 4.04 -rw-r--r-- 1 a.9.2.co 2: Ans: 2 Pred: 2.55 Error: 1.85 -rw-r--r-- 1 a.9.4.co 0.30250 -rw-r--r-- 1 a.9.7.co 3: Ans: 4 Pred: 4.04 Error: -rw-r--r-- 1 a.9.9.co 0.00160 12502: -rw-r--r-- 1 a.1.1.out 4: Ans: 2 Pred: 1.85 Error: 4.71 0.02250 -rw-r--r-- 1 a.1.2.out 3.54 Sum: 0.49750 Total: 5 RMSE: 0.315436 -rw-r--r-- 1 a.1.4.out Running RMSE: 0.315436 / 5 predictions 3.87 -rw-r--r-- 1 a.1.7.out 3.33 12502: -rw-r--r-- 1 a.1.9.out Movie: 2.97 0: Ans: 4 Pred: 4.71 Error: -rw-r--r-- 1 a.2.1.out 0.50410 : -rw-r--r-- 1 a.2.2.out . 1: Ans: 5 Pred: 3.54 Error: -rw-r--r-- 1 a.2.4.out 2.13160 10811: -rw-r--r-- 1 a.2.7.out 2: Ans: 5 Pred: 3.87 Error: 1.2769 4.05 -rw-r--r-- 1 a.2.9.out 3: Ans: 3 Pred: 3.33 Error: 3.49 -rw-r--r-- 1 a.4.1.out 0.10890 3.94 4: Ans: 2 Pred: 2.97 Error: -rw-r--r-- 1 a.4.2.out 3.39 0.94090 -rw-r--r-- 1 a.4.4.out Sum: 4.96240 Total: 5 RMSE: 0.996233 -rw-r--r-- 1 a.4.7.out 12069: -rw-r--r-- 1 a.4.9.out : Running RMSE: .738911 /10 predictions 3.20 -rw-r--r-- 1 a.7.1.out Movie: 10811 3.48 -rw-r--r-- 1 a.7.2.out 0: Ans: 5 Pred: 4.05 Error: -rw-r--r-- 1 a.7.4.out 0.90250 1: Ans: 3 Pred: 3.49 Error: -rw-r--r-- 1 a.7.7.out -rw-r--r-- 1 a.7.9.out 0.24010 is a script, createtablermse: 2: Ans: 4 Pred: 3.94In dotouts Error: -rw-r--r-- 1 a.9.1.out #!/bin/bash 0.00360 -rw-r--r-- 1 a.9.2.out 3: Ans: 3 Pred: 3.39for gError: in .1 .2 .4 .7 .9 do; for h in .1 .2 .4 .7 .9 -rw-r--r-- 1 a.9.4.out 0.15210 grep RMSE:\ a\$g\$h.out >> rmse -rw-r--r-- 1 a.9.7.out Sum: 1.29830 Total: 4 RMSE: 0.569715 -rw-r--r-- 1 a.9.9.out Running RMSE: 0.964397 / 743 preds I copy to src/mpp-mpred-3.2.0/dotouts. Movie: 12069: do Sum: Sum: Sum: Sum: Sum: Sum: Sum: Sum: Sum: Sum: Sum: Sum: Sum: Sum: Sum: Sum: Sum: Sum: Sum: Sum: Sum: Sum: Sum: Sum: Sum: 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 10:15 10:15 10:15 10:15 10:15 10:15 10:15 10:16 10:16 10:16 10:16 10:16 10:16 10:16 10:17 10:17 10:17 10:17 10:17 10:17 10:17 10:18 10:18 10:18 10:18 a.1.1 a.1.2 a.1.4 a.1.7 a.1.9 a.2.1 a.2.2 a.2.4 a.2.7 a.2.9 a.4.1 a.4.2 a.4.4 a.4.7 a.4.9 a.7.1 a.7.2 a.7.4 a.7.7 a.7.9 a.9.1 a.9.2 a.9.4 a.9.7 a.9.9 692.82510 691.59330 691.90610 691.90610 691.90610 691.84690 690.47330 691.90610 691.90610 691.90610 693.27970 691.90610 691.90610 691.90610 691.90610 691.90610 691.90610 691.90610 691.90610 691.90610 691.90610 691.90610 691.90610 691.90610 691.90610 and e.g., a.9.9 contains: -rw-r--r--rw-r--r--rw-r--r--rw-r--r--rw-r--r--rw-r--r--rw-r--r-- 1 a.9.9.config 1 hi-a.9.9.txt hi-a.9.9.txt.answers lo-a.9.9.txt lo-a.9.9.txt.answers p95test.txt.predictions p95test.txt.rmse dotouts is a script, createtablejob:#!/bin/bash for g in .1 .2 .4 .7 .9 do; for h in .1 .2 .4 .7 .9 do grep Input:\ \ \ lo a\$g\$h.out >> job Total: Total: Total: Total: Total: Total: Total: Total: Total: Total: Total: Total: Total: Total: Total: Total: Total: Total: Total: Total: Total: Total: Total: Total: Total: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: 745 745 745 745 745 745 745 745 745 745 745 745 745 745 745 745 745 745 745 745 745 745 745 745 745 lo-a.1.1.txt lo-a.1.2.txt lo-a.1.4.txt lo-a.1.7.txt lo-a.1.9.txt lo-a.2.1.txt lo-a.2.2.txt lo-a.2.4.txt lo-a.2.7.txt lo-a.2.9.txt lo-a.4.1.txt lo-a.4.2.txt lo-a.4.4.txt lo-a.4.7.txt lo-a.4.9.txt lo-a.7.1.txt lo-a.7.2.txt lo-a.7.4.txt lo-a.7.7.txt lo-a.7.9.txt lo-a.9.1.txt lo-a.9.2.txt lo-a.9.4.txt lo-a.9.7.txt lo-a.9.9.txt RMSE: RMSE: RMSE: RMSE: RMSE: RMSE: RMSE: RMSE: RMSE: RMSE: RMSE: RMSE: RMSE: RMSE: RMSE: RMSE: RMSE: RMSE: RMSE: RMSE: RMSE: RMSE: RMSE: RMSE: RMSE: 0.964348 0.963490 0.963708 0.963708 0.963708 0.963667 0.962710 0.963708 0.963708 0.963708 0.964664 0.963708 0.963708 0.963708 0.963708 0.963708 0.963708 0.963708 0.963708 0.963708 0.963708 0.963708 0.963708 0.963708 0.963708
View full slide show 71 MOD 41 ’ĆĮ7 7 2 MOD 41 ’ĆĮ 49 MOD 41 ’ĆĮ8 7 4 MOD 41 ’ĆĮ(7 2 ) 2 MOD 41 ’ĆĮ(8) 2 MOD 41 ’ĆĮ64 MOD 41 ’ĆĮ 23 78 MOD 41 ’ĆĮ(7 4 )2 MOD 41 ’ĆĮ(23)2 MOD 41 ’ĆĮ529 MOD 41 ’ĆĮ37 716 MOD 41 ’ĆĮ(78 ) 2 MOD 41 ’ĆĮ(37) 2 MOD 41 ’ĆĮ1369 MOD 41 ’ĆĮ16 732 MOD 41 ’ĆĮ(716 )2 MOD 41 ’ĆĮ(16)2 MOD 41 ’ĆĮ 256 MOD 41 ’ĆĮ10 764 MOD 41 ’ĆĮ(732 ) 2 MOD 41 ’ĆĮ(10) 2 MOD 41 ’ĆĮ100 MOD 41 ’ĆĮ18
View full slide show In dotouts is a script, createtablermse: In dotouts is a script, createtablejob: #!/bin/bash for g in .1 .2 .4 .7 .9 do for h in .1 .2 .4 .7 .9 do grep RMSE:\ a\$g\$h.out >> rmse done done #!/bin/bash for g in .1 .2 .4 .7 .9 do for h in .1 .2 .4 .7 .9 do grep Input:\ \ \ lo a\$g\$h.out >> job done done Sum: 692.82510 Sum: 691.59330 Sum: 691.90610 Sum: 691.90610 Sum: 691.90610 Sum: 691.84690 Sum: 690.47330 Sum: 691.90610 Sum: 691.90610 Sum: 691.90610 Sum: 693.27970 Sum: 691.90610 Sum: 691.90610 Sum: 691.90610 Sum: 691.90610 Sum: 691.90610 Sum: 691.90610 Sum: 691.90610 Sum: 691.90610 Sum: 691.90610 Sum: 691.90610 Sum: 691.90610 Sum: 691.90610 Sum: 691.90610 Sum: 691.90610 Total: 745 Total: 745 Total: 745 Total: 745 Total: 745 Total: 745 Total: 745 Total: 745 Total: 745 Total: 745 Total: 745 Total: 745 Total: 745 Total: 745 Total: 745 Total: 745 Total: 745 Total: 745 Total: 745 Total: 745 Total: 745 Total: 745 Total: 745 Total: 745 Total: 745 RMSE: 0.964348 RMSE: 0.963490 RMSE: 0.963708 RMSE: 0.963708 RMSE: 0.963708 RMSE: 0.963667 RMSE: 0.962710 RMSE: 0.963708 RMSE: 0.963708 RMSE: 0.963708 RMSE: 0.964664 RMSE: 0.963708 RMSE: 0.963708 RMSE: 0.963708 RMSE: 0.963708 RMSE: 0.963708 RMSE: 0.963708 RMSE: 0.963708 RMSE: 0.963708 RMSE: 0.963708 RMSE: 0.963708 RMSE: 0.963708 RMSE: 0.963708 RMSE: 0.963708 RMSE: 0.963708 Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: lo-a.1.1.txt lo-a.1.2.txt lo-a.1.4.txt lo-a.1.7.txt lo-a.1.9.txt lo-a.2.1.txt lo-a.2.2.txt lo-a.2.4.txt lo-a.2.7.txt lo-a.2.9.txt lo-a.4.1.txt lo-a.4.2.txt lo-a.4.4.txt lo-a.4.7.txt lo-a.4.9.txt lo-a.7.1.txt lo-a.7.2.txt lo-a.7.4.txt lo-a.7.7.txt lo-a.7.9.txt lo-a.9.1.txt lo-a.9.2.txt lo-a.9.4.txt lo-a.9.7.txt lo-a.9.9.txt
View full slide show Array Lesson 1 Outline 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. Array Lesson 1 Outline Mean of a List of Numbers Mean: Declarations Mean: Greeting, Input Mean: Calculation Mean: Output Mean: Compile, Run Mean: 5 Input Values Mean: 7 Input Values Mean: One Line Different Mean: Compile, Run for 5 Mean: Compile, Run for 7 Scalars #1 Scalars #2 Another Scalar Example A Similar Program, with Multiplication A Similar Program, with a Twist Arrays Array Element Properties 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. Array Properties #1 Array Properties #2 Array Properties #3 Array Properties #4 Array Properties #5 Array Indices #1 Array Indices #2 Multidimensional Arrays & 1D Arrays Array Declarations #1 Array Declarations #2 Array Declarations #3 Assigning a Value to an Array Element Array Element Assignment Example Getting Array Element Value with scanf Array Element scanf Example #1 Array Element scanf Example #2 for Loops for Tasks on Arrays #1 for Loops for Tasks on Arrays #2 Another for/Array Example #1 Another for/Array Example #2 Another for/Array Example #3 DonŌĆÖt Need to Use Entire Declared Length Array Lesson 1 CS1313 Spring 2019 1
View full slide show Proof of Correctness ’āś Notice that v=(gu1yu2 mod p) mod q ’üŁ =(gH(M)w mod q yrw mod q mod p) mod q ’üŁ =(gH(M)w mod q gxrw mod q mod p) mod q ’üŁ =(gH(M)w +xrw mod q mod p) mod q ’üŁ =(g(H(M)+xr)w mod q mod p) mod q ’üŁ =(g(H(M)+xr)k(H(M)+xr)-1 mod q mod p) mod q ’üŁ =(gk mod p) mod q ’üŁ =r Cryptography and Network Security 355
View full slide show Sector 0 Z502 Disk Structure Definition Of Sector 0: This is the first block on a disk. It is produced when you do a software Format of the disk. It defines various segments of the disk necessary for successful operation. Byte Bytes Offset in Field Field 0 1 Disk ID 1 1 Bitmap Size 2 1 RootDir Size 3 1 Swap Size 4 2 6 8 10 12 15 2 2 2 3 1 Description The number you have given to the disk. It will be easiest if you assign the same number as the hardware uses, but itŌĆÖs your choice. How large is the bitmap. You can determine your own size. The size will be 4 X BitmapSize So if this field contains a 3, then 4 X 3 = 12 and 12 blocks will be assigned to the bitmap. How large is the Root Directory Header. You can determine your own size. The size will be RootDirSize So if this field contains a 1, then 1 block will be assigned to the Root Directory Header. Note that the total size of a directory is determine by the number of indices, subdirectories and files that are in that directory. This field is only to specify the header size. How large is the Swap Space. You can determine your own size. The size will be 4 X SwapSize So if this field contains a 2, then 4 X 2 = 8 and 8 blocks will be assigned to the Swap Directory. Disk Length This is the number of sectors you are using on the disk. Note Byte 5 is Most Significant Byte, Byte 4 is Least Significant Byte Bitmap Location The starting sector number where the bitmap is located. Note Byte 7 is MSB, Byte 6 is LSB Swap Location The starting sector number where the Swap Space is located. Note Byte 9 is MSB, Byte 8 is LSB Root Dir Location The starting sector number where the Root Directory is located. Note Byte 11 is MSB, Byte 10 is LSB RESERVED For this release, these bytes must be set to ŌĆś\0ŌĆÖ. Revision For this release, this byte must be set to 1. 7
View full slide show Prerequisite: modular arithmetic ŌĆó x mod n = remainder of x when divide by n ŌĆó Facts: [(a mod n) + (b mod n)] mod n = (a+b) mod n [(a mod n) - (b mod n)] mod n = (a-b) mod n [(a mod n) * (b mod n)] mod n = (a*b) mod n ŌĆó Thus (a mod n)d mod n = ad mod n ŌĆó Example: x=14, n=10, d=2: (x mod n)d mod n = 42 mod 10 = 6 xd = 142 = 196 xd mod 10 = 6 26
View full slide show Prerequisite: modular arithmetic ’ü▓ x mod n = remainder of x when divide by n ’ü▓ Facts: [(a mod n) + (b mod n)] mod n = (a+b) mod n [(a mod n) - (b mod n)] mod n = (a-b) mod n [(a mod n) * (b mod n)] mod n = (a*b) mod n ’ü▓ Thus (a mod n)d mod n = ad mod n ’ü▓ Example: x=14, n=10, d=2: (x mod n)d mod n = 42 mod 10 = 6 xd = 142 = 196 xd mod 10 = 6 29
View full slide show Swap-Space Management ’ü« Swap-space ŌĆö Virtual memory uses disk space as an extension of main memory ’ü¼ Less common now due to memory capacity increases ’ü« Swap-space can be carved out of the normal file system, or, more commonly, it can be in a separate disk partition (raw) ’ü« Swap-space management ’ü¼ 4.3BSD allocates swap space when process starts; holds text segment (the program) and data segment ’ü¼ Kernel uses swap maps to track swap-space use ’ü¼ Solaris 2 allocates swap space only when a dirty page is forced out of physical memory, not when the virtual memory page is first created ’Ć┤ File data written to swap space until write to file system requested ’Ć┤ Other dirty pages go to swap space due to no other home ’Ć┤ Text segment pages thrown out and reread from the file system as needed ’ü« What if a system runs out of swap space? ’ü« Some systems allow multiple swap spaces Operating System Concepts Essentials ŌĆō 8 th Edition 11.30 Silberschatz, Galvin and Gagne ┬®2011
View full slide show Swap-Space Management ’ü« Swap-space ŌĆö Virtual memory uses disk space as an extension of main memory ’ü¼ Less common now due to memory capacity increases ’ü« Swap-space can be carved out of the normal file system, or, more commonly, it can be in a separate disk partition (raw) ’ü« Swap-space management ’ü¼ 4.3BSD allocates swap space when process starts; holds text segment (the program) and data segment ’ü¼ Kernel uses swap maps to track swap-space use ’ü¼ Solaris 2 allocates swap space only when a dirty page is forced out of physical memory, not when the virtual memory page is first created ’Ć┤ File data written to swap space until write to file system requested ’Ć┤ Other dirty pages go to swap space due to no other home ’Ć┤ Text segment pages thrown out and reread from the file system as needed ’ü« What if a system runs out of swap space? ’ü« Some systems allow multiple swap spaces Operating System Concepts Essentials ŌĆō 2nd Edition 9.32 Silberschatz, Galvin and Gagne ┬®2013
View full slide show Selection Sort Selection sort finds the smallest number in the list and places it first. It then finds the smallest number remaining and places it second, and so on until the list contains only a single number. swap Select 1 (the smallest) and swap it with 2 (the first) in the list 2 9 5 4 8 1 6 8 2 6 The number 1 is now in the correct position and thus no longer needs to be considered. swap Select 2 (the smallest) and swap it with 9 (the first) in the remaining list 1 Select 4 (the smallest) and swap it with 5 (the first) in the remaining list 1 2 5 4 8 9 6 The number 2 is now in the correct position and thus no longer needs to be considered. 5 is the smallest and in the right position. No swap is necessary 1 2 4 5 8 9 6 The number 6 is now in the correct position and thus no longer needs to be considered. Select 6 (the smallest) and swap it with 8 (the first) in the remaining list 1 6 The number 5 is now in the correct position and thus no longer needs to be considered. Select 8 (the smallest) and swap it with 9 (the first) in the remaining list 1 2 4 5 6 9 8 The number 6 is now in the correct position and thus no longer needs to be considered. Since there is only one element remaining in the list, sort is completed 1 2 4 5 6 8 9 The number 8 is now in the correct position and thus no longer needs to be considered. 9 5 4 swap swap 2 4 5 8 9 swap
View full slide show