CS1331: Introduction to OOP
Georgia Institute of Technology
Exam 3 Review
Dr. Aibek Musaev
1
Asymptotics
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
// do stuff
}
}
2
Asymptotics
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
// some code
}
}
3
Asymptotics
for (int i = 0; i < n; i++) {
for (int j = 0; j < 1000; j++) {
for (int k = 0; k < 10; k++) {
// constant work
}
}
}
4
Asymptotics
for (int i = 1; i < n; i *= 3) {
for (int j = 0; j < n; j += 2) {
// work
}
}
5
Sorting Algorithms
◼ Initial data: [85, 41, 23, 99, 18, 59, 32, 71]
◼ What is the order of the following data after 3
iterations (i.e., passes) of an ascending…
❑ Selection sort algorithm
❑ Insertion sort algorithm
❑ Bubble sort algorithm
6
Coding Exercise: Sorting Strings
◼
◼
Write a Java program that creates an array with the names of the
Beatles members and sorts it in alphabetical order using selection
sort.
Instructions:
❑ Create an array with the names "John Lennon," "Paul
McCartney," "George Harrison," and "Ringo Starr."
❑ Implement your favorite sorting algorithm to sort the array in
alphabetical order.
❑ Print the sorted array to the console.
7
Generics, Part 1
Implement a class named StudentData that has two
generic types.
◼ The first generic type should be called S. Generic type S
must satisfy the requirements of the Comparable
interface for type S.
◼ The second generic type should be called T.
◼ This class should also contain a private field of type S
named gpa and a private field of type T named
studentName.
◼
8
Generics, Part 2 (optional)
◼
Make sure that the first generic type S must also satisfy
the requirements of the Computable interface for type
S.
9