1 / 10

1 Nov

1 Nov. HW 1 comments Backtracking. HW 1. Original problem + 3 modifications Modified data structure Basic program structure List of operations and elaborated program structure Produce Java code and verify your design! There will be some logical errors, but easy to correct

gilda
Télécharger la présentation

1 Nov

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 1 Nov HW 1 comments Backtracking

  2. HW 1 • Original problem + 3 modifications • Modified data structure • Basic program structure • List of operations and elaborated program structure • Produce Java code and verify your design! • There will be some logical errors, but easy to correct • Put the appropriate overall header, overall trailer and also header and trailer information • Overall header – class and main method headers • Overall trailer – ‘}’ - indicates end of class • Header – identifier declarations used in main • Trailer – empty • JWB encloses the generated code with beginning and ending braces (‘{‘ and ‘}’)

  3. Java Headers and Trailers Overall header public class MultTable { public static void main(String[] args) Overall Trailer } //end class Header int rowNo, colNo, elementNo, MAX; Trailer - (empty)

  4. Backtracking In the forms of iteration and selection used in JSP, the condition test precedes execution of a part. • we use read-ahead rule to handle serial input files if pattern is a single character or record • we use multiple read ahead rule if pattern is some fixed number, n, of characters (or records) • use backtracking if there is no fixed number, n

  5. Backtracking Problem: A cardfile of punched cards is sorted into ascending sequence of values of a key which appears in each card. • 1st card for each group with a common key value is a header card • Other records are detail cards. • Each detail card carries an integer amount • It is required to pro­duce a report showing the totals of amount for all keys

  6. Corresponding data structures

  7. Basic Program Structure

  8. Backtracking Modified problem: file has a record-type field: • 'header‘ - indicates group-id of the set of records that follow • 'detail' - indicates that record belongs to a group and contains data • other – if not of type ‘header’ or ‘detail’, record is an error • Program should detect the following errors: • header missing • detail cards have some other identifier (not ‘detail’) • Groups containing errors should be listed as an errorlist (not totaled)

  9. Structure of Error List & Program

  10. Backtracking Recognition problem: We cannot recognize a good group with any predetermined fixed read ahead We tackle the recognition problem using ‘backtracking’ in 3 stages: • Assume (posit) that a group will be good (ignore the recognition difficulty) and design the full program accordingly. • Verify each data along the way – if any data contradicts the assumption of good data, issue a quit statement that branches to the second selection (badgroup) c. Modify the program text resulting from stage b. to ensure that side-effects are repealed where necessary

More Related