Problem of the Day  At low tide, a ship docks in the harbor  Ship is 9’ above the water line when it docks  Over the side hangs a rope ladder w/ rungs.

Slides:



Advertisements
Similar presentations
Objects and Classes Part II
Advertisements

Stacks, Queues, and Linked Lists
COSC 1P03 Data Structures and Abstraction 10.1 The List If A is success in life, then A equals x plus y plus z. Work is x; y is play; and z is keeping.
CS 206 Introduction to Computer Science II 09 / 05 / 2008 Instructor: Michael Eckmann.
Binary Trees Chapter 6. Linked Lists Suck By now you realize that the title to this slide is true… By now you realize that the title to this slide is.
COMP 121 Week 11: Linked Lists. Objectives Understand how single-, double-, and circular-linked list data structures are implemented Understand the LinkedList.
LECTURE 38: ORDERED DICTIONARY CSC 212 – Data Structures.
Problem of the Day  At low tide, a ship docks in the harbor  Ship is 9’ above the water line when it docks  Over the side hangs a rope ladder w/ rungs.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
Searching Chapter Chapter Contents The Problem Searching an Unsorted Array Iterative Sequential Search Recursive Sequential Search Efficiency of.
CSC 213 – Large Scale Programming Lecture 14: Sequence-based Priority Queues.
Comparing Objects in Java. The == operator When you define an object, for instance Person p = new Person("John", 23); we talk about p as if its value.
Week 3 - Wednesday.  What did we talk about last time?  Started linked lists.
Describing algorithms in pseudo code To describe algorithms we need a language which is: – less formal than programming languages (implementation details.
Set, TreeSet, TreeMap, Comparable, Comparator. Def: The abstract data type set is a structure that holds objects and satifies ARC: Objects can be added.
Problem Of The Day  Decipher the following phrase: STANDS 0 _
CSC 213 – Large Scale Programming. Today’s Goal  Consider what will be important when searching  Why search in first place? What is its purpose?  What.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Problem of the Day  What do you get when you cross a mountain climber and a grape?
Recap (önemli noktaları yinelemek) from last week Paradigm Kay’s Description Intro to Objects Messages / Interconnections Information Hiding Classes Inheritance.
JAVA COLLECTIONS LIBRARY School of Engineering and Computer Science, Victoria University of Wellington COMP T2, Lecture 2 Marcus Frean.
(c) University of Washington14-1 CSC 143 Java Collections.
Problem of the Day  At low tide, a ship docks in the harbor  Ship is 9’ above the water line when it docks  Over the side hangs a rope ladder w/ rungs.
Recursion l Powerful Tool l Useful in simplifying a problem (hides details of a problem) l The ability of a function to call itself l A recursive call.
LECTURE 37: ORDERED DICTIONARY CSC 212 – Data Structures.
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Question of the Day  On a game show you’re given the choice of three doors: Behind one door is a car; behind the others, goats. After you pick a door,
Some Other Collections: Bags, Sets, Queues and Maps COMP T2 Lecture 4 School of Engineering and Computer Science, Victoria University of Wellington.
Data Design and Implementation. Definitions of Java TYPES Atomic or primitive type A data type whose elements are single, non-decomposable data items.
Data structures Abstract data types Java classes for Data structures and ADTs.
LINKED LISTS Linear Linked List. November 1, 2005Linked Lists2 of 48 Linked Lists Like stacks and queues, linked lists are lists of nodes that point to.
ADT ITEC 320 Lecture 22. ADT Review Generic lists –Ada compilation workout Recursive algorithms –What would a recursive copy look like? Project 4 is up.
Built-in Data Structures in Python An Introduction.
LECTURE 34: MAPS & HASH CSC 212 – Data Structures.
CSC 212 – Data Structures Lecture 37: Course Review.
Comparison-Based Sorting & Analysis Smt Genap
C++ Programming: From Problem Analysis to Program Design, Second Edition Chapter 17: Linked Lists.
CSC 212 – Data Structures Lecture 17: Stacks. Question of the Day Move one matchstick to produce a square.
Week 8 - Monday.  What did we talk about last time?  BST traversals  Get range implementation.
1 Heaps and Priority Queues v2 Starring: Min Heap Co-Starring: Max Heap.
CSC 212 – Data Structures Lecture 26: Hash Tables.
Problem of the Day  Simplify this equation: (x - a) * (x - b) * (x - c) * … * (x - z)
This recitation 1 An interesting point about A3: Using previous methods to avoid work in programming and debugging. How much time did you spend writing.
COMP 121 Week 11: Linked Lists.
CSC 212 Trees & Recursion. Announcements Midterm grades were generally good  Wide distributions of scores, however  Will hand back at end of class 
CSC 212 Sequences & Iterators. Announcements Midterm in one week  Will cover through chapter 5 of book  Midterm will be open book, open note (but, closed.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
Interfaces and Inner Classes
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
Jeremy Quilter EDUC 533.  If the hour hand on a clock moves 1/60 th of a degree every minute then how many degrees will the hour hand move in one hour?
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Lecture 8: Advanced OOP Part 2. Overview Review of Subtypes Interfaces Packages Sorting.
CSC 212 – Data Structures Lecture 31: Last Word On Dictionaries.
Question of the Day  What three letter word completes the first word and starts the second one: DON???CAR.
Week 7 - Wednesday.  What did we talk about last time?  Recursive running time  Master Theorem  Symbol tables.
Topic 13 Iterators. 9-2 Motivation We often want to access every item in a data structure or collection in turn We call this traversing or iterating over.
CSC Programming for Science Lecture 27: Arrays as Parameters, Searching, & Sorting.
Question of the Day  What three letter word completes the first word and starts the second one: DON???CAR.
Problem of the Day  Can you move exactly one glass to arrange the glasses containing orange juice to be next to one another?
Day 3: The Command and Visitor Patterns. Preliminaries The Java static type system uses simple rules to infer types for Java expressions. The inferred.
Problem of the Day  Simplify this equation: (x - a) * (x - b) * (x - c) * … * (x - z)
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
COMP 103 Maps and Queues. RECAP  Iterators (for-each loop)  Bag, Sets, and Stacks - a class, not interface TODAY  Maps and Queues 2 RECAP-TODAY QUICK.
List Structures What is a list? A homogeneous collection of elements with a linear relationship between the elements linear relationship - each element.
CSC 243 – Java Programming, Fall, 2008 Tuesday, September 30, end of week 5, Interfaces, Derived Classes, and Abstract Classes.
Abstract Data Types in C
CMSC 341 Lecture 13 Leftist Heaps
Chapter 16 Linked Structures
Lexical Ordering and Sorting
Presentation transcript:

Problem of the Day  At low tide, a ship docks in the harbor  Ship is 9’ above the water line when it docks  Over the side hangs a rope ladder w/ rungs 1’ apart  Tide rises at a rate of 9” per hour After 6 hours what length of ladder will still be above water?

Problem of the Day  At low tide, a ship docks in the harbor  Ship is 9’ above the water line when it docks  Over the side hangs a rope ladder w/ rungs 1’ apart  Tide rises at a rate of 9” per hour After 6 hours what length of ladder will still be above water? 9’ – the ladder will rise with the boat!

CSC 212 – Data Structures

Problem With Position  Really, really limited in how it can be used  Provides way of holding & accessing an element  No way to use element with a Position  Great for keeping unorganized lists of information  Sucks for anything else like: Keeping a list whose data is automatically sorted Searching for something within huge collection Use data for analysis by linking related items Prioritizing items to stay up-to-date on demands

How Much Info Can You Get?

How Do We Organize Data?

Key Key To How We Organize Data

Entry To The Rescue  Entry provides 2 items to view & use data valu(e)  Preserves keeping the valu(e)able data we care about  Key  Key detail used to organize valuables also maintained

Entry To The Rescue  Entry provides 2 items to view & use data valu(e)  Preserves keeping the valu(e)able data we care about  Key  Key detail used to organize valuables also maintained interface Entry { K key(); V value(); }

KeyValue What’s The Key & Value?

Comparable Interface  Provides simple, abstract way to compare data  Found in java.lang package just like Iterable  Makes coding easier by simplifying search & compare  Total ordering relation needed to implement exactly one  Must be exactly one of a b  If a < b & b < c then a < c implied by this definition

Comparable Interface  Single method defined by Comparable int compareTo(E o)  Compare this instance with o (ther) instance  The only thing that matters is relative value returned  Specific value meaningless & only defines result is: negative zero positive negative if this o

Comparable Example positive 0 negative class Student implements Comparable { private float qpa;... public int compareTo(Student other) { if (qpa > other.qpa) { // Need to return positive number here return 73; } else if (qpa == other.qpa) { // Need to return 0 in this case return 0; } else { // Need to return negative number here return ; } }

Using Comparable Student match(float grade, Iterable it){ Student seeker = new Student(); seeker.setQPA(grade); for (Student s : it) { if (seeker.compareTo(s) == 0) { return s; } } // Prof. Idiot forgot to define Exception for this unexpected event, so… return null; }

What Does compareTo() Match?

And Your Reaction Should Be…

 NHL team class can only have 1 compareTo  But many ways to compare and rank teams

And Your Reaction Should Be…  NHL team class can only have 1 compareTo  But many ways to compare and rank teams  Is writing specific case-by-case code our fate?

Comparator to the Rescue!  Can also use Comparator s to compare data  Interface in java.util package (like Iterator )  Like Iterator, is separate class performing work  Comparator defines single method int compare(E o1, E o2)  Specific value meaningless; result defined by: negative zero positive negative if o1 o2

positive 0 negative class WinComp implements Comparator public int compare(NHLTeam o1, NHLTeam o2) { if (o1.getWins() > o2.getWins()) { return 42; // Need to return positive number here } else if (o1.getWins() == o2.getWins()) { return 0; // Need to return 0 in this case } else { return -68; // Need to return negative number here } } class PointsComp implements Comparator public int compare(NHLTeam o1, NHLTeam o2) { return (o1.getPoints() - o2.getPoints()); } } Comparator Example

Using Comparator int rank(NHLTeam team, Comparator comp, Iterable it){ int count = 1; for (NHLTeam goons : it) { if (comp.compare(team, goons) < 0) { count++; } } // Rank of the given team for this metric return count; }

Your Turn  Get into your groups and complete activity

For Next Lecture  Read GT – for Friday's lecture  What is a PriorityQueue and what does it do?  Queue sounds familiar; is there any relationship?  How can I link Marx, Orwell, & Homer Simpson?  Week #14 assignment posted & due Tuesday  Programming Assignment #3  Programming Assignment #3 due next Friday