Skip to content

CSCI 370 - Lec 4: Optimization and Design Patterns in Software Engineering


  • Optimization Algorithms (Christofides’ Algorithm & TSP)
  • AI in Drug Discovery and Development
  • Strategy Pattern (Design Pattern)
  • Observer Pattern (Design Pattern)

Traveling Salesman Problem (TSP) & Christofides’ Algorithm

Section titled “Traveling Salesman Problem (TSP) & Christofides’ Algorithm”
  • The Traveling Salesman Problem (TSP) asks: What is the shortest route to visit a set of cities and return to the starting point?
  • It is NP-hard; the number of possible routes grows factorially (e.g., 10 cities = ~3.6 million routes).
  • Logistics (e.g., UPS delivery optimization)
  • Fiber optic cable layout
  • Genome sequencing

Christofides’ algorithm offers an approximate solution with a guaranteed upper bound of 1.5 times the optimal route length.

  1. Minimum Spanning Tree (MST):

    • Connect all nodes (cities) without creating loops.
    • Use shortest possible total edge weight.
  2. Find Odd-Degree Vertices:

    • Identify vertices in the MST with an odd number of connections.
  3. Minimum Weight Perfect Matching:

    • Pair all odd-degree vertices with minimum-weight connections.
  4. Combine to Form Eulerian Circuit:

    • Result is a multigraph with all even-degree vertices, allowing an Eulerian circuit (visits every edge once).
  5. Convert to Hamiltonian Circuit:

    • Remove repeated cities to obtain a path visiting each city exactly once.
  • Near-optimal solution
  • Efficient compared to brute-force

A delivery company must visit 15 addresses. Christofides’ algorithm reduces route length, saving fuel and time.


  • Speeds up drug development
  • Improves hospital efficiency
  • Enables personalized treatment based on patient data
  • Radiomics + Deep Learning:
    • Extract features from X-rays/CT scans to classify pneumonia
  • CAD Systems:
    • Aid radiologists by highlighting affected areas
  • Explainability Tools (e.g., SHAP):
    • Help understand AI decisions
  • Example model (Random Forest) achieved ~82% accuracy for detecting COVID-19 from imaging data
  • Predicts protein structures
  • Accelerates analysis of vaccine candidates (e.g., Pfizer during COVID)
  • Enables scaling up of vaccine production
  • AI models require large, high-quality datasets
  • Poor data = inaccurate predictions
  • Projects like Oracle’s “Stargate” invest in predictive healthcare using AI (e.g., early cancer detection)

  • Inheritance makes code tightly coupled.
  • Adding new behaviors requires modifying many classes.

Encapsulate interchangeable behaviors and pass them to objects.

  • Context: Class using a behavior (e.g., Duck)
  • Strategy Interface: Common interface for all behaviors (e.g., FlyBehavior)
  • Concrete Strategies: Implement different behaviors (e.g., FlyHigh, NoFly)
  • Favor composition over inheritance
  • Avoid code duplication
  • Open for extension, closed for modification (OCP)
  • Add new behaviors without changing existing code
  • Payment system: define Payment interface and implement strategies like Cash, CreditCard, PayPal, etc.

Notifying interested parties (observers) when an object (subject) changes.

  • Subject: Stock Market
  • Observers: Wall Street, SEC
  • Observers want to be notified when a stock is bought or sold.
  • Code modification was needed every time a new observer was added.
  • Subject Interface: Manages observers (add/remove/notify)
  • Observer Interface: Contains notify() method
  • Concrete Observers: Implement specific behavior on notification
  • Decouples subject from observers
  • Open for extension, closed for modification
  • Easily add/remove observers without touching core logic
  • GUI Button in C#: adding/removing click event listeners behaves like the observer pattern

Software entities should be open for extension but closed for modification.

  • Add functionality via new code
  • Avoid changing existing, working code
  • Helps prevent bugs and ensures stability

Lecture 5 focused on optimization and design patterns that emphasize clean, maintainable code. Christofides’ algorithm provides a real-world solution to TSP, while Strategy and Observer patterns illustrate how to write flexible, reusable object-oriented code. These patterns support the Open-Closed Principle, ensuring scalable and bug-resistant systems.