Top-Down Design of Programs

Lecture 8: Top-Down Design of Programs

Date: Fall 2025

Presenters: Dr. Kristin Schaefer, based on original slides by Drs. John Keyser, Tony Cahill & Niki Ritchey


Overview of Today’s Lecture
  • Topics to Cover:

    • Top-Down Design

    • Dictionaries


Top-Down Design

Definition

  • Top-Down Design: A method of program organization and ideation where a problem is broken down hierarchically from the highest level to more detailed levels.

Program Ideation and Organization

  • The lecture centers around efficiently determining the structure of a program through a top-down approach, ensuring clarity and systematic organization in programming tasks.


Curriculum Design Challenge

Problem Statement

  • Scenario: Creation of a college degree curriculum with a limit of 40 courses.

    • Question: How to determine which courses should be included in the curriculum?

Common Approaches

  • Initial Approach: Simple listing of classes believed to be valuable.

    • Problems with this approach:

    • Risk of missing critical areas of study.

    • Difficulty in maintaining balance across different subject areas (Math, Arts, Sciences).


A Better Approach to Curriculum Design
  1. Identify Broad Categories:

    • Start by thinking about overarching categories of courses.

  2. Specify Course Breakdown:

    • Begin breaking these categories into smaller subcategories, such as Core Curriculum and Major-Specific courses.

Example Breakdown

  • Core Curriculum Breakdown:

    • Total Core Curriculum Courses: 14

    • Math/Science: 5

    • Communication: 2

    • Philosophy/Social Science: 2

    • History/Government: 4

    • Arts/Culture: 1

  • Major-Specific Courses: Total of 26.


Further Breakdown of Categories
  1. Deep Dive into Categories:

    • Continue to break down each major category until individual courses can be specified.

  2. Example Breakdown for Mathematics:

    • Math: 2 Courses

    • Science: 3 Courses


Hierarchical Structure in Curriculum Design
  • Hierarchy Development Process:

    • Initiate with the most general idea (e.g., creating a curriculum).

    • Subdivide into more specific categories (e.g., Core, Major).

    • Continue breaking down until the most specific unit is clear (individual course).

Characteristics of Hierarchies

  • Coherent and Distinct Units: Each unit in the hierarchy should be cohesive and uniquely identifiable.


Hierarchical Structures in Various Contexts

Observations:

  • Hierarchies facilitate organization in:

    1. Universities: Organized into structures from University → Departments.

    2. Corporations: Chains from President/CEO down to employees.

    3. Biological Systems: Body → Systems → Organs → Tissues → Cells.

    4. Communities: Metro region → Cities → Zones → Buildings.

    5. Sports: League → Conference → Division.


Computing Terminology Related to Hierarchies
  • Data Structure Known as a “Tree”:

    • Root: The topmost node in a tree structure.

    • Node: An individual element within the tree.

    • Parent Node: The node directly above another node.

    • Child Nodes: Nodes that descend from a parent node.

    • Leaf Nodes: Nodes without children (end points in a tree structure).


Advantages of Hierarchies
  1. Coherency: Each node clearly represents a concept or idea.

  2. Conceptual Separation: Allows focus on one node at a time without interference from others.

  3. Management of Complexity: Facilitates understanding of large organizations or complex systems by structuring them logically.


Disadvantages of Hierarchies
  1. Artificial Boundaries: Difficulty in clearly separating concepts that are interconnected.

  2. Over-Simplification: Simplistic separation can cause loss of important relationships.

  3. Drawbacks in Practice: Rigid structures can lead to issues in adaptability within organizations.

  4. Recommendation: While there are disadvantages, hierarchies are a foundational tool for effective organization.


Top-Down Design Process

Definition

  • The process involving breaking down a problem into hierarchical components starting from the most general to the specifics.

  • This approach can be applied to various challenges, especially in engineering.

Practical Example

Case: Planning a Week-Long Vacation

  • Initial Breakdown Options: Hotels, Transportation, Activities.

  • Continue defining elements down to daily schedules if necessary.


Top-Down Program Design Approach
  1. Identify Overall Problem:

    • Start by defining the problem you wish to solve.

  2. List Major Steps:

    • Break down into large, manageable steps.

  3. Further Breakdown:

    • Continue to decompose until implementation seems obvious and concise, typically aiming for code segments that are straightforward (1 to 10 lines).

  4. Commenting for Structure:

    • Represent nodes as comments to visually indicate structure during design.


Example: Study Analyzer Program

Objective

  • The program calculates time spent studying for various tests, recording session data along the way.

Breakdown of Program

  1. Read In Session Data

  2. Process User Queries

  3. Present Summary of Program

  4. Loop until done entering data

Detailed Steps in Program Logic

  • Receive Test Name and Session Length

  • Store these entries.

  • Process the data to return results based on user queries.


Program Coding Stage
  • Convert Nodes to Comments for clarity:

#Read In Session Data
  #Present Summary of Program
  print("This program calculates the amount of time you...")
  #Loop Until Done Entering Study Sessions
  #Get Test Name

Final Implementation Aspects
  • Example of looping through and processing user input.

  • Conditions for adding names and lengths to lists, checking presence of entries, and calculating total study time.


Introduction to Dictionaries

Key Features

  • Definition: A dictionary is a type of data structure that stores data in key-value pairs.

    • A key can map to one value, with the potential for different keys to share the same value.

    • Example in real-world dictionary:

    • Key: a word; Value: its definition, pronunciation, synonyms, etc.

Creating a Dictionary

  • Dictionaries can be created using {} notation, with key-value pairs defined as: {key: value, key2: value2, ...}.

    • Example: person = {"name": "Alice", "age": 30, "city": "New York"}