BadSort(A)
- While A is not sorted
- Select two values in the array at random
- Swap those two values.
LinearSearch(A,key)
- i ← 0
- while i < A.size and A[i] ≠ key
- i++
- return i
for size from 32 to max Fill an array with random values Search the array for random values a fixed number of times. Print the time to search the array.
Array Size Time in Msec 32 13 64 15 128 29 256 57 512 112 1024 223 2048 445 4096 888 8192 1780 16384 3570 32768 7148 65536 14302 131072 28676 262144 57267 524288 114575
Sort(A)
- for i ← 0 to A.size-2
- smallPos ← i
- for j ← i+1 to A.size-1
- if A[smallPos] > A[j]
- smallPos ← j
- if i ≠ smallPos
- Swap(A[i], A[smallPos]);
Array Size Time in Msec sqrt(time) 32 2 1 64 7 3 128 23 5 256 81 9 512 297 17 1024 1129 34 2048 4385 66 4096 17269 131 8192 68522 262 16384 272917 522