Lecture 7
Lecture 7
Test score
Max: 97/100
Min: 10/100
Mean: 66/100
Median: 68.5/100
Std. dev: 20
Average points per Problem
Max: 97/100
Min: 10/100 Test score
Mean: 66/100
Median: 68.5/100
Std. dev: 20 Note: I only curve the final course grade, not individual exam scores. However,
if I were to assign final letter grades based on this score, here’s how it would
look
Test regrade policy
• Email cs ci1933-s [email protected] with a
summary of what you’d like regraded
• Attach a picture of the relevant part of your
exam to your email
• Email needs to be sent within 24 hrs from now
(before 9pm on Friday, 3/4)
Roadmap for next section of course
• Algorithm complexity analysis (continued)
• Sorting algorithms
• Abstract data types and data structures that
implement them
– Lists, stacks, queues, dictionaries
Brief review of key concepts covered last time
Intro to analysis of algorithm complexity
How do we decide which algorithm is “best”?
• Possible metrics:
– Correctness!
– How much time does it take? (time complexity)
– How much memory does it require? (space
complexity)
(we can precisely quantify these)
• Algorithm #2
• Iterate from 1st to last element of the array “Insertion” sort
• Compare the current element to its predecessor
• If curr. element smaller, compare it to elements before; move greater elements right one
position to make space for smaller element
• Algorithm #3
“Merge sort”
- Divide an array into halves
- Sort the two halves (recursively)
- Merge them into one sorted array
• Algorithm #3 “Quicksort”
– Pick an element from the list (pivot).
– Reorder the list so that all elements less than the pivot come before the pivot and so that all
elements greater than the pivot come after it (equal values can go either way).
– Repeat the process on the sub-list of lesser elements and the sub-list of greater elements.
Summary of various sorting
algorithms
Scan steps:
Swap steps:
if l is less than r:
// While both subarrays are not empty, compare an entry in one subarray with
// an entry in the other; then copy the smaller item into the temporary array
index = 0 // Next available location in tempArray
while ( (beginHalf1 <= endHalf1) and (beginHalf2 <= endHalf2) ) {
if (a[beginHalf1] <= a[beginHalf2]) {
tempArray[index] = a[beginHalf1]
beginHalf1++
}
else {
tempArray[index] = a[beginHalf2]
beginHalf2++
}
index++
}
• Total levels:
• For each level (how many comparisons?):
• Worst case?
Exercise: Quick Sort complexity
analysis
Quick Sort time complexity analysis
• Consists of one main procedure (partitioning), which is called
recursively
• 1 partitioning step, complexity?
• ~ O(n) (should require no more than n comparisons)
• Worst case?
We pick a pivot that is larger/smaller than all other elements at each step
~ n partitionings
Rual et al. Towards a proteome-scale map of the human protein–protein interaction network. Nature 437, 1173-1178 (20 October 2005)
A simpler type of data: my weekend to-do list
public A L i s t ( ) {
this(MAX_SIZE); // c a l l next constructor
}
public AList( int maxSize) {
length = 0;
// necessary cast to generic type
list= (T[])new Object[maxSize];
}
/* Rest of implementation goes here */
}