1 / 16

Oct 25

Oct 25. Group_ID rule Multiple Read-ahead Backtracking. Group-ID Rule. We frequently wish to process groups in a file sorted by group.

aqua
Download Presentation

Oct 25

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. Oct 25 Group_ID rule Multiple Read-ahead Backtracking

  2. Group-ID Rule We frequently wish to process groups in a file sorted by group. Problem statement: Produce a Census report that reports the number of males and females in each household and summarizes the number of households, males and females and average household size as shown below: Household Id# yyyyy #Females xxxxxx #Males xxxxxx Household Id# yyyyy #Females xxxxxx #Males xxxxxx … Household Id# yyyyy #Females xxxxxx #Males xxxxx Totals: # hhlds: yyyyyy # F: xxxxxx # M: xxxxxx ave. hhld size: x.x The input file is a text file with each record (line) containing: Household id 0-3 Person id 4-6 Gender code 7 (‘0’= female, ‘1’= male)

  3. JSP • System diagram • Data structures for: • input - censusFile.jsp • output - censusReport.jsp • Composite data model showing correspondences • Basic Program Structure – censusBasicStr2.jsp • List and allocate operations • Produce elaborated program structure - censusElabStr.jsp • Generate structure text or code • Structure text • Java code

  4. Group ID Rule • Group-id Rule: “If a structure contains a component that is a group of records all having the same value of a (usually sorted) identifier, then there must be an operation that stores the value of the identifier. This operation should be allocated once per group, at the beginning of the group.” • Design focuses on: • a static not a dynamic view of the problem; • data structures (objects), not on dynamic flow of control

  5. Multiple Read-Ahead • Problem: • Write a program to remove all comments from a C program. A comment in C begins with the characters, /*, and ends with the characters, */. Take note of the fact that C allows strings, any characters enclosed by double-quotes ("), as well as constants, which are enclosed in single quotes. • Solution • Data structure • In order to recognize a "C" comment, we must read two consecutive characters prior to selection (static not dynamic view) • Comment Structure • Multiple read-ahead rule • C Program

  6. Bottom-up Design • machine has elementary data types and elementary operations • we may decide that we need data types and operations at a more abstract level Example: We create matrix data structure with operations matadd, matsub, matmult and matdiv, together with matrix constants, matzero and matident to represent the zero and identity matrices. • we have extended our elementary operations by bottom-up design

  7. Generalized vs. Generalized Components • In JSP we build a hierarchic tree structure • Each component depends on one and only one component higher up in the hierarchy. • No generalized components. A change to P2 will have no effect on any other component because each component has structural integrity.

  8. Generalized Components • PC depends only on P2, but PA depends on both P1 and P, while PB depends on P1, P2 and P3. What part of component PB will need to be changed if component P1 is changed? Will this change affect the way PB works as a component of P3?

  9. Generalized Components • In some sense we have optimized since this design has only seven components, whereas our original had eight. • Our components are generalized. We may have saved valuable storage space. • But in the process, we have lost design integrity, and increased the burden of future maintenance.

  10. Bottom-up Versus Generalized Design • We can design new, more general elementary operations using bottom-up design to transform our programming environment. • Creating generalized components is an optimization technique; optimization should only be attempted after a correct design has been derived.

  11. Data Structure - Census File

  12. Data structure of Report

  13. Composite data structure

  14. Elaborated Program structure

  15. Data structure“C” program text file

  16. Comment Structure

More Related