CS 2430 Object Oriented Programming and Data Structures I

Slides:



Advertisements
Similar presentations
Data Structures A data structure is a collection of data organized in some fashion that permits access to individual elements stored in the structure This.
Advertisements

CS 2430 Day 28. Announcements We will have class in ULR 111 on Monday Exam 2 next Friday (sample exam will be distributed next week)
CSCA48 Course Summary.
Information and Computer Sciences University of Hawaii, Manoa
Information and Computer Sciences University of Hawaii, Manoa
Final Exam Tuesday, December 22nd 2:00 - 3:50pm room 102 Warren Weaver Hall.
Lecture 8: Advanced OOP Part 2. Overview Review of Subtypes Interfaces Packages Sorting.
Week 15 – Monday.  What did we talk about last time?  Tries.
COMPUTER 2430 Object Oriented Programming and Data Structures I
Sort & Search Algorithms
The List ADT.
Computing with C# and the .NET Framework
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
Data Structures I (CPCS-204)
Week 4 - Friday CS221.
Chapter 5 Ordered List.
Recitation 13 Searching and Sorting.
COMPUTER 2430 Object Oriented Programming and Data Structures I
Exam Hints.
Chapter 7 Single-Dimensional Arrays
Week 15 – Monday CS221.
COMPUTER 2430 Object Oriented Programming and Data Structures I
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
Top Ten Words that Almost Rhyme with “Peas”
Lecture 1: Welcome to CSE 373
structures and their relationships." - Linus Torvalds
COMPUTER 2430 Object Oriented Programming and Data Structures I
Topic 14 Searching and Simple Sorts
THURSDAY, OCTOBER 17 IN LAB
Lecture 2: Implementing ADTs
Building Java Programs
Chapter 5 Ordered List.
COMPUTER 2430 Object Oriented Programming and Data Structures I
COMPUTER 2430 Object Oriented Programming and Data Structures I
COMPUTER 2430 Object Oriented Programming and Data Structures I
CS 2430 Object Oriented Programming and Data Structures I
searching Concept: Linear search Binary search
ITEC 2620M Introduction to Data Structures
CSE 373: Data Structures and Algorithms
COMPUTER 2430 Object Oriented Programming and Data Structures I
COMPUTER 2430 Object Oriented Programming and Data Structures I
CSE 373 Data Structures and Algorithms
CSE 373: Data Structures and Algorithms
Introduction to Computer Science for Majors II
Implementing Hash and AVL
COMPUTER 2430 Object Oriented Programming and Data Structures I
Searching and Sorting Topics Sequential Search on an Unordered File
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
Searching CLRS, Sections 9.1 – 9.3.
COMPUTER 2430 Object Oriented Programming and Data Structures I
COMPUTER 2430 Object Oriented Programming and Data Structures I
Building Java Programs
Topic 14 Searching and Simple Sorts
Figure 7.1 Some queue operations. Figure 7.1 Some queue operations.
Topic 24 sorting and searching arrays
COMPUTER 2430 Object Oriented Programming and Data Structures I
Review CSE116 2/21/2019 B.Ramamurthy.
COMPUTER 2430 Object Oriented Programming and Data Structures I
COMPUTER 2430 Object Oriented Programming and Data Structures I
Review B.Ramamurthy 4/6/2019 BR.
COMPUTER 2430 Object Oriented Programming and Data Structures I
COMPUTER 2430 Object Oriented Programming and Data Structures I
Jeff West - Quiz Section 16
Sum this up for me Let’s write a method to calculate the sum from 1 to some n public static int sum1(int n) { int sum = 0; for (int i = 1; i
Lecture 4: Introduction to Code Analysis
Final Review B.Ramamurthy 5/8/2019 BR.
Instructor: Dr. Michael Geiger Spring 2019 Lecture 34: Exam 3 Preview
Data Structures Using C++ 2E
structures and their relationships." - Linus Torvalds
COMPUTER 2430 Object Oriented Programming and Data Structures I
Presentation transcript:

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!