CS 2430 Object Oriented Programming and Data Structures I Day1 on Thursday, before lab1
Test 3 Complete the following phases for LSP Require no more Require Less Promise no less Promise More
Test 3 Sorting Index 1 2 3 4 5 6 7 Array 8 Bubble Selection Insertion
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
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
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
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
Test 3 Finding a target in a sorted array O(Log N) Linear Search or Binary Search?
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
Test 3 The total number of times Test3 is called: (N+1) + N + (N-1) + . . . + 4 + 3 + 2 = 2 + 3 + 4 + . . . + (N-1) + N + (N+1) = (2 + (N+1)) * ((N+1) – 2 + 1) / 2 = (N+3) * (N) / 2 = (N2 + 3N) / 2
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 0 899 What are low, high and mid? Index! 11 11 11
// 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!
// 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!
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 0 899 449 448 224 225 336 335 280 281 308 307 294 14 14 14
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
Final Exam True/False Fill blank Coding Counting Tracing Sorting Binary search Hashing
Object Oriented Programming ADT (Abstract Data Type) Data Hiding (Data Encapsulation) Inheritance Interface Polymorphism LSP
Object Oriented Programming Class and Instance Reference and Object Run Time Binding Generic Class/Interface Garbage collection
Object Oriented Programming JUnit Testing Test-Bed Main Testing System Testing
Java GUI Programming
Data Structures Containers Stack Queue Circular Array (Linked List)
Algorithms and Big O Prefix and Postfix Sorting Binary Search Hashing Counting
Examples Date Student Complex Golfer FixedPoint . . .
Iterator Try it for Prog3 Regular array Circular array
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; } @Override public boolean hasNext() return index < theList.num; public FixedPoint next() return theList.list[index ++];
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()
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);
All are in D2L Let me know of any issues Your Scores and Grades All are in D2L Let me know of any issues
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
Please Fill out the Course Outcome Survey!