CMPT 115 Lecture Notes - Lecture 2: Pseudocode, Dynamic Array, Bubble Sort
Document Summary
Notes written by michael horsch, mark eramian, ian mcquillan, lingling jin, and dmytro dyachuk. The di erence between a problem and an algorithm is subtle but important. A problem is a description which associates inputs to output states. Pre: list is the array of integers to be sorted, of length n. Post: list contains the same elements, rearranged into ascending order. Problems: the preconditions describe the inputs to the problem, the postconditions describe the resulting states of the variables, a problem statement itself does not indicate how to solve the problem. Sort the array list of integers into ascending order. Pre: list :: shared array ofinteger n :: integer -- the length of list. Post: list contains the same elements, rearranged into ascending order. if not(isempty (list)) then. Listofinteger larger selectlarger (list, pivot) quicksort(smaller ) quicksort(larger ) list gluetogether (smaller ,pivot,larger )