Max(A)
- max = a0
- For i = 2 to n
- If ai > max
- max = ai
- Endif
- Endfor
MergeLists (A,B,C)
- For i = 1 to A.size
- C[i] = A[i]
- Endfor
- For i = 1 to B.size
- C[i+m] = B[i]
- EndFor
- Sort(C);
MergeLists(A,B,C)
- aPos = 0
- bPos = 0
- index = 0
- While aPos < A.size and bPos < B.size
- If A[aPos] < B[bPos]
- C[index++] = A[aPos++]
- Else
- C[index++] = B[bPos++]
- Endif
- Endwhile
- While aPos < A.size
- C[index++] = A[aPos++]
- Endwhile
- While bPos < B.size
- C[index++] = B[bPos++]
- Endwhile
MergeSort(A)
- Divide A into two sub lists B and C each of size n/2
- Sort B
- Sort C
- MergeLists(B,C,A)
IntervalScheduling(tasks) each task has a startTime and an endTime
- sort the tasks by finish time.
- current_time = 0
- position = 0
- While tasks still remain
- If task[position].starTime ≥ current_time
- schedule task[position]
- current_time = task[position].endTime
- EndIf
- position++
- EndWhile