Section 5: HW6 and Interfaces

Slides:



Advertisements
Similar presentations
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 excerpts Graphs (breadth-first-search)
Advertisements

CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
try { Assert(Life. Real); Assert(Life
Slides adapted from Alex Mariakakis, with material from Krysta Yousoufian, Mike Ernst, Kellen Donohue Section 5: HW6 and Interfaces.
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Graphs & Graph Algorithms Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
CS 206 Introduction to Computer Science II 03 / 30 / 2009 Instructor: Michael Eckmann.
CISC220 Fall 2009 James Atlas Nov 13: Graphs, Line Intersections.
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Java Classes, Interfaces, and Types 1.
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
Implementing Stacks Ellen Walker CPSC 201 Data Structures Hiram College.
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
Graphs. Made up of vertices and arcs Digraph (directed graph) –All arcs have arrows that give direction –You can only traverse the graph in the direction.
COMP261 Lecture 6 Dijkstra’s Algorithm. Connectedness Is this graph connected or not? A Z FF C M N B Y BB S P DDGG AA R F G J L EE CC Q O V D T H W E.
CS 61B Data Structures and Programming Methodology July 2, 2008 David Sun.
Interfaces F What is an Interface? F Creating an Interface F Implementing an Interface F What is Marker Interface?
SLIDES ADAPTED FROM ALEX MARIAKAKIS, WITH MATERIAL FROM KRYSTA YOUSOUFIAN, MIKE ERNST, KELLEN DONOHUE Section 5: HW6 and Interfaces Justin Bare and Deric.
Justin Bare and Deric Pang with material from Erin Peach, Nick Carney, Vinod Rathnam, Alex Mariakakis, Krysta Yousoufian, Mike Ernst, Kellen Donohue Section.
CS Prelim Review – 10/15/09  First prelim is TOMORROW at 7:30 PM  Review session – Tonight 7:30 PM, Phillips 101  Things you should do:  Review every.
Slides with material from Alex Mariakakis, Krysta Yousoufian, Mike Ernst, Kellen Donohue Section 3: HW4, ADTs, and more.
Graphs - II CS 2110, Spring Where did David leave that book? 2.
Review Graph Directed Graph Undirected Graph Sub-Graph Spanning Sub-Graph Degree of a Vertex Weighted Graph Elementary and Simple Path Link List Representation.
CSC 172 DATA STRUCTURES.
Graphs and Graph Algorithms
Section 7: Dijkstra’s Justin Bare and deric Pang
Section 4: Graphs and Testing
CS Data Structures Chapter 6 Stacks Mehmet H Gunes
OOP: Encapsulation &Abstraction
Graphs Chapter 20.
Graphs Chapter 15 introduces graphs which are probably the most general and commonly-used data structure. This lecture introduces heaps, which are used.
A vertex u is reachable from vertex v iff there is a path from v to u.
Chapter 13: The Graph Abstract Data Type
Csc 2720 Instructor: Zhuojun Duan
Ellen Walker CPSC 201 Data Structures Hiram College
CC 215 Data Structures Graph Searching
Depth First Search—Backtracking
Section 5: HW6 and Interfaces
CS120 Graphs.
Data Structures and Algorithms for Information Processing
Comp 245 Data Structures Graphs.
Graph.
Paul Ammann & Jeff Offutt
Why do Java programmers wear glasses?
What do you call 8 Hobbits?
Graphs Chapter 13.
Breadth First Search 11/21/ s
Graph Traversals Depth-First Traversals. Algorithms. Example.
Section 7: Dijkstra’s & Midterm Postmortem
Tree Searching.
CSE 373 Data Structures Lecture 16
Section 3 Graphs & Testing
Section 4: Interfaces Parsing Data and
Section 5: HW6 and Interfaces
COMP171 Depth-First Search.
Section 4: Graphs and Testing
Breadth First Search s
Depth-First Search CSE 2011 Winter April 2019.
Warmup ["hip","hip"] = Hip Hip Array! ???.
Section 5: HW6 and Interfaces
A vertex u is reachable from vertex v iff there is a path from v to u.
Graphs.
Graphs.
Breadth First Search s
Graphs.
Chapter 14 Graphs © 2011 Pearson Addison-Wesley. All rights reserved.
Applications of BFS CSE 2011 Winter /17/2019 7:03 AM.
Graphs.
Graph Search in C++ Andrew Lindsay.
Presentation transcript:

Section 5: HW6 and Interfaces SLIDES ADAPTED FROM ALEX MARIAKAKIS, WITH MATERIAL FROM KRYSTA YOUSOUFIAN, MIKE ERNST, KELLEN DONOHUE

How is Homework 5 going?

Agenda Reminders Breadth-first search (BFS) Interfaces HW 5 due tomorrow night (4/27) Midterm on Monday (4/30) Breadth-first search (BFS) Interfaces Parsing Marvel Data

Reminders: Expensive CheckReps are BAD Debug flags are GOOD (at least when assignments are turned in, but can be useful for finding hard-to-discover problems – so need to be able to control expensive checks) Debug flags are GOOD (or enums to indicate depth of debug)

Don’t forget your CheckReps!

Graphs B A Can I reach B from A? C D E

Breadth-First Search (BFS) Often used for discovering connectivity Calculates the shortest path if and only if all edges have same positive or no weight Depth-first search (DFS) is commonly mentioned with BFS BFS looks “wide”, DFS looks “deep” DFS can also be used for discovery, but not the shortest path

BFS Pseudocode put start node in a queue while (queue is not empty): pop node N off queue mark node N as visited if (N is goal): return true else: for each node O that is child of N: if O is not marked visit push O onto queue return false

Breadth-First Search START: Starting at A Q: <A> Goal: Fully explore Pop: A, Q: <> Q: <B, C> Pop: B, Q: <C> Q: <C> Pop: C, Q: <C> Q: <> DONE A B C

Breadth-First Search with Cycle START: Starting at A Q: <A> Goal: Fully Explore Pop: A, Q: <> Q: <B> Pop: B, Q: <> Q: <C> Pop: C, Q: <> Q: <A> NEVER DONE A B C

Mark the node as visited! BFS Pseudocode Mark the node as visited! put start node in a queue while (queue is not empty): pop node N off queue mark node N as visited if (N is goal): return true else: for each node O that is child of N: if O is not marked visited: push O onto queue return false

Breadth-First Search Q: <> Problem: Find everything reachable from A Q: <> B A C D E

Breadth-First Search Q: <> Q: <A> B A C D E

Breadth-First Search Q: <> Q: <A> B A C D E

Breadth-First Search Q: <> Q: <A> Q: <C> B A C D E

Breadth-First Search Q: <> Q: <A> Q: <C> Q: <C ,D> B A C D E

Breadth-First Search Q: <> Q: <A> Q: <C> Q: <C ,D> Q: <D> B A C D E

Breadth-First Search Q: <> Q: <A> Q: <C> Q: <C ,D> Q: <D> Q: <D, E> B A C D E

Breadth-First Search Q: <> Q: <A> Q: <C> Q: <C ,D> Q: <D> Q: <D, E> Q: <E> B A C D E

Breadth-First Search Q: <> Q: <A> Q: <C> Q: <C ,D> Q: <D> Q: <D, E> Q: <E> DONE B A C D E

Shortest Paths with BFS 1 B From Node B A Destination Path Cost A <B,A> 1 B <B> C <B,A,C> 2 D E 1 1 1 C 1 D 1 1 Shortest path to D? to E? What are the costs? E

Shortest Paths with BFS 1 B From Node B A Destination Path Cost A <B,A> 1 B <B> C <B,A,C> 2 D <B,D> E <B,D,E> 1 1 1 C 1 D 1 1 Shortest path to D? to E? What are the costs? E

Shortest Paths with Weights 2 B From Node B A Destination Path Cost A <B,A> 2 B <B> C <B,A,C> 5 D E 100 100 3 C 2 D 2 6 Weights are not the same! Are the paths? E

Shortest Paths with Weights 2 B From Node B A Destination Path Cost A <B,A> 2 B <B> C <B,A,C> 5 D <B,A,C,D> 7 E <B,A,C,E> 100 100 3 C 2 D 2 6 E

Interfaces

Classes, Interfaces, and Types The fundamental unit of programming in Java is a class Classes can extend other classes and implement interfaces Interfaces can extend other interfaces

Classes, Objects, and Java Everything is an instance of a class Defines data and methods Every class extends exactly one other class Object if no explicit superclass Inherits superclass fields Every class also defines a type Foo defines type Foo Foo inherits all inherited types

Interfaces int compareTo(Object other); } Pure type declaration public interface Comparable { int compareTo(Object other); } Can contain: Method specifications (implicitly public abstract) Named constants (implicitly public final static) Does not contain implementation! Cannot create instances of interfaces (Interfaces are a skeleton)

Implementing Interfaces A class can implement one or more interfaces class Kitten implements Pettable, Huggable The implementing class and its instances have the interface type(s) as well as the class type(s) The class must provide or inherit an implementation of all methods defined by the interface(s) Not true for abstract classes

Using Interface Types An interface defines a type, so we can declare variables and parameters of that type A variable with an interface type can refer to an object of any class implementing that type List<String> x = new ArrayList<String>(); void sort(List aList) {…}

Guidelines for Interfaces Provide interfaces for significant types and abstractions Write code using interface types like Map instead of HashMap and TreeMap wherever possible Allows code to work with different implementations later on Both interfaces and classes are appropriate in various circumstances

Parsing Marvel Data Parsing is already implemented for you! Data is in marvel.tsv Will be pushed with hw6 Each line is in the form: "character" "book” Ex: "CAPTAIN AMERICA" "N 57” Parsing is already implemented for you! MarvelParser.parseData() Returns Map of Character -> List of Books they’re in