## Introduction to Dynamic Programming

Dynamic Programming is a technique used in computer science to solve complex problems by breaking them down into smaller subproblems and solving them in a way that avoids redundant calculations. we will discuss the concept of Dynamic Programming using the example of Matrix Chain Multiplication. We will start with the basics and move on to a detailed explanation of the Matrix Chain Multiplication problem, how it can be solved using dynamic programming, and its practical applications.

### Definition of Dynamic Programming

Dynamic Programming is a problem-solving technique that involves breaking down a complex problem into smaller subproblems and solving them in a way that avoids redundant calculations.

### Applications of Dynamic Programming

Dynamic Programming is used in a wide range of fields, including computer science, economics, operations research, and engineering. It is commonly used to solve optimization problems, such as finding the shortest path in a graph or minimizing the cost of a task.

### Steps Involved in Dynamic Programming

The following steps are involved in solving a problem using Dynamic Programming:

- Define the problem and identify its subproblems.
- Develop a recursive relation to solve the problem.
- Create a memoization table to store the results of subproblems.
- Use the memoization table to solve the problem iteratively.

## Matrix Chain Multiplication

### Definition of Matrix Chain Multiplication

Matrix Chain Multiplication is a mathematical problem that involves multiplying a sequence of matrices to obtain the most efficient result. In this problem, we are given a sequence of matrices of varying dimensions, and we have to determine the order in which they should be multiplied to obtain the most efficient result.

### Example of Matrix Chain Multiplication

Suppose we have three matrices A, B, and C, with dimensions 10×20, 20×30, and 30×40, respectively. To multiply these matrices, we can either perform the operation (AB)C or A(BC). The former requires 10x20x30 + 10x30x40 = 18000 + 12000 = 30000 operations, while the latter requires 20x30x40 + 10x20x40 = 24000 + 8000 = 32000 operations. Therefore, the most efficient way to multiply these matrices is to perform the operation (AB)C.

### Recursive Relation for Matrix Chain Multiplication

The recursive relation for Matrix Chain Multiplication is as follows:

M(i, j) = 0 for i = j M(i, j) = min{M(i, k) + M(k+1, j) + p(i-1)p(k)p(j)} for i ≤ k < j

Here, `M(i, j)`

represents the minimum number of operations required to multiply the matrices from `i`

to `j`

, and `p`

is an array containing the dimensions of the matrices.

### Solving Matrix Chain Multiplication Using Dynamic Programming

We can solve the Matrix Chain Multiplication problem using Dynamic Programming by following these steps:

- Define the problem and identify its subproblems.
- Develop a recursive relation to solve the problem.
- Create a memoization table to store the results of subproblems.
- Use the memoization table to solve the problem iteratively.

### Practical Applications of Matrix Chain Multiplication

Matrix Chain Multiplication has practical applications in various fields, including computer graphics, cryptography, and machine learning. For example, it is used in the training of neural networks, which involve the multiplication of large matrices.

## DAA-2022

## Q-1.

(b) Discuss the concept of asymptotic notation and its properties.

## Q-2.

## Q-3

## Q-4

What is Huffman code ? discuss the greedy algorithm for constructing the Huffman code.

## Q-5

## Q-6

## Q-7

What is bitonic sequence ? discuss bitonic sort algorithm and it’s time complexity.

## Q-8

What is sorting Network ? Discuss the structure of bubble sorting network.