Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 2430 Object Oriented Programming and Data Structures I

Similar presentations


Presentation on theme: "CS 2430 Object Oriented Programming and Data Structures I"— Presentation transcript:

1 CS 2430 Object Oriented Programming and Data Structures I
Day1 on Thursday, before lab1

2 Test 3 Complete the following phases for LSP Require no more
Require Less Promise no less Promise More

3 Test 3 Sorting Index 1 2 3 4 5 6 7 Array 8 Bubble Selection Insertion

4 Test 3 h1(key) = key % 13 h2(key) = 1 + key % 11 Key 59 46 20 45 32 19
18 57 70 h1(key) 7 6 5 h2(key) 3 10 2 11 9 8

5 Linear Probe h1(key) = key % 13 ( h2(key) = 1 + key % 11 ) Key 59 46
20 45 32 19 18 57 70 h1(key) 7 6 5 h2(key) 3 10 2 11 9 8 1 2 3 4 5 6 7 8 9 10 11 12 70 18 45 59 46 20 32 19 57

6 Double Hashing h1(key) = key % 13 h2(key) = 1 + key % 11 Key 59 46 20
45 32 19 18 57 70 h1(key) 7 6 5 h2(key) 3 10 2 11 9 8 1 2 3 4 5 6 7 8 9 10 11 12 32 20 18 45 59 57 46 19 70

7 Test 3 Finding a target in an un-sorted array O(N)
Finding a target in a sorted array O(Log N) Selection Sort O(N2) Queue add method of circular array implementation O(1) Adding into a sorted array and maintaining order Computing the average

8 Test 3 Finding a target in a sorted array O(Log N)
Linear Search or Binary Search?

9 Test 3 Pass I First of J Last of J # of calls 3 4 5 . N N+1 N+2 N+5 .
for (int I = 3; I < N + 3; I ++) for (int J = (N + 5); J >= (I + 2); J --) Test3(); The total number of times Test3 is called: ___________________ Pass I First of J Last of J # of calls 3 4 5 . N N+1 N+2 N+5 . 5 6 7 . N+2 N+3 N+4 N+1 N N-1 . 4 3 2

10 Test 3 The total number of times Test3 is called: (N+1) + N + (N-1) = (N-1) + N + (N+1) = (2 + (N+1)) * ((N+1) – 2 + 1) / 2 = (N+3) * (N) / 2 = (N2 + 3N) / 2

11 Array items[] has 900 values and sorted in descending order
Array items[] has 900 values and sorted in descending order. Binary search is used to find a target. Tracing the execution assuming the target is at index 294. low mid high What are low, high and mid? Index! 11 11 11

12 // Ascending Order public class SortedList { private Comparable [] items; private int count; public int BinarySearch(Comparable x) int lo = 0, hi = count - 1; while ( lo <= hi ) int mid = ( lo + hi ) / 2; int result = items[mid].CompareTo(x); if ( result == 0 ) return mid; if ( result > 0 ) hi = mid - 1; else lo = mid + 1; } return -1; ..... Quiz is coming? Program due!

13 // Descending Order public class SortedList { private Comparable [] items; private int count; public int BinarySearch(Comparable x) int lo = 0, hi = count - 1; while ( lo <= hi ) int mid = ( lo + hi ) / 2; int result = items[mid].CompareTo(x); if ( result == 0 ) return mid; if ( result > 0 ) lo = mid + 1; // hi = mid - 1; else hi = mid - 1; // lo = mid + 1; } return -1; ..... Quiz is coming? Program due!

14 Array items[] has 900 values and sorted in descending order
Array items[] has 900 values and sorted in descending order. Binary search is used to find a target. Tracing the execution assuming the target is at index 294. low mid high 14 14 14

15

16

17 Scratch Papers Not Needed
Final Exam Thursday, Dec 20 7:00 – 8:50 pm Velzy Commons, Ullsvik Comprehensive Close Notes No Calculators Scratch Papers Not Needed

18 Final Exam True/False Fill blank Coding Counting Tracing Sorting
Binary search Hashing

19 Object Oriented Programming
ADT (Abstract Data Type) Data Hiding (Data Encapsulation) Inheritance Interface Polymorphism LSP

20 Object Oriented Programming
Class and Instance Reference and Object Run Time Binding Generic Class/Interface Garbage collection

21 Object Oriented Programming
JUnit Testing Test-Bed Main Testing System Testing

22 Java GUI Programming

23 Data Structures Containers Stack Queue Circular Array (Linked List)

24 Algorithms and Big O Prefix and Postfix Sorting Binary Search Hashing
Counting

25 Examples Date Student Complex Golfer FixedPoint . . .

26 Iterator Try it for Prog3 Regular array Circular array

27 public class FixedPointList { private FixedPoint[] list = new FixedPoint[GROWBY]; private int num = 0; // regular array public static class MyIterator implements Iterator<FixedPoint> private FixedPointList theList; private int index; public MyIterator(FixedPointList list) theList = list; index = 0; public boolean hasNext() return index < theList.num; public FixedPoint next() return theList.list[index ++];

28 private Object [] elements;
public class Queue { private Object [] elements; private int front, rear, count; // circular array public static class QueueIterator implements Iterator private Queue theQueue; private int index; // index of the next object // more data fields? public QueueIterator ( Queue queue ) theQueue = queue; index = ??? } @Override public boolean hasNext() return ??? public Object next()

29 public class Final { private static Queue myQueue = new Queue(1000);
public class Final { private static Queue myQueue = new Queue(1000); private static void sumCmd() Queue.QueueIterator iterator = new Queue.QueueIterator(myQueue); FixedPoint fp, sum = new FixedPoint(0.0, curQ); while(iterator.hasNext()) fp = (FixedPoint)iterator.next(); sum = sum.plus(fp, curQ); } System.out.println("The sum is: " + fp);

30 All are in D2L Let me know of any issues
Your Scores and Grades All are in D2L Let me know of any issues

31 Prog 6 Demo An appointment with me in Outlook My Home Page: click here
20 minutes 9 am – 11:40 am, 2 pm – 3:40 pm Make appointment by 11 pm, Monday, Dec. 17 Last demo: 3:40 pm, Thursday, December 20 My Home Page: click here

32 Please Fill out the Course Outcome Survey!


Download ppt "CS 2430 Object Oriented Programming and Data Structures I"

Similar presentations


Ads by Google