COMPUTER 2430 Object Oriented Programming and Data Structures
COMPUTER 2430 Object Oriented Programming and Data Structures I 1
Expected Learning Outcomes 1. Develop software using elementary data structures. 2. Design, implement, and test programs using classes, inheritance, and polymorphism. 3. Compare and contrast algorithm efficiency at a very basic level. 4. Write module tests, system tests, and develop test specifications. 5. Perform simple object-oriented analysis and design. 6. Work in a small team (two or three people) on the analysis, design, implementation, and testing of a project. 2
Quiz 5 What is the Big O for each of the following: 1. Deleting from a regular array and keep the order O(N) for (int i = index; i < count – 1; i ++) items[i] = items[i + 1]; count --; 3
Quiz 5 What is the Big O for each of the following: 2. The Queue method remove of circular array implementation O(1) Object obj = items[front]; front = (front + 1) % items. length; return obj; 4
Quiz 5 What is the Big O for each of the following: 3. Finding the sum of a list of numbers O(N) int sum = 0; for (int i = 0; i < count; i ++) sum += items[i]; 5
Quiz 5 What is the Big O for each of the following: 3. Finding the sum of a list of Additive instances O(N) Additive sum = new Additive(); for (int i = 0; i < count; i ++) sum = sum. plus(items[i]); 6
Quiz 5 What is the Big O for each of the following: 4. Insertion Sort, average case O(N 2) for i = 1 to (size - 1) j = i while j > 0 and a[j] < a[j - 1] Swap a[j], a[j - 1] j -- 7
Quiz 5 for I = (N + 4) downto 2 for J = (I - 2) to (N + 5) if --The total number of times “if” is executed is: __________ 8
Two Formulas • How Many last – first + 1 • What is the sum? (first + last) * (number of items) / 2 9
How Many? last – first + 1 first – last + 1 1 + 2 + 3 +. . . + 10 20 + 19 + 18 +. . . + 5 + 4 + 3 3 + 4 + 5 +. . . + 18 + 19 + 20 10
What is the Sum? s = 20 + 19 +. . . + 4 + 3 s= 3 + 4 +. . . + 19 + 20 2*s = (20 + 3) + (19 + 4) +. . . + (4+19) + (3 +20) = (first + last) * (number of items) s = (first + last) * (first – last + 1) / 2 11
Quiz 5 for I = (N + 4) downto 2 for J = (I - 2) to (N + 5) if --The total number of times “if” is executed is: __________ Pass I First of J Last of J # of Comparisons N+4 N+3 N+2. 4 3 2 N+1 N. 2 1 0 N+5 N+5 4 5 6. N+4 N+5 N+6 12
Quiz 5 for I = (N + 4) downto 2 for J = (I - 2) to (N + 5) if --The total number of times “if” is executed is: __________ 4 + 5 + 6 +. . . + (N+4) + (N+5) + (N+6) = (4 + (N+6)) * ((N+6) – 4 + 1) / 2 = (N+10) * (N+3) / 2 = (N 2 + 13 N + 30) / 2 13
Quiz 5: Sorting a. Bubble Sort, 3 rd iteration (I = 0, 1, 2) 7 1 6 5 2 8 3 4 1 7 2 6 5 3 8 4 1 2 7 3 6 5 4 8 1 2 3 7 4 6 5 8 I=0 I=1 I=2 14
Quiz 5: Sorting b. Insertion Sort, 3 rd iteration (I = 1, 2, 3) 7 1 6 5 2 8 3 4 1 7 6 5 2 8 3 4 1 6 7 5 2 8 3 4 1 5 6 7 2 8 3 4 I=1 I=2 I=3 15
Quiz 5: Sorting c. Selection Sort, 3 rd iteration (I = 0, 1, 2) 7 1 6 5 2 8 3 4 1 7 6 5 2 8 3 4 1 2 6 5 7 8 3 4 1 2 3 5 7 8 6 4 I=0 I=1 I=2 16
Binary Search • Code – Array of integers – Array of Date – Array of Comparable • Tracing – In array – Not in array – Format 17
Quiz 6 • • Wednesday Binary search Hashing Counting 18
Expected Learning Outcomes 1. Develop software using elementary data structures. 2. Design, implement, and test programs using classes, inheritance, and polymorphism. 3. Compare and contrast algorithm efficiency at a very basic level. 4. Write module tests, system tests, and develop test specifications. 5. Perform simple object-oriented analysis and design. 6. Work in a small team (two or three people) on the analysis, design, implementation, and testing of a project. 19
Prog 6 • Must use PFigure as is – It’s different from Pfig of Lab 12 • Minimum of three sub-classes from Pfigure – One drawing and one picture • Must make and use a PFigure. List – Containing instances from at least two sub-classes – Polymorphism! • Move cannot just left-right, up-down, or bounce 20
SE Tool • Time plan – Monday, Dec 3, by 11 pm • Time Log – Punch in/out when working on Prog 6 21
Prog 6 Group folders 22
Counting Exercise 23
- Slides: 23