What is Computer

Module: M2-R5: Web Design & Publishing

Chapter: Ch1 Computer Intro

🔹 What is Top-down Approach?

The Top-down approach is a method of problem solving where a complex problem is broken down into smaller and simpler sub-problems. Each sub-problem is solved individually, and the results are combined to form the complete solution.

🧩 Concept:

Also called Stepwise Refinement, this approach starts from a high-level overview of the problem and gradually refines it into smaller modules until each can be easily solved.

# Example of Top-down Problem Solving (Python)

def get_marks():
    marks = []
    for i in range(3):
        m = int(input(f"Enter marks for subject {i+1}: "))
        marks.append(m)
    return marks

def calculate_total(marks):
    return sum(marks)

def calculate_percentage(total, subjects):
    return total / subjects

def display_result(total, percentage):
    print(f"Total Marks: {total}")
    print(f"Percentage: {percentage:.2f}%")

def main():
    marks = get_marks()
    total = calculate_total(marks)
    percentage = calculate_percentage(total, len(marks))
    display_result(total, percentage)

main()

Output (Sample):

Enter marks for subject 1: 80
Enter marks for subject 2: 90
Enter marks for subject 3: 85
Total Marks: 255
Percentage: 85.00%
🔹 Steps in Top-down Approach
  • Identify the main problem or goal.
  • Divide the main task into smaller sub-problems.
  • Keep dividing until each sub-problem is easily solvable.
  • Write a separate function for each sub-problem.
  • Integrate all functions to form the complete program.
🔹 Advantages
  • Makes complex problems easier to manage and understand.
  • Promotes modular programming.
  • Each module can be tested and debugged independently.
  • Improves code readability and maintainability.
🔹 Disadvantages
  • Requires full understanding of the overall problem before breaking it down.
  • Sometimes difficult to divide problems correctly.
✅ Summary
  • The top-down approach follows the divide and conquer principle.
  • It emphasizes breaking a large problem into smaller modules.
  • Encourages structured, modular, and reusable code.
  • Commonly used in software design and function-based programming.
Quick Links