Comments

Notes

MCS 211

18 topics

Problem Solving Technique

Updated Jan 11, 20255 min read

Divide and Conquer Approach

This is one of the popular approaches in which a problem is divided into smaller subproblems. These subproblems are further divided into smaller subproblems until they can no longer be divided. It is a top down approach in which the algorithm logically progresses from the initial instance down to the smallest sub-instances via intermediate sub-instances.

 An algorithm, following divide & conquer technique, involves following steps:

Step 1. Divide the problem (top level) into a set of sub-problems (lower level). 

Step 2. Solve every sub-problem individually by recursive approach. 

Step 3. Merge the solution of the sub-problems into a complete solution of the problem.

Following are the examples of the problems that can efficiently be solved using divide and conquer approach.

  • Binary Search.  

  •  Quick Sort. 

  •  Merge Sort.  

  •  Strassen's Matrix Multiplication.

  •  Closest Pair of Points.

Greedy Technique

Using the Greedy approach, optimization problems are solved efficiently. In an optimization problem, the given set of input values are either to be maximized or minimized (called as objective), subject to some constraints or conditions.

  • Greedy algorithm always picks the best choice (greedy approach) out of many at a particular moment to optimize a given objective. 

  • The greedy method chooses the local optimum at each step and this decision may result in an overall non-optimum or optimum solution.  

  • The greedy approach doesn't always produce the optimal solution rather produces a very nearby solution to the optimal solution.

Consequently, Greedy algorithms are often very easy to design for the optimisation problems. 

Following are some of the examples of the greedy approach.

  • Kruskal’s Minimum Spanning Tree  

  • Prim's Minimal Spanning Tree 

  • Dijkstra's shortest path  

  • Knapsack Problem

Dynamic Programming

Dynamic Programming approach is a bottom-up approach which involves finding the solution of all sub-problems, saving these partial results, and then reusing them to solve larger sub-problems until the solution to the original problem is obtained. Reusing the results of sub-problems (by maintaining a table of results) is the major advantage of dynamic programming because it avoids the re-computations (computing results twice or more) of the same problem. Thus Dynamic programming approach takes much less time than naïve or straightforward methods.

Dynamic Programing Vs Divide and conquer

Feature
Dynamic Programming
Divide And Conquer
Subproblem Type
Overlapping
Independent
Key Principle
Optimal substructure
Divide and merge
Redundancy
Eliminates redundancy
No redundancy
Memory Usage
Requires additional storage
Minimal (stack space only)
Example Problems
Fibonacci, LCS, Knapsack
Merge Sort, Quick Sort

When to Use

  • Dynamic Programming: Use when problems have overlapping subproblems and optimal substructure.

  • Divide and Conquer: Use when problems can be divided into independent subproblems with no overlap.

Branch and Bound

Branch and Bound is an algorithmic technique used to solve optimization problems, particularly those involving combinatorial optimization or discrete search spaces. It systematically explores branches of a solution space while "bounding" sections of the space that cannot yield better solutions than already found.?

Key Concepts

1. Problem Type

  • Branch and Bound is used for problems where you need to either maximize or minimize an objective function under certain constraints.

  • Examples: Traveling Salesman Problem (TSP), Knapsack Problem, Integer Linear Programming.

2. Key Elements

 a. Branching:

    • Splits the problem into smaller subproblems (branches) to explore different parts of the solution space.

    • Each branch corresponds to a decision or choice in the solution.

 b. Bounding:

  • Calculates an upper or lower bound for the objective function for each subproblem.
  • If a bound is worse than the current best solution, the subproblem is discarded (pruned).
c. Pruning:
  • Eliminates branches of the search space that cannot produce better solutions than the current best.

3. Search Strategy

  • Can be depth-first, breadth-first, or best-first depending on how subproblems are explored.

Randomized Algorithms

In a randomized algorithm, a random number is selected at any stage of the solution and is used for computation of the solution, that’s why it is called a randomized algorithm. In other words it can be said that algorithms that make random choices for faster solutions are known as randomized algorithms. For example, in the Quick sort algorithm, a random number can be generated and considered as a pivot. In another example, a random number can be chosen as a possible divisor to factor a large number.

Backtracking Algorithm

Backtracking algorithm is like creating checkpoints while exploring new solutions. It works analogues to depth-first search. It searches for all the possible solutions. During the exploration of solutions, if a solution doesn't work, it back-track to the previous place and then find the other alternatives to get the solution. If there are no more choice points the search fails.

DETERMINISTIC AND STOCHASTIC ALGORITHM

A deterministic algorithm produces the same output for a given input every time it is executed. The behavior of the algorithm is entirely predictable and follows a predefined sequence of operations.

Characteristics:

  1. Predictability: Always provides the same result for the same input.

  2. No Randomness: Does not involve any random decisions or variables.

  3. Repeatability: Consistently repeatable under identical conditions.

  4. Examples:

    • Binary Search

    • Merge Sort

    • Dijkstra's Algorithm (Shortest Path)

    • Depth-First Search (DFS) and Breadth-First Search (BFS)


Advantages:

  • Reliable and consistent results.

  • Easier to debug and test due to predictable behavior.

  • Suitable for critical systems where randomness is undesirable.

Disadvantages:

  • May be less efficient for certain complex or large-scale problems compared to stochastic approaches.

  • May require more computational resources to explore all possibilities in some problems (e.g., NP-complete problems).

Stochastic Algorithms

A stochastic algorithm uses randomness as part of its logic. It may produce different outputs for the same input, depending on the random choices made during execution.

Characteristics:


  1. Randomness: Relies on random variables, choices, or probability distributions.

  2. Non-Deterministic Behavior: May produce different results for the same input.

  3. Probabilistic Guarantees: Often provides a solution with a certain probability of being optimal or near-optimal.

  4. Examples:

    • Genetic Algorithms

    • Simulated Annealing

    • Monte Carlo Methods

    • Randomized QuickSort

Advantages:

  • Often faster and more scalable for complex or large-scale problems.

  • Can escape local optima to find global solutions (e.g., in optimization problems).

  • Suitable for problems where exact solutions are hard or impossible to compute deterministically.

Disadvantages:

  • Results are not always consistent or repeatable.

  • May require multiple runs to ensure reliability.

  • Harder to debug and test due to randomness.

Share