Lecture Activity
Today we talked about statement counts and time complexity.
We analyzed the following during lecture:
- The first try of the Driver.java file from 2/13
has a statement count of 14 (1 + 2*6 + 1) and
a time complexity of O(1).
- The first catch of the Driver.java file from 2/13 has
a statement count of 2 and a time complexity of O(1).
- The second try of the Driver.java file from 2/13 has
a statement count of 1 + 3*n and a time complexity of O(n)
where n is the number of pairs of data lines in the input file.
- The second catch of the Driver.java file from 2/13 has
a statement count of 2 and a time complexity of O(1).
- The constructor of the Numbers.java file from 2/15 has
a statement count of 1 + n and a time complexity of O(n)
where n is the size of the numbers array.
- The initialize method of the Numbers.java file from 2/15
has a statement count of n and a time complexity of O(n)
where n is the size of the numbers array.
- The print method of the Numbers.java file from 2/15 has
a statement count of n and a time complexity of O(n)
where n is the size of the numbers array.
- The getNumbers method of the Numbers.java file from 2/15 has
a statement count of 1 and a time complexity of O(1).
- The swap method of the Sort.java file from 2/15 has
a statement count of 3 and a time complexity of O(1).
- The findMin method of the Sort.java file from 2/15 has
a statement count of 2 + 2k in the worst case and a statement
count of 2 + k in the best case and a time complexity of
O(k) where k is finish - start.
- The selectionSort method of the Sort.java file from 2/15 has
a worst case statement count of 6n + n2 and a time
complexity of O(n2).
A Useful Summation Equality
i=1 to nΣ i = (1 + 2 + ... + n ) = n(n+1)/2