cs231 Lecture Notes Week 2, Friday Analysis of Algorithms ---------------------- Is mergeSort faster than the simple sort we saw last time (which is sometimes called selection sort)? What do we mean by faster? One possibility is run time (how do we deal with different machines)? obviously running the program on two different machines isn't fair, but it's possible that On machine A, one algorithm is faster than the other, but On machine B, the other algorithm is faster! So, the usual practice of computer scientists is to evaluate algorithms by counting the number of ABSTRACT OPERATIONS. By "abstract operation" I mean something less concrete than the simple operations computers perform. Instead, for each kind of algorithm, we usually choose the particular operation that we expect to take most of the time. For example, 1) text manipulation: count integer operations 2) matrix arithmetic: count floating-point operations sometimes, the number of multiply-adds 3) sorting: count the number of comparisons This decision is sometimes a little arbitrary. Next problem: The number of operations depends on the size of the problem (how big is the text, or the matrix, or the array we are sorting). So what we really want is a function number of ops = f (problem size) Next problem: problem size is not always one dimensional (matrixes are 2 or 3 or more dimensional) In this case (sorting) life is easy. Ok, so let's figure out the number of COMPARISONS as a function of the SIZE OF THE ARRAY (a.k.a. number of elements). Simple sort: public void sort () { for (int i=0; i