Slippery Rock University Dr. Deborah Whitfield Go Browns!

Chapter 2: Analysis Example
Data Structures and Algorithms in Java
CpSc 374

The selection sort is one of many sorts we will analyze and discuss this semester:

The code on the left is in algorithm - not code
constants are created for the cost of each operation in a line of the code (as needed)
Now, multiply the cost by the number of times the line is executed and add them up:


Best case analysis
Best case occurs when the data is already sorted
Worse case analysis
We first need to know what summations are in algebraic format:

Now, use the equivalent equation and do some math...