try { Assert(Life. Real); Assert(Life

Slides:



Advertisements
Similar presentations
Object Oriented Programming with Java
Advertisements

CSE 390B: Graph Algorithms Based on CSE 373 slides by Jessica Miller, Ruth Anderson 1.
Slides adapted from Alex Mariakakis, with material from Krysta Yousoufian, Mike Ernst, and Kellen Donohue Section 4: Graphs and Testing.
Java Review Interface, Casting, Generics, Iterator.
Graphs CSC 220 Data Structure. Introduction One of the Most versatile data structures like trees. Terminology –Nodes in trees are vertices in graphs.
GRAPHS Lecture 18 CS2110 – Fall Graph Algorithms 2 Search –depth-first search –breadth-first search Shortest paths –Dijkstra's algorithm Minimum.
Graph Searching CSE 373 Data Structures Lecture 20.
Breadth-First and Depth-First Search
Graph Search Methods Spring 2007 CSE, POSTECH. Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u. A search method.
© 2006 Pearson Addison-Wesley. All rights reserved14 A-1 Chapter 14 excerpts Graphs (breadth-first-search)
Slides adapted from Alex Mariakakis, with material from Krysta Yousoufian, Mike Ernst, Kellen Donohue Section 5: HW6 and Interfaces.
Graphs CS3240, L. grewe.
Advanced Programming in Java
Sadegh Aliakbary Sharif University of Technology Fall 2010.
Lecture 17 Abstract classes Interfaces The Comparable interface Event listeners All in chapter 10: please read it.
Graph Traversals Depth-First Traversal. The Algorithm.
Graph Traversals CSC 172 SPRING 2002 LECTURE 26. Traversing graphs Depth-First Search like a post-order traversal of a tree Breath-First Search Less like.
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.
16-Aug-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming in Java Topic : Interfaces, Copying/Cloning,
CSE 331 Software Design & Implementation Hal Perkins Autumn 2012 Java Classes, Interfaces, and Types 1.
220 FINAL TEST REVIEW SESSION Omar Abdelwahab. INHERITANCE AND POLYMORPHISM Suppose you have a class FunClass with public methods show, tell, and smile.
Implementing Stacks Ellen Walker CPSC 201 Data Structures Hiram College.
Search Related Algorithms. Graph Code Adjacency List Representation:
Tree Searching Breadth First Search Dept First Search.
Chapter 14 Graphs. © 2004 Pearson Addison-Wesley. All rights reserved Terminology G = {V, E} A graph G consists of two sets –A set V of vertices,
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
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.
GRAPHS. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different implementations.
A programmer’s wife tells him, “Would you mind going to the store and picking up a loaf of bread. Also, if they have eggs, get a dozen.” The programmer.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Ver Chapter 13: Graphs Data Abstraction & Problem Solving with C++
Trees, Binary Search Trees, Balanced Trees, Graphs Graph Fundamentals Telerik Algo Academy
Computer Science 209 Software Development Inheritance and Composition.
Lecture Objectives  To understand how Java implements a stack  To learn how to implement a stack using an underlying array or linked list  Implement.
© 2006 Pearson Addison-Wesley. All rights reserved 14 A-1 Chapter 14 Graphs.
Interfaces F What is an Interface? F Creating an Interface F Implementing an Interface F What is Marker Interface?
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
SLIDES ADAPTED FROM ALEX MARIAKAKIS, WITH MATERIAL FROM KRYSTA YOUSOUFIAN, MIKE ERNST, KELLEN DONOHUE Section 5: HW6 and Interfaces Justin Bare and Deric.
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
Justin Bare and Deric Pang with material from Erin Peach, Nick Carney, Vinod Rathnam, Alex Mariakakis, Krysta Yousoufian, Mike Ernst, Kellen Donohue Section.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Graph Traversal Text Weiss, § 9.6 Depth-First Search Think Stack Breadth-First Search Think Queue.
This In Java, the keyword this allows an object to refer to itself. Or, in other words, this refers to the current object – the object whose method or.
Slides with material from Alex Mariakakis, Krysta Yousoufian, Mike Ernst, Kellen Donohue Section 3: HW4, ADTs, and more.
Source: David Lee Matuszek
Graph Searching CSIT 402 Data Structures II. 2 Graph Searching Methodology Depth-First Search (DFS) Depth-First Search (DFS) ›Searches down one path as.
Graph Theory Def: A graph is a set of vertices and edges G={V,E} Ex. V = {a,b,c,d,e} E = {ab,bd,ad,ed,ce,cd} Note: above is a purely mathematical definition.
1 Stacks Abstract Data Types (ADTs) Stacks Application to the analysis of a time series Java implementation of a stack Interfaces and exceptions.
Graphs. What is a graph? In simple words, A graph is a set of vertices and edges which connect them. A node (or vertex) is a discrete position in the.
A programmer’s roommate tells him, “Would you mind going to the store and picking up a loaf of bread. Also, if they have eggs, get a dozen.” The programmer.
Graphs - II CS 2110, Spring Where did David leave that book? 2.
Chapter 13: The Graph Abstract Data Type
Section 5: HW6 and Interfaces
Section 5: HW6 and Interfaces
null, true, and false are also reserved.
Why do Java programmers wear glasses?
Homework 8: Critters (cont.)
Section 7: Dijkstra’s & Midterm Postmortem
OO Design with Inheritance
The programmer returns with 12 loaves of bread.
Section 3 Graphs & Testing
Section 4: Interfaces Parsing Data and
Section 5: HW6 and Interfaces
Section 4: Graphs and Testing
Warmup ["hip","hip"] = Hip Hip Array! ???.
Section 5: HW6 and Interfaces
Presentation transcript:

try { Assert(Life. Real); Assert(Life try { Assert(Life.Real); Assert(Life.Fantasy); } catch(LandSlideException ex) #region Reality while(true) character.Eyes.ForEach(eye => eye.Open().Orient(Direction.Sky).See();); self.Wealth = null; self.Sex = Sex.Male; if(self.ComeDifficulty == Difficulty.Easy && self.GoDifficulty == Difficulty.Easy && self.High < 0.1 && self.Low < 0.1) self.Sympathies.Clear(); switch(wind.Direction) case Direction.North: case Direction.East: case Direction.South: case Direction.West: default: piano.Play(); break; #endregion “Bohemian Rhapsody”

Section 6: HW6 and Interfaces Slides by Alex Mariakakis with material from Krysta Yousoufian, Mike Ernst, Kellen Donohue

Agenda BFS Interfaces Parsing Marvel Data

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” Can also be used for discovery, but not the shortest path

BFS Pseudocode public boolean find(Node start, Node end) { put start node in a queue while (queue is not empty) { pop node N off queue if (N is goal) return true; else { for each node O that is child of N push O onto queue } return false;

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

Breadth-First Search with Cycle Q: <> Q: <A> Q: <B> Q: <C> NEVER DONE A B C

BFS Pseudocode Mark the node as visited! What if there’s a cycle? public boolean find(Node start, Node end) { put start node in a queue while (queue is not empty) { pop node N off queue if (N is goal) return true; else { for each node O that is child of N push O onto queue } return false; Mark the node as visited! What if there’s a cycle? What if there’s no path between start and end?

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

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

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

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

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

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

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

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

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

Shortest Paths with BFS 1 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 E

Shortest Paths with Weights B 2 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 Paths are not the same!

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 Java classes contain both specification and implementation!

Interfaces 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

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 myList) {…}

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 the Marvel data Demo Parsing the Marvel data