Download presentation
Presentation is loading. Please wait.
Published byMeryl Phillips Modified over 9 years ago
1
Top Down Design Brent M. Dingle Texas A&M University Chapter 4 – Section 1 (and some from Mastering Turbo Pascal 5.5, 3 rd Edition by Tom Swan)
2
Definition Designing an algorithm to perform a task by breaking the task into smaller subtasks, and then breaking the subtasks into even smaller subtasks is called top-down design. Because you start at the biggest, most complex, task (the top) and break it into smaller subtasks thus moving down in complexity.
3
Synonyms Top-down design is also referred to as: the Divide and Conquer method the Stepwise Refinement method
4
Benefits Top-down design has proven itself to be an efficient and easily understood method of designing algorithms. The algorithms it produces are usually easy to understand and implement.
5
Outside computer science A builder starts with a blueprint and builds a foundation before building the walls. A musician begins with a theme or melody before adding trills. A writer starts with a general idea or an outline before writing the story. In sum, start “big” – get an overview of what must be done, then figure out the details.
6
Example Suppose you wanted to get dressed to go outside. What are the subtasks of getting dressed? Select what clothes you want to wear. Put on the selected clothes.
7
Example (cont 1) Now that we have the general idea of what subtasks are needed to get dressed, we need to see if we can break the subtasks down any further. What would the subtasks of “Selecting what clothes you want to wear” be?
8
Subtasks of Selecting Clothes Select undergarments (if any) Select pants (if any) Select shirt (if any) Select socks/hose (if any) Select shoes (if any) Select tie/neck adornment (if any) Select hat/head adornment (if any) Select jewelry (if any) Check that everything “goes together.” Reselect items that don’t go together Repeat until satisfied.
9
Subtasks of Put on the selected clothes Identify types of clothes selected (i.e. undergarments, outer garments, extras, jewelry, and so on). Put on undergarments, if any. Put on outer garments (shirts, pants, etc), if any. Put on extras (shoes, ties, etc), if any Put on jewelry, if any.
10
Subtasks Further Breakdown Could we break the selection tasks down any more? Most likely. Could we break the putting on tasks down any more? Most likely. In fact we could probably break them down so that we had a step by step explicit description. I’ll leave that for you to try, as the above should be enough to convey the idea of top-down design.
11
Challenge ( no grade ) Pretend you wanted to describe the task of going to a football game. Break it into subtasks. I’ll start: Go to football game Before game, Get tickets. On game day, go to the stadium. Enter stadium. Watch game. Can you break those subtasks down more? The question, “how ?” usually helps.
12
Challenge ( no grade ) Break the task: Mail a letter. into subtasks. The first subtask might be: Write a letter. The last subtask might be: Place envelope into mailbox.
13
Note Order and Similarity Notice that as you break the tasks down some sort of ORDER of tasks is often implied or necessary. Notice also some of the tasks may be very similar, so similar that if you just changed one or two words you would be writing the same description.
14
Similar tasks Notice that our list of “put on” subtasks is rather repetitive. What if we just made a subtask called PutOn(clothing item) Then we could say: For garment_type = [under garment] to [jewelry] do BEGIN For (all clothes selected) AND (not already put on) do Begin If (current clothing item is of garment_type) then PutOn( current clothing item) End END
15
Parameter Notice that in the above example our “put on” subtask would require a parameter of [clothing item].
16
Difficulty A difficulty in top-down design, when applying it to writing a program, is knowing exactly how far to break subtasks down. Experience helps in this matter. A general rule once suggested was that: No subtask when coded should take up more than a page. This is similar in Math to: No proof should take up more than a page (use lemmas to break it into smaller pieces) This is similar in English to: No paragraph should exceed one (typed) page. However, these are GENERAL rules and don’t always apply.
17
Pascal Pascal uses procedures and functions to perform subtasks. We will be seeing what those are shortly.
18
End Top Down Design
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.