Algorithms, Part 3 of 3 Topics Top down-design Reading

Slides:



Advertisements
Similar presentations
Modular Design Using Subroutines (functions later)
Advertisements

CMSC 104, Version 9/011 Top-Down Design Topics Top-Down Design Top-Down Design Examples The Function Concept Reading Sections 3.9, 3.10.
Basics of Computer Programming Web Design Section 8-1.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
Structured Programming structured programming: A technique for organizing and coding computer programs in which a hierarchy of modules is used, each having.
Chapter 1 Program Design
The Program Design Phases
Algorithms IV: Top-Down Design
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 02.
Structured Programming Defn: This is an approach to program development that produces programs of high quality that are easy to test, debug, modify and.
Top-Down Design and Modular Development
Program Design CMSC 201. Motivation We’ve talked a lot about certain ‘good habits’ we’d like you guys to get in while writing code. There are two main.
Invitation to Computer Science, Java Version, Second Edition.
Practice and Evaluation. Practice Develop a java class called: SumCalculator.java which computes a sum of all integer from 1 to 100 and displays the result.
INTRODUCTION TO COMPUTING CHAPTER NO. 04. Programming Languages Program Algorithms and Pseudo Code Properties and Advantages of Algorithms Flowchart (Symbols.
Top-Down Design and Modular Development. The process of developing methods for objects is mostly a process of developing algorithms; each method is an.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 6 Using Methods.
CMSC 104, Version 8/061L17Top-DownDesign.ppt Top-Down Design Topics Top-Down Design Top-Down Design Examples The Function Concept Reading Sections 3.1.
CS221 Algorithm Basics. What is an algorithm? An algorithm is a list of instructions that transform input information into a desired output. Each instruction.
1 CS161 Introduction to Computer Science Topic #9.
Data Structure and Algorithms. Algorithms: efficiency and complexity Recursion Reading Algorithms.
L061 Algorithms, Part 3 of 3 Topics Top down-design Structure charts Reading Sections , 3.3.
Top-down approach / Stepwise Refinement & Procedures & Functions.
Computing Higher – SD Unit - Topic 8 – Procedure and Standard Algorithms P Lynch, St Andrew’s High School Unit 2 Software Development Process Topic.
© Janice Regan, CMPT 128, February CMPT 128: Introduction to Computing Science for Engineering Students Recursion.
1 UMBC CMSC 104, Section Fall 2002 Functions, Part 1 of 3 Topics Top-down Design The Function Concept Using Predefined Functions Programmer-Defined.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Recursion ● Recursion is a computer programming technique that allows programmers to divide problems into smaller problems of the same type. ● You can.
Development Environment
Introduction to Computing Science and Programming I
Algorithms and Problem Solving
Structured Programming
Visit for more Learning Resources
Algorithms IV Top-Down Design.
A451 Theory – 7 Programming 7A, B - Algorithms.
Chapter 15 Recursion.
Basics of Computer Programming
Possible exam questions with Scenarios
Algorithms IV Top-Down Design.
Programming Fundamentals
Chapter 15 Recursion.
CMSC201 Computer Science I for Majors Lecture 15 – Program Design
Topic:- ALGORITHM Incharge Faculty – Lokesh Sir.
Algorithm development
Programming Problem steps must be able to be fully & unambiguously described Problem types; Can be clearly described Cannot be clearly described (e.g.
CMSC201 Computer Science I for Majors Lecture 11 – Program Design
Basics of Computer Programming
Basics of Computer Programming
Basics of Computer Programming
Unit# 8: Introduction to Computer Programming
Print slides for students reference
Starting Out with Programming Logic & Design
Problem Solving Techniques
Structured Programming
Computational Thinking
Chapter 5: Algorithms Computer Science: An Overview Tenth Edition
Chapter 6 : Algorithm Development
Programming Fundamentals (750113) Ch1. Problem Solving
Programming Fundamentals (750113) Ch1. Problem Solving
UMBC CMSC 104 – Section 01, Fall 2016
Algorithms IV Top-Down Design.
Basics of Recursion Programming with Recursion
Algorithms and Problem Solving
Starting Out with Programming Logic & Design
AKA Stepwise refinement
Algorithms, Part 3 of 3 Topics Top down-design Structure charts
Top-Down Design & JSP Skill Area Part D
CMSC201 Computer Science I for Majors Lecture 12 – Program Design
Computer Science: An Overview Tenth Edition
Agenda for Unit 3: Functions
Presentation transcript:

Algorithms, Part 3 of 3 Topics Top down-design Reading Sections 3.9, 3.10

Pseudocode and Then Some We can write an algorithm for finding the average of two integers: Read integer <num1>, from the user Read integer <num2> from the user <sum> = <num1> + <num2> <average> = <sum> / 2 Display “The average of <num1> “and” <num2 > “is” <average>. Steps 1, 2 & 5 will make use of code found in the run-time library. 1 2 3 4 5

Investigating Steps 1 & 5 Read integer <num1>, from the user Display “The average =” <average>. Are these really single steps? Each of them is really a sequence of steps, a subprogram. Two kinds of subprograms: Functions - an answer is returned to the main program. Procedures - no answer returned to the main program

Functions and Procedures In our example, the function that gets a value from the user and the procedure that prints out the answer were already written. Many times it is necessary for us to write our own procedures or functions.

Top-Down Design If we look at a problem as a whole, it may seem impossible to solve because it is so complex. Examples: writing a tax computation program writing a word processor Complex problems can be solved using top-down design, also known as stepwise refinement. We break the problem into parts Then break the parts into parts Soon, each of the parts will be easy to do

Advantages of Top-Down Design Breaking the problem into parts helps us to clarify what needs to be done. At each step of refinement, the new parts become less complicated and, therefore, easier to figure out. Parts of the solution may turn out to be reusable. Breaking the problem into parts allows more than one person to work on the solution.

An Example of Top-Down Design Scenario: We own a home improvement company. We do painting, roofing, and basement waterproofing. A section of town has recently flooded (zip code 21222). We want to send out pamphlets to our customers in that area.

The Top Level Get the customer list from a file. Sort the list according to zip code. Make a new file of only the customers with the zip code 21222 from the sorted customer list. Print an envelope for each of these customers. Main Read Sort Select Print

Pseudocode for our Main Program Start Call Read Customer List Call Sort on customer list by zipcode Call Select Target List from Customer List using only zipcode 21222 Call Print Envelopes using target list Stop

Another Level? Should any of these steps be broken down further? Possibly. How do I know? Ask yourself whether or not you could easily write the algorithm for the step. If not, break it down again. When you are comfortable with the breakdown, write pseudocode for each of the steps (modules) in the hierarchy.

Structured Programs We will use top-down design for all of our programming projects. This is the standard way of writing programs. Programs produced using this method and using only the three kinds of control structures, sequential, selection and repetition, are called structured programs. Structured programs are easier to test, modify, and are also easier for other programmers to understand.

Another Example Problem: Write a program that draws this picture of a house.

The Top Level Draw the outline of the house Draw the chimney Draw the door Draw the windows Main Draw Outline Draw Chimney Draw Door Draw Windows

Observation The door has both a frame and knob. We could break this into two steps. Main Draw Outline Draw Chimney Draw Door Draw Windows Draw Door Frame Draw Knob

Another Observation There are three windows to be drawn. Main Draw Outline Draw Windows . . . Draw Window 1 Draw Window 2 Draw Window 3 (x1,y1) (x2,y2) (x3,y3)

Code Reuse But don’t the windows look the same? They just have different locations. So, we can reuse the code that draws a window. Simply copy the code three times and edit it to place the window in the correct location, or Use the code three times, “sending it” the correct location each time (we will see how to do this later). This is an example of code reuse.

The Pseudocode Start Call DrawHouseOutline giving a position Call DrawChimney giving position Call DrawDoor giving position Call DrawWindow giving (x,y) position #1 Call DrawWindow giving (x,y) position #2 Call DrawWindow giving (x,y) position #3 Stop

Summary Use the divide-and conquer strategy to split the original problem into a series of sub-problems. Consider each sub-problem separately and split them further into smaller sub-problems, progressively refining the previous versions in a top-to-bottom manner, until no further refinement is possible. Stop the process when you have the pseudocode that can be directly translated in a C program.

Exam 1 All material before this page is “fair game” for the midterm. Exam 1 will be given Thurs. October 9th If you know that you can not make the exam, tell me today after class, so that we can schedule a possible makeup. Only very SERIOUS conflicts will be honored.