Introduction to Matrix Chain Multiplication algorithm with an example. Matrix Chain Products algorithm comes under Dynamic Programming concept. Done for the course Advanced Data Structures and Algorithms.
This slide first introduces the sequential pattern mining problem and also presents some required definitions in order to understand GSP algorithm. At then end there is a brief introduction of GSP algorithm and some practical constraints which it supports.
Dynamic Programming is a method for solving a complex problem by breaking it down into a collection of simpler subproblems, solving each of those subproblems just once, and storing their solutions using a memory-based data structure (array, map,etc).
This slide first introduces the sequential pattern mining problem and also presents some required definitions in order to understand GSP algorithm. At then end there is a brief introduction of GSP algorithm and some practical constraints which it supports.
Dynamic Programming is a method for solving a complex problem by breaking it down into a collection of simpler subproblems, solving each of those subproblems just once, and storing their solutions using a memory-based data structure (array, map,etc).
( Python Training: https://www.edureka.co/python )
This Edureka Python Numpy tutorial (Python Tutorial Blog: https://goo.gl/wd28Zr) explains what exactly is Numpy and how it is better than Lists. It also explains various Numpy operations with examples.
Check out our Python Training Playlist: https://goo.gl/Na1p9G
This tutorial helps you to learn the following topics:
1. What is Numpy?
2. Numpy v/s Lists
3. Numpy Operations
4. Numpy Special Functions
( Python Training: https://www.edureka.co/python )
This Edureka Python Numpy tutorial (Python Tutorial Blog: https://goo.gl/wd28Zr) explains what exactly is Numpy and how it is better than Lists. It also explains various Numpy operations with examples.
Check out our Python Training Playlist: https://goo.gl/Na1p9G
This tutorial helps you to learn the following topics:
1. What is Numpy?
2. Numpy v/s Lists
3. Numpy Operations
4. Numpy Special Functions
Question 1 1. Evaluate using integration by parts. l.docxmakdul
Question 1
1.
Evaluate using integration by parts.
ln x - + C
x2 ln x - + C
x2 ln x - x2 + C
x ln x - x + C
2 points
Question 2
1.
Evaluate using integration by parts.
x2e2x - xe2x + e2x + C
x2e2x - xe2x + e2x + C
x2e2x - xe2x + C
x2e2x - xe2x + e2x + C
2 points
Question 3
1.
Evaluate. Assume u > 0 when ln u appears.
dy
2e4y + C
e4y + C
4e4y + C
e4y + C
2 points
Question 4
1.
Find the particular solution determined by the given condition.
f'(x) = 6x2 - 4x + 21; f(1) = 17
f(x) = 2x3 - 4x2 + 21x - 2
f(x) = 6x3 - 4x2 + 21x - 6
f(x) = 2x3 - 2x2 + 21x + 4
f(x) = 2x3 - 2x2 + 21x - 4
2 points
Question 5
1.
Find the particular solution determined by the given condition.
y' = ; y = 21 when x = 1
y = 5 ln x + 21
y = ln x + 19
y = 5 ln x + 2.5
y = ln x + 21
2 points
Question 6
1.
Determine if the function is a solution to the given differential equation.
y = x ln x - 4x + 5; y'' - = 0.
Yes
No
2 points
Question 7
1.
Evaluate using integration by parts.
(x2 - x) ln (16x) - + 2x + C
(x2 - x) ln (16x) - + x + C
ln (16x) - + x + C
(x2 - x) ln (16x) - x2 + x + C
2 points
Question 8
1.
Find the general solution for the differential equation.
= 4P
P = 4eCt
P = Ce4t
P = Ce-4t
P = Cet
2 points
Question 9
1.
Evaluate. Assume u > 0 when ln u appears.
dt
e-7t2 + C
- e-7t2 + C
e-7t2 + C
- e-7t2 + C
2 points
Question 10
1.
Find the general solution for the differential equation.
y ' = 72x2 - 20x
72x3 - 20x2 + C
24x3 - 20x2 + C
72x3 - 10x2 + C
24x3 - 10x2 + C
2 points
Question 11
1.
Find the general solution for the differential equation.
y ' = x - 16
2x2 - 16 + C
- 16x + C
- x + C
x3 - 16x + C
2 points
Question 12
1.
Evaluate using integration by parts.
e4xdx
(x - 8) e4x - e4x + C
(x - 8) e4x + e4x + C
4(x - 8) e4x - 16 e4x + C
(x - 8) e4x - e4x + C
2 points
Question 13
1.
Evaluate using integration by parts.
dx
5x(2x + 3)1/2 + (2x + 3)3/2 + C
5x(2x + 3)1/2 - (2x + 3)3/2 + C
x(2x + 3)1/2 - (2x + 3)3/2 + C
5x(2x + 3)1/2 - (2x + 3)3/2 + C
2 points
Question 14
1.
Write the first four elements of the sequence.
n
0, 2, ,
2, , ,
1, , ,
0, 1, ,
2 points
Question 15
1.
Evaluate. Assume u > 0 when ln u appears.
dx
+ C
+ C
+ C
(ln 6x)2 + C
2 points
Question 16
1.
Evaluate. Assume u > 0 when ln u appears.
dp
e5p2+ C
- e5p2 + C
7e5p2 + C
-7e5p2 + C
2 points
Question 17
1.
Evaluate. Assume u > 0 when ln u appears.
dy
ln + C
18 ln + C
19 ln + C
ln + C
2 points
Question 18
1.
Evaluate using integration by parts.
dx
x(ln 2x)2 - 2 ln (2x) + C
ln (2x)2 - 2x ln (2x) - 2x + C
x(ln 2x)2 + 2x ln (2x) + 2x + C
x(ln 2x)2 - 2x ln (2x) + 2x + C
2 points
Question 19
1.
Evaluate using integration by parts.
ln x dx
x2ln x - x2 + C
ln x - x2 + C
x2ln x - x2 + 5x + C
x2ln x - x2 - 5x + C
2 ...
Practical and Worst-Case Efficient ApportionmentRaphael Reitzig
Proportional apportionment is the problem of assigning seats to parties according to their relative share of votes. Divisor methods are the de-facto standard solution, used in many countries.
In recent literature, there are two algorithms that implement divisor methods: one by Cheng and Eppstein (ISAAC, 2014) has worst-case optimal running time but is complex, while the other (Pukelsheim, 2014) is relatively simple and fast in practice but does not offer worst-case guarantees.
This talk presents the ideas behind a novel algorithm that avoids the shortcomings of both. We investigate the three contenders in order to determine which is most useful in practice.
Read more over here: http://reitzig.github.io/publications/RW2015b
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdffxintegritypublishin
Advancements in technology unveil a myriad of electrical and electronic breakthroughs geared towards efficiently harnessing limited resources to meet human energy demands. The optimization of hybrid solar PV panels and pumped hydro energy supply systems plays a pivotal role in utilizing natural resources effectively. This initiative not only benefits humanity but also fosters environmental sustainability. The study investigated the design optimization of these hybrid systems, focusing on understanding solar radiation patterns, identifying geographical influences on solar radiation, formulating a mathematical model for system optimization, and determining the optimal configuration of PV panels and pumped hydro storage. Through a comparative analysis approach and eight weeks of data collection, the study addressed key research questions related to solar radiation patterns and optimal system design. The findings highlighted regions with heightened solar radiation levels, showcasing substantial potential for power generation and emphasizing the system's efficiency. Optimizing system design significantly boosted power generation, promoted renewable energy utilization, and enhanced energy storage capacity. The study underscored the benefits of optimizing hybrid solar PV panels and pumped hydro energy supply systems for sustainable energy usage. Optimizing the design of solar PV panels and pumped hydro energy supply systems as examined across diverse climatic conditions in a developing country, not only enhances power generation but also improves the integration of renewable energy sources and boosts energy storage capacities, particularly beneficial for less economically prosperous regions. Additionally, the study provides valuable insights for advancing energy research in economically viable areas. Recommendations included conducting site-specific assessments, utilizing advanced modeling tools, implementing regular maintenance protocols, and enhancing communication among system components.
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Dr.Costas Sachpazis
Terzaghi's soil bearing capacity theory, developed by Karl Terzaghi, is a fundamental principle in geotechnical engineering used to determine the bearing capacity of shallow foundations. This theory provides a method to calculate the ultimate bearing capacity of soil, which is the maximum load per unit area that the soil can support without undergoing shear failure. The Calculation HTML Code included.
Hierarchical Digital Twin of a Naval Power SystemKerry Sado
A hierarchical digital twin of a Naval DC power system has been developed and experimentally verified. Similar to other state-of-the-art digital twins, this technology creates a digital replica of the physical system executed in real-time or faster, which can modify hardware controls. However, its advantage stems from distributing computational efforts by utilizing a hierarchical structure composed of lower-level digital twin blocks and a higher-level system digital twin. Each digital twin block is associated with a physical subsystem of the hardware and communicates with a singular system digital twin, which creates a system-level response. By extracting information from each level of the hierarchy, power system controls of the hardware were reconfigured autonomously. This hierarchical digital twin development offers several advantages over other digital twins, particularly in the field of naval power systems. The hierarchical structure allows for greater computational efficiency and scalability while the ability to autonomously reconfigure hardware controls offers increased flexibility and responsiveness. The hierarchical decomposition and models utilized were well aligned with the physical twin, as indicated by the maximum deviations between the developed digital twin hierarchy and the hardware.
About
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
• Remote control: Parallel or serial interface.
• Compatible with MAFI CCR system.
• Compatible with IDM8000 CCR.
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
• Easy in configuration using DIP switches.
Technical Specifications
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
Key Features
Indigenized remote control interface card suitable for MAFI system CCR equipment. Compatible for IDM8000 CCR. Backplane mounted serial and TCP/Ethernet communication module for CCR remote access. IDM 8000 CCR remote control on serial and TCP protocol.
• Remote control: Parallel or serial interface
• Compatible with MAFI CCR system
• Copatiable with IDM8000 CCR
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
Application
• Remote control: Parallel or serial interface.
• Compatible with MAFI CCR system.
• Compatible with IDM8000 CCR.
• Compatible with Backplane mount serial communication.
• Compatible with commercial and Defence aviation CCR system.
• Remote control system for accessing CCR and allied system over serial or TCP.
• Indigenized local Support/presence in India.
• Easy in configuration using DIP switches.
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxR&R Consult
CFD analysis is incredibly effective at solving mysteries and improving the performance of complex systems!
Here's a great example: At a large natural gas-fired power plant, where they use waste heat to generate steam and energy, they were puzzled that their boiler wasn't producing as much steam as expected.
R&R and Tetra Engineering Group Inc. were asked to solve the issue with reduced steam production.
An inspection had shown that a significant amount of hot flue gas was bypassing the boiler tubes, where the heat was supposed to be transferred.
R&R Consult conducted a CFD analysis, which revealed that 6.3% of the flue gas was bypassing the boiler tubes without transferring heat. The analysis also showed that the flue gas was instead being directed along the sides of the boiler and between the modules that were supposed to capture the heat. This was the cause of the reduced performance.
Based on our results, Tetra Engineering installed covering plates to reduce the bypass flow. This improved the boiler's performance and increased electricity production.
It is always satisfying when we can help solve complex challenges like this. Do your systems also need a check-up or optimization? Give us a call!
Work done in cooperation with James Malloy and David Moelling from Tetra Engineering.
More examples of our work https://www.r-r-consult.dk/en/cases-en/
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...Amil Baba Dawood bangali
Contact with Dawood Bhai Just call on +92322-6382012 and we'll help you. We'll solve all your problems within 12 to 24 hours and with 101% guarantee and with astrology systematic. If you want to take any personal or professional advice then also you can call us on +92322-6382012 , ONLINE LOVE PROBLEM & Other all types of Daily Life Problem's.Then CALL or WHATSAPP us on +92322-6382012 and Get all these problems solutions here by Amil Baba DAWOOD BANGALI
#vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore#blackmagicformarriage #aamilbaba #kalajadu #kalailam #taweez #wazifaexpert #jadumantar #vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore #blackmagicforlove #blackmagicformarriage #aamilbaba #kalajadu #kalailam #taweez #wazifaexpert #jadumantar #vashikaranspecialist #astrologer #palmistry #amliyaat #taweez #manpasandshadi #horoscope #spiritual #lovelife #lovespell #marriagespell#aamilbabainpakistan #amilbabainkarachi #powerfullblackmagicspell #kalajadumantarspecialist #realamilbaba #AmilbabainPakistan #astrologerincanada #astrologerindubai #lovespellsmaster #kalajaduspecialist #lovespellsthatwork #aamilbabainlahore #Amilbabainuk #amilbabainspain #amilbabaindubai #Amilbabainnorway #amilbabainkrachi #amilbabainlahore #amilbabaingujranwalan #amilbabainislamabad
Overview of the fundamental roles in Hydropower generation and the components involved in wider Electrical Engineering.
This paper presents the design and construction of hydroelectric dams from the hydrologist’s survey of the valley before construction, all aspects and involved disciplines, fluid dynamics, structural engineering, generation and mains frequency regulation to the very transmission of power through the network in the United Kingdom.
Author: Robbie Edward Sayers
Collaborators and co editors: Charlie Sims and Connor Healey.
(C) 2024 Robbie E. Sayers
2. What is Dynamic Programming?
• Dynamic Programming refers to simplifying a complicated problem by
breaking it down into simpler sub-problems in a recursive manner.
• Dynamic Programming techniques:
• Simple Subproblems
• Subproblems Optimality
• Subproblem Overlap
3. Matrix Chain Product
• Matrix chain multiplication is an optimization problem concerning the
most efficient way to multiply a given sequence of matrices
• The problem is not actually to perform the multiplications, but merely
to decide the sequence of the matrix multiplications involved.
• There are many options because matrix multiplication is associative.
In other words, no matter how the product is parenthesized, the
result obtained will remain the same.
4. Consider 2x3 matrices A, B, and C:
• We, can perform matrix Multiplication in the following ways:
i) (A x B) x C
ii) A x (B x C)
• Note: Matrix Multiplication is Associative.
5. Matrix Multiplication
• Let us consider two matrices A and B:
𝐴 =
𝑎11 𝑎12 𝑎13
𝑎21 𝑎22 𝑎23
𝐵 =
𝑏11 𝑏12
𝑏21 𝑏22
𝑏31 𝑏32
2 x 3 3 x 2
6. Matrix Multiplication
• Let us consider two matrices A and B of dimensions 2 x 3:
𝐴 =
𝑎11 𝑎12 𝑎13
𝑎21 𝑎22 𝑎23
𝐵 =
𝑏11 𝑏12
𝑏21 𝑏22
𝑏31 𝑏32
2 x 3 3 x 2
Condition for Matrix Multiplication
7. Matrix Multiplication
𝐴 =
𝑎11 𝑎12 𝑎13
𝑎21 𝑎22 𝑎23
𝐵 =
𝑏11 𝑏12
𝑏21 𝑏22
𝑏31 𝑏32
• So, the product of two matrices A and B is given by:
𝑎11𝑏11 + 𝑎12𝑏21 + 𝑎13𝑏31 𝑎11𝑏12 + 𝑎12𝑏22 + 𝑎13𝑏32
𝑎21𝑏11 + 𝑎22𝑏21 + 𝑎23𝑏31 𝑎21𝑏12 + 𝑎22𝑏22 + 𝑎23𝑏32
8. Matrix Multiplication
𝐴 =
𝑎11 𝑎12 𝑎13
𝑎21 𝑎22 𝑎23
𝐵 =
𝑏11 𝑏12
𝑏21 𝑏22
𝑏31 𝑏32
• So, the product of two matrices A and B is given by:
1 2 3 4 5 6
𝑎11𝑏11 + 𝑎12𝑏21 + 𝑎13𝑏31 𝑎11𝑏12 + 𝑎12𝑏22 + 𝑎13𝑏32
𝑎21𝑏11 + 𝑎22𝑏21 + 𝑎23𝑏31 𝑎21𝑏12 + 𝑎22𝑏22 + 𝑎23𝑏32
7 8 9 10 11 12
9. Matrix Multiplication
• To calculate the number of multiplication operations required for a
given matrix, we can use the below technique:
𝐴 =
𝑎11 𝑎12 𝑎13
𝑎21 𝑎22 𝑎23
𝐵 =
𝑏11 𝑏12
𝑏21 𝑏22
𝑏31 𝑏32
2 x 3 3 x 2
Total Number of Multiplication required = 2 x 3 x 2 = 12 operations
13. Parenthesization
(A1 x A2) x A3
2 3 3 4 4 2
Number of Operations: C[1, 2] = 2 x 3 x 4 = 24 C[3, 3] = 0
New Dimension: 2 x 4 4 x 2
Number of Operations: 2 x 4 x 2 = 16
Total Number of operations: 24 + 16 = 40 Multiplications
General Notation for this operation: C[1, 2] + C[3, 3] + d0 + d2 + d3 = 40 ------------------------------ (i)
15. Paranthesization
A1 x (A2 x A3)
2 3 3 4 4 2
Number of Operations: C[1, 1] = 0 C[2, 3] = 3 x 4 x 2 = 24
New Dimension: 2 x 3 3 x 2
Number of Operations: 2 x 3 x 2 = 12
Total Number of operations: 24 + 12 = 38 Multiplications
General Notation for this operation: C[1, 1] + C[2, 3] + d0 + d1 + d3 = 38 ------------------------------ (ii)
17. Parenthesization
• From Equation (i) and (ii):
C[1, 2] + C[3, 3] + d0 + d2 + d3 = 40 C[1, 1] + C[2, 3] + d0 + d1 + d3 = 38
>
This is the optimal solution among the two ways
18. Parenthesization
• From Equation (i) and (ii), we can derive the generalized form
C[1, 2] + C[3, 3] + d0 + d2 + d3 = 40 C[1, 1] + C[2, 3] + d0 + d1 + d3 = 38
>
C[i, j] = min { C[i, k] + C[k + 1, j] + di-1 x dk x dj}
I ≤ k < j
19. Parenthization
• The possible number of ways the given matrices can be parenthized
using the below formula:
𝐶(𝑛 −1)
2(𝑛 −1)
𝑛
Where:
n – Number of matrices for multiplication
20. Example Problem:
• Let us consider four matrices namely A1, A2, A3, and A4 of dimensions d0, d1,
d2, d3, and d4 respectively. Find the optimal matrix multiplication.
A1 x A2 x A3 x A4
d0 d1 d1 d2 d2 d3 d3 d4
3 2 2 4 4 2 2 5
The number of possible ways the matrices can be parenthesized:
Here, n = 4
𝐶(𝑛 −1)
2(𝑛 −1)
𝑛 =
𝐶(4 −1)
2(4 −1)
4 =
𝐶3
6
4 =
6 𝑋 5 𝑋 4
3 𝑋 2 𝑋 1
4 = 5. Hence there are 5 five possible ways of parenthesization.
21. Example Problem
• The following are 5 different ways of parenthesization:
1. A1 X (A2 X (A3 X A4))
2. A1 X ((A2 X A3) X A4)
3. (A1 X A2) X (A3 X A4)
4. (A1 X (A2 X A3)) X A4
5. ((A1 X A2) X A3) X A4
22. Example Problem
• Let us consider 2 tables to arrange the resultant cost and k-values.
1 2 3 4 1 2 3 4
00
0
0
0
1
2
3
4
1
2
3
4
i
j
k
C
i
j
23. Example Problem
• Let us find the C[1, 2]: C[i, j] = min { C[i, k] + C[k + 1, j] + di-1 x dk x dj}
I ≤ k < j
C[1, 2] = min { C[1, 1] + C[2, 2] + d0 x d1 x d2}
1 ≤ 1< 2
K = 1
= 0 + 0 + 3 x 2 x 4
= 24
0 24
0
0
0
1
Cost K value
1 2 3 4 1 2 3 4
1
2
3
4
1
2
3
4
24. Example Problem
• Let us find the C[2, 3]: C[i, j] = min { C[i, k] + C[k + 1, j] + di-1 x dk x dj}
I ≤ k < j
C[2, 3] = min { C[2, 2] + C[3, 3] + d1 x d2 x d3}
2 ≤ 2< 3
K = 2
= 0 + 0 + 2 x 4 x 2
= 16
0 24
0 16
0
0
1
2
Cost K value
1 2 3 4 1 2 3 4
1
2
3
4
1
2
3
4
25. Example Problem
• Let us find the C[3, 4]: C[i, j] = min { C[i, k] + C[k + 1, j] + di-1 x dk x dj}
I ≤ k < j
C[3, 4] = min { C[3, 3] + C[4, 4] + d2 x d3 x d4}
3 ≤ 3< 4
K = 3
= 0 + 0 + 4 x 2 x 5
= 40
0 24
0 16
0 40
0
1
2
3
Cost K value
1 2 3 4 1 2 3 4
1
2
3
4
1
2
3
4
26. Example Problem
• Let us find the C[1, 3]: C[i, j] = min { C[i, k] + C[k + 1, j] + di-1 x dk x dj}
I ≤ k < j
C[1, 3] = min C[1, 1] + C[2, 3] + d0 x d1 x d3 = 0 + 16 + 3 x 2 x 2 = 28
C[1, 2] + C[3, 3] + d0 x d2 x d3 = 24 + 0 + 3 x 4 x 2 = 48 When, K = 2
0 24 28
0 16
0 40
0
1 1
2
3
Cost K value
1 2 3 4 1 2 3 4
1
2
3
4
1
2
3
4
When, K = 1
1 ≤ k < 3
27. Example Problem
• Let us find the C[2, 4]: C[i, j] = min { C[i, k] + C[k + 1, j] + di-1 x dk x dj}
I ≤ k < j
C[2, 4] = min C[2, 2] + C[3, 4] + d1 x d2 x d4 = 0 + 40 + 2 x 4 x 5 = 80
C[2, 3] + C[4, 4] + d1 x d3 x d4 = 16 + 0 + 2 x 2 x 5 = 36 When, K = 3
0 24 28
0 16 36
0 40
0
1 1
2 3
3
Cost K value
1 2 3 4 1 2 3 4
1
2
3
4
1
2
3
4
When, K = 2
2 ≤ k < 4
28. Example Problem
• Let us find the C[1, 4]: C[i, j] = min { C[i, k] + C[k + 1, j] + di-1 x dk x dj}
I ≤ k < j
C[1, 4] = min C[1, 1] + C[2, 4] + d0 x d1 x d4 = 0 + 36 + 3 x 2 x 5 =66
C[1, 2] + C[3, 4] + d0 x d2 x d4 = 24 + 40 + 3 x 4 x 5 = 124
C[1, 3] + C[4, 4] + d0 x d3 x d4 = 28 + 0 + 3 x 2 x 5 = 58
When, K = 2
0 24 28 58
0 16 36
0 40
0
1 1 3
2 3
3
Cost K value
1 2 3 4 1 2 3 4
1
2
3
4
1
2
3
4
When, K = 1
When, K = 3
1 ≤ k < 4
29. Example Problem
0 24 28 58
0 16 36
0 40
0
1 1 3
2 3
3
Cost K value
1 2 3 4 1 2 3 4
1
2
3
4
1
2
3
4
• From the k-value table, we can parenthesize the given matrices:
A1 x A2 x A3 x A4
(A1 x A2 x A3) x A4
(A1 x (A2 x A3)) x A4
((A1) x (A2 x A3)) x A4
A1 A2 A3 A4
30. Effectiveness of Parenthesization
• Example:
B is 3 x 100
C is 100 x 5
D is 5 x 5
(B x C) x D takes 1500 + 75 = 1575 operations
B x (C x D) takes 1500 + 2500 = 4000 operations
31. Naïve Approach
• In naïve approach, we try the brute-force method of finding all
possible parenthesization methods and then to choose the optimal
method.
• The number of paranthesizations will be equal to number of binary
trees with n nodes.
• This is Exponential in time
• This is called the Catalan number, and it is almost 4n
32. Greedy Approach - 1
• Repeatedly select the product that uses the most operations.
A is 10 x 5
B is 5 x 10
C is 10 x 5
D is 5 x 10
(A x B) x (C x D) takes 500 + 1000 + 500 = 2000 operations
A x ((B x C) x D) takes 500 + 250 + 250 = 1000 operations
33. Greedy Approach - 2
• Repeatedly select the product that uses the fewest operations.
A is 101 x 11
B is 11 x 9
C is 9 x 100
D is 100 x 99
A x ((B x C) x D)) takes 109989 + 9900 + 108900 = 228789 operations.
(A x B) x (C x D) takes 9999 + 89991 + 89100 = 189090 operations
34. Dynamic Programming Algorithm: Matrix-
Chain Multiplication
Algorithm matrixChain(S):
Input: sequence S of n matrices to be multiplied
Output: number of operations in an optimal parentheization of S
for i <- 1 to n-1 do
Ni,i <- 0
for b <- 1 to n-1 do
for i <- 0 to n-b-1 do
j <- i + b
Ni,j <- +infinity
for k <- i to j-1 do
Ni,j <- min {Ni,j, Ni,k + Nk+1,j + di x dk+1 x dj+1}
35. Dynamic Programming Algorithms:
• The subproblems here are not independent, the subproblems
overlap.
• Since subproblems overlaps, we don’t use recursion.
• Instead we construct optimal subproblems “bottom-up”.
• The running time is O(n3).
36. Reference
• Matrix Chain Multiplication - Dynamic Programming – Abdul
Bari. https://youtu.be/prx1psByp7U?si=bvn_xBi78xEl3HQI
• Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein. 2009. Introduction to
Algorithms, Third Edition (3rd. ed.). The MIT Press.
• Steven S. Skiena. 2008. The Algorithm Design Manual (2nd. ed.). Springer Publishing Company,
Incorporated.