The Final Exam will last for two hours. Closed book, no calculators allowed.
I will spend all of Thursday's class, June 1st, reviewing for the Final. Feel free to email me and Jiang Zheng with questions before the exam, futrelle@ccs.neu.edu, jiangzh@ccs.neu.edu.
There will be four questions on the Final, on the topics listed below.
Question 3. Selection Sort: Estimate the number of comparison steps ("<") needed in selection sort, as defined by the code below (from Sedgewick). Assume that a selection(a, 0, N-1) call is made. If you understand how the sort works, you may not need to look at the code at all, you could just work through it with a simple diagram. The outer for loop is simple enough; you need only be sure that you understand how many comparison operations, line 5, are performed in the inner for loop for each step in the outer loop. Add up all these operations to get the total. Hint: You should get a sum of approximately N terms. If you don't know how to perform this sum (you should know!) then add up a number of them and see if the sum is growing like N, NlgN, or N2.
What is the "big Oh" complexity of selection sort, based on your analysis?
1 void selection(int a[], int l, int r)
2 { for (int i = l; i < r; i++)
3 { int min = i;
4 for (int j = i+1; j <= r; j++)
5 if (a[j] < a[min]) min = j;
6 exch(a[i], a[min]);
7 }
8 }
Go to Syllabus and Calendar page for COM1201
Return to Prof. Futrelle's home page