hw6, BFS, debugging CSE 331 Section 5 10/25/12 Slides by Kellen Donohue

Similar documents
Section 2: Developer tools and you. Alex Mariakakis (staff-wide)

SECTION 2: HW3 Setup.

SECTION 2: Loop Reasoning & HW3 Setup

SECTION 2: Loop Reasoning & HW3 Setup

A Tutorial for ECE 175

Section 4: Graphs and Testing. Slides by Erin Peach and Nick Carney

Programming Logic - Beginning

Lab 4: Imperative & Debugging 12:00 PM, Feb 14, 2018

The NetBeans IDE is a big file --- a minimum of around 30 MB. After you have downloaded the file, simply execute the file to install the software.

Under the Debug menu, there are two menu items for executing your code: the Start (F5) option and the

Section 5: HW6 and Interfaces. Slides adapted from Alex Mariakakis, with material from Krysta Yousoufian, Mike Ernst, Kellen Donohue

Introduction to Computation and Problem Solving

1.00 Lecture 2. What s an IDE?

Supplement: Visual C++ Debugging

Testing, Debugging, Program Verification

CSE 374 Programming Concepts & Tools

GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial

Lab 8 - Vectors, and Debugging. Directions

Lecture 5 Abstract Data Types

Project #1 Seamcarve

MEDIA COMPUTATION DRJAVA. Lecture 11.3 November 7, 2008

CSCI0330 Intro Computer Systems Doeppner. Lab 02 - Tools Lab. Due: Sunday, September 23, 2018 at 6:00 PM. 1 Introduction 0.

Laboratory Assignment #4 Debugging in Eclipse CDT 1

Access Intermediate

Chapter 12 Visual Program Debugger

Lecture 16: HashTables 10:00 AM, Mar 2, 2018

Exam Review. CSE 331 Section 10 12/6/12. Slides by Kellen Donohue with material from Mike Ernst

Access Intermediate

C++ for Everyone, 2e, Cay Horstmann, Copyright 2012 John Wiley and Sons, Inc. All rights reserved. Using a Debugger WE5.

Project #1 Seamcarve

Software Engineering Testing and Debugging Debugging

Lecture 5: Implementing Lists, Version 1

The class Object. Lecture CS1122 Summer 2008

Today s Topic. Software Engineering Testing and Debugging Debugging. Today s Topic. The Main Steps in Systematic Debugging

Hi everyone. I hope everyone had a good Fourth of July. Today we're going to be covering graph search. Now, whenever we bring up graph algorithms, we

CS 151. Recursion (Review!) Wednesday, September 19, 12

CSE 374 Programming Concepts & Tools. Brandon Myers Winter 2015 Lecture 11 gdb and Debugging (Thanks to Hal Perkins)

CSE 373: Data Structures and Algorithms

Excel 2013 Intermediate

CSE 373 OCTOBER 11 TH TRAVERSALS AND AVL

RPL's Library Catalogue User Guide

Using the Xcode Debugger

CS W3134: Data Structures in Java

Welcome to Lab! Feel free to get started until we start talking! The lab document is located on the course website:

ICOM 4015 Advanced Programming Laboratory. Chapter 1 Introduction to Eclipse, Java and JUnit

Debugging in Small Basic is the process of analysing a program to detect and fix errors or improve functionality in some way.

CS 215 Software Design Homework 3 Due: February 28, 11:30 PM

CSCI 1100L: Topics in Computing Lab Lab 11: Programming with Scratch

Model-View-Controller

JCreator. Starting JCreator

Lecture 24 Wrap Up. Final Logistics CSE 331. Today. CSE 331 Software Design and Implementation. Wednesday, 8:30-10:20 AM

Jerry Cain Handout #5 CS 106AJ September 30, Using JSKarel

CSE 331 Software Design and Implementation. Lecture 24 Wrap Up

Thread Safety. Review. Today o Confinement o Threadsafe datatypes Required reading. Concurrency Wrapper Collections

NetBeans Tutorial. For Introduction to Java Programming By Y. Daniel Liang. This tutorial applies to NetBeans 6, 7, or a higher version.

CMSC 341 Lecture 10 Binary Search Trees

Homework #10 due Monday, April 16, 10:00 PM

CSE373 Winter 2014, Final Examination March 18, 2014 Please do not turn the page until the bell rings.

CSE 373 MAY 10 TH SPANNING TREES AND UNION FIND

CSE373 Fall 2013, Second Midterm Examination November 15, 2013

Java Program Structure and Eclipse. Overview. Eclipse Projects and Project Structure. COMP 210: Object-Oriented Programming Lecture Notes 1

Software Engineering

In either case, remember to delete each array that you allocate.

CSE 351. GDB Introduction

Section 4: Graphs and Testing

CSE 373 NOVEMBER 20 TH TOPOLOGICAL SORT

How to Remove Duplicate Rows in Excel

SECTION 1: CODE REASONING + VERSION CONTROL + ECLIPSE

CPE 101. Overview. Programming vs. Cooking. Key Definitions/Concepts B-1

CSE 332: Data Structures and Parallelism Winter 2019 Setting Up Your CSE 332 Environment

Sixth lecture; classes, objects, reference operator.

Welcome to Lab! Feel free to get started until we start talking! The lab document is located on the course website:

HASH TABLES cs2420 Introduction to Algorithms and Data Structures Spring 2015

1 5,9,2,7,6,10,4,3,8,1 The first number (5) is automatically the first number of the sorted list

6.005 Elements of Software Construction Fall 2008

On the Web sun.com/aboutsun/comm_invest STAROFFICE 8 DRAW

Access Intermediate

Web API Lab. The next two deliverables you shall write yourself.

CSE 143, Winter 2013 Programming Assignment #8: Huffman Coding (40 points) Due Thursday, March 14, 2013, 11:30 PM

CS1 Lecture 5 Jan. 26, 2018

Debugging. CSE 2231 Supplement A Annatala Wolf

Checked and Unchecked Exceptions in Java


CSE P 501 Compilers. Parsing & Context-Free Grammars Hal Perkins Spring UW CSE P 501 Spring 2018 C-1

Dealing with Bugs. Kenneth M. Anderson University of Colorado, Boulder CSCI 5828 Lecture 27 04/21/2009

Code::Blocks Student Manual

PROGRESS BOOK PARENT ACCESS NAVIGATION

the employee s next birthday is in the past. This mechanism will consistently update the employee s next birthday.

Section 4: Graphs and Testing

COMP390 (Design &) Implementation

CSE 143. More ArrayIntList; pre/post; exceptions; debugging. Computer Programming II. CSE 143: Computer Programming II

Write for your audience

Adam Blank Lecture 3 Autumn 2016 CSE 143. Computer Programming II

ENGR 40M Project 3c: Coding the raindrop pattern

CS 302: INTRODUCTION TO PROGRAMMING. Lectures 7&8

CS1 Lecture 5 Jan. 25, 2019

Computer Science II Lab 3 Testing and Debugging

GradeConnect.com. User Manual

Binary Trees Due Sunday March 16, 2014

Graphs & Digraphs Tuesday, November 06, 2007

Transcription:

hw6, BFS, debugging CSE 331 Section 5 10/25/12 Slides by Kellen Donohue

Agenda hw4 being graded hw5 may be graded first, for feedback to be used on hw6 hw6 due next week Today hw6 BFS Debugging

hashcode() and equals() Overriding these important for using classes you write in collections, e.g. Read Javadoc for requirements Transitive, symmetric, etc. we ll discuss later in lecture Usually must override hashcode() if you override equals() Eclipse can generate them for you Right click in class source file Source -> Generate hashcode() and equals() Not always perfect learn more later & in 332

Special values vs. exceptions Map<String, Integer> map = new HashMap<String, Integer>(); System.out.println(map.get( hi ));

Special values vs. exceptions Map<String, Integer> map = new HashMap<String, Integer>(); System.out.println(map.get( hi )); // prints null

Special values vs. exceptions Map<String, Integer> map = new HashMap<String, Integer>(); System.out.println(1 + map.get( hi ));

Special values vs. exceptions Map<String, Integer> map = new HashMap<String, Integer>(); System.out.println(1 + map.get( hi )); // throws NullPointerException

Special values vs. exceptions Map<String, String> map = new HashMap<String, String>(); map.put( hi, null); System.out.println(map.get( hi )); System.out.println(map.get( bye )); // Prints null twice

Special values vs. exceptions C# Dictionary<string, int> map = new Dictionary<string, int>(); Console.WriteLine(map[ hi ]);

Special values vs. exceptions C# Dictionary<string, int> map = new Dictionary<string, int>(); Console.WriteLine(map[ hi ]); // C# -- Throws exception // (Java -- prints null)

Special values vs. exceptions C# Dictionary<string, int> map = new Dictionary<string, int>(); map[ hi ] = 6; int hival, byeval; bool hisuccess = map.trygetvalue( hi, out hival); bool byesuccess = map.trygetvalue( bye, out byeval);

Special values vs. exceptions C# Dictionary<string, int> map = new Dictionary<string, int>(); map[ hi ] = 6; int hival = 4, byeval, = 5; map.trygetvalue( hi, out hival); map.trygetvalue( bye, out byeval); // hival gets 6, byeval gets 0 (!) // (Java throws exception)

Special values vs. exceptions Morals of the story There s more than one right answer to special values vs. exceptions, and you may find more than one in practice Be sure to read the specs to know what happens e.g. What happens with null keys?

Homework 6 Use Graph ADT from hw5 Fill with Marvel Data Nodes = characters Edges = books Labeled with title Connecting characters if both characters appeared in that book Turns out to model real life social graphs

Graph paths List of nodes travelled to get from one node to another, moving along edges, respecting direction A C B D E

Graph paths List of nodes travelled to get from one node to another, moving along edges, respecting direction A C B D E

Graph paths List of nodes travelled to get from one node to another, moving along edges, respecting direction A C B D E

Graph paths List of nodes travelled to get from one node to another, moving along edges, respecting direction A C B D E

Graph paths List of nodes travelled to get from one node to another, moving along edges, respecting direction ADEC is a path A to C A C B D E

Graph paths List of nodes travelled to get from one node to another, moving along edges, respecting direction ADEC is a path A to C AC is a path A to C A C B D E

Graph paths List of nodes travelled to get from one node to another, moving along edges, respecting direction ADEC is a path A to C AC is a path A to C There s no path A to B A C E B D

Graph paths We often want to find the shortest path between two nodes Google Maps Optimal route through a maze A C B D AC is the shortest path A to C E

Breadth-first search Informally, put the start node in a queue While the queue isn t empty Pick a node N off the queue If N is the goal then return Else, for each node O you can reach from N If O isn t marked» Add O to the queue» Mark O Couldn t find an path after exploring graph

Breadth-first search We often want to find the shortest path between two nodes Google Maps Optimal route through a maze A C B D AC is the shortest path A to C E

Breadth-first search Queue A B C D E

Breadth-first search Queue C A B C D E

Breadth-first search Queue C D A B C D E

Breadth-first search Queue D A B C D E

Breadth-first search Queue A B C D E

Breadth-first search Queue E A B C D E

Breadth-first search Queue A B C D E

Breadth-first search Queue empty, so no path A->B A B C D E

Maze demo Breadth-first search

Breadth-first search Guaranteed to find shortest-path In number of nodes Not lowest cost path if edges have cost If a stack was used instead of queue = depth first search Very memory intensive for large graphs -- O(b^d) Will use in HW6 to find shortest paths between two characters

Eclipse Debugging Hal will talk more in lecture tomorrow about debugging In some sense debugging is last resort Still want good tools for it Eclipse has a great debugger! Complicated, hidden features I ll demo a lot, but don t feel try to remember how to do everything slides will be posted

Eclipse Debugging

Eclipse Debugging Double click in the gray area to the left of your code to set a breakpoint. A breakpoint is a line that the Java VM will stop at during normal execution of your program, and wait for action from you.

Eclipse Debugging Click the Bug icon to run in Debug mode. Otherwise your program won t stop at your breakpoints.

Eclipse Debugging Controlling your program while debugging is done with these buttons

Eclipse Debugging Play, pause, stop work just like you d expect

Eclipse Debugging Step Into Steps into the method at the current execution point if possible. If not possible then just proceeds to the next execution point. If there s multiple methods at the current execution point step into the first one to be executed.

Eclipse Debugging Step Over Steps over any method calls at the current execution point. Theoretically program proceeds just to the next line. BUT, if you have any breakpoints set that would be hit in the method(s) you stepped over, execution will stop at those points instead.

Eclipse Debugging Step Out Allows method to finish and brings you up to the point where that method was called. Useful if you accidentally step into Java internals (more on how to avoid this next). Just like with step over though you may hit a breakpoint in the remainder of the method, and then you ll stop at that point.

Eclipse Debugging Enable/disable step filters There s a lot of code you don t want to enter when debugging, internals of Java, internals of JUnit, etc. You can skip these by configuring step filters. Checked items are skipped.

Eclipse Debugging Stack Trace Shows what methods have been called to get you to current point where program is stopped. You can click on different method names to navigate to that spot in the code without losing your current spot.

Eclipse Debugging Variables Window Shows all variables, including method parameters, local variables, and class variables, that are in scope at the current execution spot. Updates when you change positions in the stackframe. You can expand objects to see child member values. There s a simple value printed, but clicking on an item will fill the box below the list with a pretty format. Some values are in the form of ObjectName (id=x), this can be used to tell if two variables are reffering to the same object.

Eclipse Debugging Variables that have changed since the last break point are highlighted in yellow. You can change variables right from this window by double clicking the row entry in the Value tab.

Eclipse Debugging Variables that have changed since the last break point are highlighted in yellow. You can change variables right from this window by double clicking the row entry in the Value tab.

Eclipse Debugging There s a powerful right-click menu. See all references to a given variable See all instances of the variable s class Add watch statements for that variables value (more later)

Eclipse Debugging Show Logical Structure Expands out list items so it s as if each list item were a field (and continues down for any children list items)

Eclipse Debugging Breakpoints Window Shows all existing breakpoints in the code, along with their conditions and a variety of options. Double clicking a breakpoint will take you to its spot in the code.

Eclipse Debugging Enabled/Disabled Breakpoints Breakpoints can be temporarily disabled by clicking the checkbox next to the breakpoint. This means it won t stop program execution until reenabled. This is useful if you want to hold off testing one thing, but don t want to completely forget about that breakpoint.

Eclipse Debugging Hit count Breakpoints can be set to occur less-frequently by supplying a hit count of n. When this is specified, only each n-th time that breakpoint is hit will code execution stop.

Eclipse Debugging Conditional Breakpoints Breakpoints can have conditions. This means the breakpoint will only be triggered when a condition you supply is true. This is very useful for when your code only breaks on some inputs! Watch out though, it can make your code debug very slowly, especially if there s an error in your breakpoint.

Eclipse Debugging Disable All Breakpoints You can disable all breakpoints temporarily. This is useful if you ve identified a bug in the middle of a run but want to let the rest of the run finish normally. Don t forget to re-enable breakpoints when you want to use them again.

Eclipse Debugging Break on Java Exception Eclipse can break whenever a specific exception is thrown. This can be useful to trace an exception that is being translated by library code.

Eclipse Debugging Expressions Window Used to show the results of custom expressions you provide, and can change any time. Not shown by default but highly recommended.

Eclipse Debugging Expressions Window Used to show the results of custom expressions you provide, and can change any time. Resolves variables, allows method calls, even arbitrary statements 2+2 Beware method calls that mutate program state e.g. stk1.clear() or in.nextline() these take effect immediately

Eclipse Debugging Expressions Window These persist across projects, so clear out old ones as necessary.

Demo Eclipse Debugging