SlideShare a Scribd company logo
ALGORITHMS II LAB
PRESENTATION
Presented By:-
Rishabh Kumar Sharma, Gx-05
Aman Prasad, Gx-07
Abhishek Chandra, Gx-25
Debtanu Pal, Gx-24
IIEST SHIBPUR
CONTENTS
• Assignment on Dynamic Programming
– Matrix Chain Multiplication
• Naive Recursive Approach
• Dynamic Programming Approach
• Memoized Matrix Chain
• Comparison between the 2 approaches
• Extension of the Dynamic Programming Approach for
Matrix Multiplication to Polygon Triangulation
CONTENTS
• Assignment on Greedy Algorithms
– Huffman Compression Algorithm
● Study variation of average codeword length with change
in the probability of occurrence of a symbol
DYNAMIC PROGRAMMING
• A Dynamic Programming Approach to a problem is taken
when a problem has the following 2 properties:-
– Optimal Substructure :- Optimal Solution to a problem
includes within it the optimal solution to a subproblem.
– Overlapping Subproblems
RECURSIVE MATRIX CHAIN
RMC(p,i,j)
if i==j then return zero
m[i,j]=INF
for k=i to j-1
q=RMC(p,i,k)+RMC(p,k+1,j)+p(i-1)*p(k)*p(j)
if q<m[i,j]
m[i,j]=q
Return m[i,j]
Time Complexity of running this one:
T(n) ≥ 1+∑(T(k)+T(n-k)+1) ≥ 2 ∑ T(i) +n ≥ 2^n - 1
OBSERVATIONS:-RECURSIVE MATRIX
CHAIN
INPUT
SIZE
COMPARIS
ONS
PARENTHE
SIZATIONS
2 1 1
4 13 5
6 121 42
8 1093 429
10 9841 4862
12 88573 58786
14 797161 742900
The No. Of comparisons of a size ‘n’ Input is comparable
to the CATALAN Number:
c(n) == (4^n)/(n^(3/2))
REASON
We have to check each and every possible parenthesization
and hence solve a large no. Of problems repeatedly.
MATRIX CHAIN MUL. USING DP
MATRIX-CHAIN-ORDER (p)
n=length[p]-1
for i=1 to n
m[i,i]=0
for l=2 to n
for i=1 to n-l+1
j=i+l-1
m[i,j]=INF
for k=i to j-1
q=m[i,k]+m[k+1,j]+pi-1pkpj
if q< m[i,j]
m[i,j]=q ; s[i,j]=k
Return m and s
HISTOGRAM COMPARISON
MATRIX CHAIN MULTIPLICATION
USING BRUTE FORCE APPROACH
MATRIX CHAIN MULTIPLICATION
USING DP
Comparison Between Recursive and
Dynamic Programming Approach
MATRIX CHAIN MULTIPLICATION USING
MEMOIZATION
Mem-Matrix-Chain(array p, int i, int j) {
if (m[i, j] != UNDEFINED) then 
     return m[i, j];     // already defined
    else if ( i = = j) then 
        m[i, i] = 0;     // basic case
    else {
       m[i, j] = infinity;    // initialize
       for k = i to j − 1 do {// try all splits
          cost = Mem-Matrix-Chain(p,i,k) +
Mem-Matrix-Chain(p,k+1,j)+ p[i−1]p[k]p[j];
    if (cost < m[i, j]) then   // update if better
              m[i, j] = cost; 
       } 
      } 
      return m[i, j];           // return final cost
}
POLYGON TRIANGULATION COMPARISON
WITH MATRIX CHAIN MULTIPLICATION
MATRIX CHAIN MULTIPLICATION
• Problem involves finding the
optimal parenthesization so that
no. Of multiplications is
minimum.
• Optimal Substructure –
Subproblems consist of finding
minimum no. Of multiplication of
the smaller subchains
• Bottom up approach consists of a
table in which we keep record of
the particular parenthesization
for which the multiplication is
minimum.
POLYGON TRIANGULATION
• Problem involves finding the optimal
triangulation so that the perimeter
of the resulting triangulation is
minimum.
• Optimal Substructure- Subproblems
consist of finding minimum cost
subpolygons on the left and right
side of the first triangulation.
• Bottom up approach consists of a
table which keeps records of the
smaller polygons(and the minimum
perimeter to triangulate these)
ALGORITHM
for (int gap = 0; gap < n; gap++)
for (int i = 0, j = gap; j < n; i++, j++)
if (j < i+2){
table[i][j] = 0 ;
//INITIALIZATION OF THE TABLE TO STORE MINIMAL TRIANGULATION COST
tri[i][j]=0;
}
else{
table[i][j] = MAX;
for (int k = i+1; k < j; k++){
double val = table[i][k] + table[k][j] + cost(points,i,j,k);
//CALCULATING THE COST OF THE GIVEN TRIANGULATION
if (table[i][j] > val) {
// COMPARING WITH THE VALUES IN TABLE TO FIND MINIMAL TRIANGULATION
table[i][j] = val;
tri[i][j]=k;
} c++;
}
return table[0][n-1];
OVERLAPPING SUBPROBLEMS
A SMALL EXAMPLE
OPTIMAL
TRIANGULATION:
COST – 15.30
ANOTHER
TRIANGULATION:
COST – 15.77
KRUSKAL'S ALGORITHM
• 1. Sort all the edges in non-decreasing order of their weight.
• 2. Pick the smallest edge. Check if it forms a cycle with the spanning tree
formed so far. If cycle is not formed, include this edge. Else, discard it. //
GREEDY ELEMENT
• 3. To check the existence of cycle, check whether for two vertices x and
y. Find_set(x)==Find_set(y), or not. If equal they already belong to the
same disjoint set(tree), hence will form a cycle if they are joined. So
edge(x,y) will not belong to the MST. // DISJOINT SETS
• 4. Repeat step 2 until there are (V-1) edges in the spanning tree.
TIME COMPLEXITY
• Time Complexity: O(ElogE) or O(ElogV).
• Sorting of edges takes O(ELogE) time.
• After sorting, we iterate through all edges and apply
find-union algorithm.
• The find and union operations can take atmost O(LogV) time.
• So overall complexity is O(ELogE + ELogV) time.
• The value of E can be atmost O(V2
), so O(LogV) are O(LogE)
same.
• Therefore, overall time complexity is O(ElogE) or O(ElogV)
OBSERVATIONS
• Increase in no. Of comparisons keeping the no. Of
vertices constant.
EDGES VERTICES No. OF COMP E*log(V)
2000 500 39863 17931
3000 500 61549 26897
4000 500 83726 35863
5000 500 106267 44829
6000 500 129099 53794
9000 500 198913 `81692
Graphical Representation
X-axis: Input number Y-axis: No. Of Comparisons
OBSERVATIONS
• Increase in no. Of comparisons keeping the
no. Of vertices constant.
EDGES VERTICES COMP
5000 500 106267
5000 600 107582
5000 700 108694
5000 800 109657
5000 900 111267
Graphical Representation
COMPARISON
EDGES INC. VERTICES CONST. VERTICES INC. EDGES CONST.
COMPARISON
EDGES INC. VERTICES CONST.
EDGES VERTICES COMP.
5000 500 106267
5100 500 108539
5200 500 110812
5300 500 114089
VERTICES CONST. EDGES INC.
EDGES VERTICES COMP.
5000 500 106267
5000 600 107583
5000 700 108695
5000 800 109658
VALUE OF c and n0.... QUICKSORT
ASSIGNMENT
• We have the no. Of comparisons(yi) and the corresponding
input size(xi).
• Fit these points to the curve f(x)=axlogx +bx +c.
• Use the method of least squares.
• R^2 = (yi-f(xi))^2.
• Take Partial derivative of R^2 w.r.t a,b and c... And equate to
0.
• We get 3 variables and 3 equations.
• Finally, a=1.792, b= -7.48, c=79.8962.

More Related Content

What's hot

Analysis of algorithn class 3
Analysis of algorithn class 3Analysis of algorithn class 3
Analysis of algorithn class 3
Kumar
 
digital control Chapter 2 slide
digital control Chapter 2 slidedigital control Chapter 2 slide
digital control Chapter 2 slide
asyrafjpk
 
Seismic data processing lecture 4
Seismic data processing lecture 4Seismic data processing lecture 4
Seismic data processing lecture 4
Amin khalil
 
Convolution linear and circular using z transform day 5
Convolution   linear and circular using z transform day 5Convolution   linear and circular using z transform day 5
Convolution linear and circular using z transform day 5
vijayanand Kandaswamy
 
Applications of Z transform
Applications of Z transformApplications of Z transform
Applications of Z transform
AakankshaR
 
Z transform
Z transformZ transform
Z transform
ayushagrawal464
 
asymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysisasymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysis
Anindita Kundu
 
Lti and z transform
Lti and z transformLti and z transform
Lti and z transform
pranvendra29
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
Rishabh Soni
 
Spline Interpolation
Spline InterpolationSpline Interpolation
Spline Interpolation
aiQUANT
 
inverse z transform
inverse z transforminverse z transform
inverse z transform
Zlatan Ahmadovic
 
Lec 5 asymptotic notations and recurrences
Lec 5 asymptotic notations and recurrencesLec 5 asymptotic notations and recurrences
Lec 5 asymptotic notations and recurrences
Ankita Karia
 
Application of Convolution Theorem
Application of Convolution TheoremApplication of Convolution Theorem
Application of Convolution Theorem
ijtsrd
 
Z TRANSFORM PROPERTIES AND INVERSE Z TRANSFORM
Z TRANSFORM PROPERTIES AND INVERSE Z TRANSFORMZ TRANSFORM PROPERTIES AND INVERSE Z TRANSFORM
Z TRANSFORM PROPERTIES AND INVERSE Z TRANSFORM
Towfeeq Umar
 
Discreate time system and z transform
Discreate time system and z transformDiscreate time system and z transform
Discreate time system and z transform
VIKAS KUMAR MANJHI
 
Dcs lec02 - z-transform
Dcs   lec02 - z-transformDcs   lec02 - z-transform
Dcs lec02 - z-transform
Amr E. Mohamed
 
report
reportreport
report
murali vnv
 
Pseudo Random Number Generators
Pseudo Random Number GeneratorsPseudo Random Number Generators
Pseudo Random Number Generators
Darshini Parikh
 
Design of sampled data control systems part 2. 6th lecture
Design of sampled data control systems part 2.  6th lectureDesign of sampled data control systems part 2.  6th lecture
Design of sampled data control systems part 2. 6th lecture
Khalaf Gaeid Alshammery
 
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and SystemsDSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
Amr E. Mohamed
 

What's hot (20)

Analysis of algorithn class 3
Analysis of algorithn class 3Analysis of algorithn class 3
Analysis of algorithn class 3
 
digital control Chapter 2 slide
digital control Chapter 2 slidedigital control Chapter 2 slide
digital control Chapter 2 slide
 
Seismic data processing lecture 4
Seismic data processing lecture 4Seismic data processing lecture 4
Seismic data processing lecture 4
 
Convolution linear and circular using z transform day 5
Convolution   linear and circular using z transform day 5Convolution   linear and circular using z transform day 5
Convolution linear and circular using z transform day 5
 
Applications of Z transform
Applications of Z transformApplications of Z transform
Applications of Z transform
 
Z transform
Z transformZ transform
Z transform
 
asymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysisasymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysis
 
Lti and z transform
Lti and z transformLti and z transform
Lti and z transform
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic Notations
 
Spline Interpolation
Spline InterpolationSpline Interpolation
Spline Interpolation
 
inverse z transform
inverse z transforminverse z transform
inverse z transform
 
Lec 5 asymptotic notations and recurrences
Lec 5 asymptotic notations and recurrencesLec 5 asymptotic notations and recurrences
Lec 5 asymptotic notations and recurrences
 
Application of Convolution Theorem
Application of Convolution TheoremApplication of Convolution Theorem
Application of Convolution Theorem
 
Z TRANSFORM PROPERTIES AND INVERSE Z TRANSFORM
Z TRANSFORM PROPERTIES AND INVERSE Z TRANSFORMZ TRANSFORM PROPERTIES AND INVERSE Z TRANSFORM
Z TRANSFORM PROPERTIES AND INVERSE Z TRANSFORM
 
Discreate time system and z transform
Discreate time system and z transformDiscreate time system and z transform
Discreate time system and z transform
 
Dcs lec02 - z-transform
Dcs   lec02 - z-transformDcs   lec02 - z-transform
Dcs lec02 - z-transform
 
report
reportreport
report
 
Pseudo Random Number Generators
Pseudo Random Number GeneratorsPseudo Random Number Generators
Pseudo Random Number Generators
 
Design of sampled data control systems part 2. 6th lecture
Design of sampled data control systems part 2.  6th lectureDesign of sampled data control systems part 2.  6th lecture
Design of sampled data control systems part 2. 6th lecture
 
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and SystemsDSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
DSP_FOEHU - MATLAB 01 - Discrete Time Signals and Systems
 

Similar to Algorithms Lab PPT

Chapter 5.pptx
Chapter 5.pptxChapter 5.pptx
Chapter 5.pptx
Tekle12
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programming
hodcsencet
 
AAC ch 3 Advance strategies (Dynamic Programming).pptx
AAC ch 3 Advance strategies (Dynamic Programming).pptxAAC ch 3 Advance strategies (Dynamic Programming).pptx
AAC ch 3 Advance strategies (Dynamic Programming).pptx
HarshitSingh334328
 
Introduction to dynamic programming
Introduction to dynamic programmingIntroduction to dynamic programming
Introduction to dynamic programming
Amisha Narsingani
 
Approximation Algorithms TSP
Approximation Algorithms   TSPApproximation Algorithms   TSP
Computer algorithm(Dynamic Programming).pdf
Computer algorithm(Dynamic Programming).pdfComputer algorithm(Dynamic Programming).pdf
Computer algorithm(Dynamic Programming).pdf
jannatulferdousmaish
 
Least Square Optimization and Sparse-Linear Solver
Least Square Optimization and Sparse-Linear SolverLeast Square Optimization and Sparse-Linear Solver
Least Square Optimization and Sparse-Linear Solver
Ji-yong Kwon
 
Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesDesign and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture Notes
Sreedhar Chowdam
 
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWERUndecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
muthukrishnavinayaga
 
Algorithm in computer science
Algorithm in computer scienceAlgorithm in computer science
Algorithm in computer science
Riazul Islam
 
4optmizationtechniques-150308051251-conversion-gate01.pdf
4optmizationtechniques-150308051251-conversion-gate01.pdf4optmizationtechniques-150308051251-conversion-gate01.pdf
4optmizationtechniques-150308051251-conversion-gate01.pdf
BechanYadav4
 
optmizationtechniques.pdf
optmizationtechniques.pdfoptmizationtechniques.pdf
optmizationtechniques.pdf
SantiagoGarridoBulln
 
Optmization techniques
Optmization techniquesOptmization techniques
Optmization techniques
Deepshika Reddy
 
Firefly exact MCMC for Big Data
Firefly exact MCMC for Big DataFirefly exact MCMC for Big Data
Firefly exact MCMC for Big Data
Gianvito Siciliano
 
Unit3_1.pdf
Unit3_1.pdfUnit3_1.pdf
Unit3_1.pdf
Pratimakumari213460
 
Undecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation AlgorithmsUndecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation Algorithms
Muthu Vinayagam
 
The International Journal of Engineering and Science (The IJES)
The International Journal of Engineering and Science (The IJES)The International Journal of Engineering and Science (The IJES)
The International Journal of Engineering and Science (The IJES)
theijes
 
Module 2 Design Analysis and Algorithms
Module 2 Design Analysis and AlgorithmsModule 2 Design Analysis and Algorithms
Module 2 Design Analysis and Algorithms
Cool Guy
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
Yıldırım Tam
 
Chap12 slides
Chap12 slidesChap12 slides
Chap12 slides
BaliThorat1
 

Similar to Algorithms Lab PPT (20)

Chapter 5.pptx
Chapter 5.pptxChapter 5.pptx
Chapter 5.pptx
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programming
 
AAC ch 3 Advance strategies (Dynamic Programming).pptx
AAC ch 3 Advance strategies (Dynamic Programming).pptxAAC ch 3 Advance strategies (Dynamic Programming).pptx
AAC ch 3 Advance strategies (Dynamic Programming).pptx
 
Introduction to dynamic programming
Introduction to dynamic programmingIntroduction to dynamic programming
Introduction to dynamic programming
 
Approximation Algorithms TSP
Approximation Algorithms   TSPApproximation Algorithms   TSP
Approximation Algorithms TSP
 
Computer algorithm(Dynamic Programming).pdf
Computer algorithm(Dynamic Programming).pdfComputer algorithm(Dynamic Programming).pdf
Computer algorithm(Dynamic Programming).pdf
 
Least Square Optimization and Sparse-Linear Solver
Least Square Optimization and Sparse-Linear SolverLeast Square Optimization and Sparse-Linear Solver
Least Square Optimization and Sparse-Linear Solver
 
Design and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture NotesDesign and Analysis of Algorithms Lecture Notes
Design and Analysis of Algorithms Lecture Notes
 
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWERUndecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
Undecidable Problems - COPING WITH THE LIMITATIONS OF ALGORITHM POWER
 
Algorithm in computer science
Algorithm in computer scienceAlgorithm in computer science
Algorithm in computer science
 
4optmizationtechniques-150308051251-conversion-gate01.pdf
4optmizationtechniques-150308051251-conversion-gate01.pdf4optmizationtechniques-150308051251-conversion-gate01.pdf
4optmizationtechniques-150308051251-conversion-gate01.pdf
 
optmizationtechniques.pdf
optmizationtechniques.pdfoptmizationtechniques.pdf
optmizationtechniques.pdf
 
Optmization techniques
Optmization techniquesOptmization techniques
Optmization techniques
 
Firefly exact MCMC for Big Data
Firefly exact MCMC for Big DataFirefly exact MCMC for Big Data
Firefly exact MCMC for Big Data
 
Unit3_1.pdf
Unit3_1.pdfUnit3_1.pdf
Unit3_1.pdf
 
Undecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation AlgorithmsUndecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation Algorithms
 
The International Journal of Engineering and Science (The IJES)
The International Journal of Engineering and Science (The IJES)The International Journal of Engineering and Science (The IJES)
The International Journal of Engineering and Science (The IJES)
 
Module 2 Design Analysis and Algorithms
Module 2 Design Analysis and AlgorithmsModule 2 Design Analysis and Algorithms
Module 2 Design Analysis and Algorithms
 
Dynamic programming
Dynamic programmingDynamic programming
Dynamic programming
 
Chap12 slides
Chap12 slidesChap12 slides
Chap12 slides
 

Recently uploaded

Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
Krassimira Luka
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
danielkiash986
 
Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
JomonJoseph58
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
National Information Standards Organization (NISO)
 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
melliereed
 
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDFLifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Vivekanand Anglo Vedic Academy
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
deepaannamalai16
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
Jyoti Chand
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Denish Jangid
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
imrankhan141184
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
BoudhayanBhattachari
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
National Information Standards Organization (NISO)
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
zuzanka
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 

Recently uploaded (20)

Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
 
Pharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brubPharmaceutics Pharmaceuticals best of brub
Pharmaceutics Pharmaceuticals best of brub
 
Stack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 MicroprocessorStack Memory Organization of 8086 Microprocessor
Stack Memory Organization of 8086 Microprocessor
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
Jemison, MacLaughlin, and Majumder "Broadening Pathways for Editors and Authors"
 
Nutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour TrainingNutrition Inc FY 2024, 4 - Hour Training
Nutrition Inc FY 2024, 4 - Hour Training
 
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDFLifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
Lifelines of National Economy chapter for Class 10 STUDY MATERIAL PDF
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
 
Wound healing PPT
Wound healing PPTWound healing PPT
Wound healing PPT
 
Chapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptxChapter wise All Notes of First year Basic Civil Engineering.pptx
Chapter wise All Notes of First year Basic Civil Engineering.pptx
 
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
Traditional Musical Instruments of Arunachal Pradesh and Uttar Pradesh - RAYH...
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
B. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdfB. Ed Syllabus for babasaheb ambedkar education university.pdf
B. Ed Syllabus for babasaheb ambedkar education university.pdf
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"Benner "Expanding Pathways to Publishing Careers"
Benner "Expanding Pathways to Publishing Careers"
 
SWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptxSWOT analysis in the project Keeping the Memory @live.pptx
SWOT analysis in the project Keeping the Memory @live.pptx
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 

Algorithms Lab PPT

  • 1. ALGORITHMS II LAB PRESENTATION Presented By:- Rishabh Kumar Sharma, Gx-05 Aman Prasad, Gx-07 Abhishek Chandra, Gx-25 Debtanu Pal, Gx-24 IIEST SHIBPUR
  • 2. CONTENTS • Assignment on Dynamic Programming – Matrix Chain Multiplication • Naive Recursive Approach • Dynamic Programming Approach • Memoized Matrix Chain • Comparison between the 2 approaches • Extension of the Dynamic Programming Approach for Matrix Multiplication to Polygon Triangulation
  • 3. CONTENTS • Assignment on Greedy Algorithms – Huffman Compression Algorithm ● Study variation of average codeword length with change in the probability of occurrence of a symbol
  • 4. DYNAMIC PROGRAMMING • A Dynamic Programming Approach to a problem is taken when a problem has the following 2 properties:- – Optimal Substructure :- Optimal Solution to a problem includes within it the optimal solution to a subproblem. – Overlapping Subproblems
  • 5. RECURSIVE MATRIX CHAIN RMC(p,i,j) if i==j then return zero m[i,j]=INF for k=i to j-1 q=RMC(p,i,k)+RMC(p,k+1,j)+p(i-1)*p(k)*p(j) if q<m[i,j] m[i,j]=q Return m[i,j] Time Complexity of running this one: T(n) ≥ 1+∑(T(k)+T(n-k)+1) ≥ 2 ∑ T(i) +n ≥ 2^n - 1
  • 6. OBSERVATIONS:-RECURSIVE MATRIX CHAIN INPUT SIZE COMPARIS ONS PARENTHE SIZATIONS 2 1 1 4 13 5 6 121 42 8 1093 429 10 9841 4862 12 88573 58786 14 797161 742900 The No. Of comparisons of a size ‘n’ Input is comparable to the CATALAN Number: c(n) == (4^n)/(n^(3/2))
  • 7. REASON We have to check each and every possible parenthesization and hence solve a large no. Of problems repeatedly.
  • 8. MATRIX CHAIN MUL. USING DP MATRIX-CHAIN-ORDER (p) n=length[p]-1 for i=1 to n m[i,i]=0 for l=2 to n for i=1 to n-l+1 j=i+l-1 m[i,j]=INF for k=i to j-1 q=m[i,k]+m[k+1,j]+pi-1pkpj if q< m[i,j] m[i,j]=q ; s[i,j]=k Return m and s
  • 9. HISTOGRAM COMPARISON MATRIX CHAIN MULTIPLICATION USING BRUTE FORCE APPROACH MATRIX CHAIN MULTIPLICATION USING DP
  • 10. Comparison Between Recursive and Dynamic Programming Approach
  • 11. MATRIX CHAIN MULTIPLICATION USING MEMOIZATION Mem-Matrix-Chain(array p, int i, int j) { if (m[i, j] != UNDEFINED) then       return m[i, j];     // already defined     else if ( i = = j) then          m[i, i] = 0;     // basic case     else {        m[i, j] = infinity;    // initialize        for k = i to j − 1 do {// try all splits           cost = Mem-Matrix-Chain(p,i,k) + Mem-Matrix-Chain(p,k+1,j)+ p[i−1]p[k]p[j];     if (cost < m[i, j]) then   // update if better               m[i, j] = cost;         }        }        return m[i, j];           // return final cost }
  • 12. POLYGON TRIANGULATION COMPARISON WITH MATRIX CHAIN MULTIPLICATION MATRIX CHAIN MULTIPLICATION • Problem involves finding the optimal parenthesization so that no. Of multiplications is minimum. • Optimal Substructure – Subproblems consist of finding minimum no. Of multiplication of the smaller subchains • Bottom up approach consists of a table in which we keep record of the particular parenthesization for which the multiplication is minimum. POLYGON TRIANGULATION • Problem involves finding the optimal triangulation so that the perimeter of the resulting triangulation is minimum. • Optimal Substructure- Subproblems consist of finding minimum cost subpolygons on the left and right side of the first triangulation. • Bottom up approach consists of a table which keeps records of the smaller polygons(and the minimum perimeter to triangulate these)
  • 13. ALGORITHM for (int gap = 0; gap < n; gap++) for (int i = 0, j = gap; j < n; i++, j++) if (j < i+2){ table[i][j] = 0 ; //INITIALIZATION OF THE TABLE TO STORE MINIMAL TRIANGULATION COST tri[i][j]=0; } else{ table[i][j] = MAX; for (int k = i+1; k < j; k++){ double val = table[i][k] + table[k][j] + cost(points,i,j,k); //CALCULATING THE COST OF THE GIVEN TRIANGULATION if (table[i][j] > val) { // COMPARING WITH THE VALUES IN TABLE TO FIND MINIMAL TRIANGULATION table[i][j] = val; tri[i][j]=k; } c++; } return table[0][n-1];
  • 15. A SMALL EXAMPLE OPTIMAL TRIANGULATION: COST – 15.30 ANOTHER TRIANGULATION: COST – 15.77
  • 16. KRUSKAL'S ALGORITHM • 1. Sort all the edges in non-decreasing order of their weight. • 2. Pick the smallest edge. Check if it forms a cycle with the spanning tree formed so far. If cycle is not formed, include this edge. Else, discard it. // GREEDY ELEMENT • 3. To check the existence of cycle, check whether for two vertices x and y. Find_set(x)==Find_set(y), or not. If equal they already belong to the same disjoint set(tree), hence will form a cycle if they are joined. So edge(x,y) will not belong to the MST. // DISJOINT SETS • 4. Repeat step 2 until there are (V-1) edges in the spanning tree.
  • 17. TIME COMPLEXITY • Time Complexity: O(ElogE) or O(ElogV). • Sorting of edges takes O(ELogE) time. • After sorting, we iterate through all edges and apply find-union algorithm. • The find and union operations can take atmost O(LogV) time. • So overall complexity is O(ELogE + ELogV) time. • The value of E can be atmost O(V2 ), so O(LogV) are O(LogE) same. • Therefore, overall time complexity is O(ElogE) or O(ElogV)
  • 18. OBSERVATIONS • Increase in no. Of comparisons keeping the no. Of vertices constant. EDGES VERTICES No. OF COMP E*log(V) 2000 500 39863 17931 3000 500 61549 26897 4000 500 83726 35863 5000 500 106267 44829 6000 500 129099 53794 9000 500 198913 `81692
  • 19. Graphical Representation X-axis: Input number Y-axis: No. Of Comparisons
  • 20. OBSERVATIONS • Increase in no. Of comparisons keeping the no. Of vertices constant. EDGES VERTICES COMP 5000 500 106267 5000 600 107582 5000 700 108694 5000 800 109657 5000 900 111267
  • 22. COMPARISON EDGES INC. VERTICES CONST. VERTICES INC. EDGES CONST.
  • 23. COMPARISON EDGES INC. VERTICES CONST. EDGES VERTICES COMP. 5000 500 106267 5100 500 108539 5200 500 110812 5300 500 114089 VERTICES CONST. EDGES INC. EDGES VERTICES COMP. 5000 500 106267 5000 600 107583 5000 700 108695 5000 800 109658
  • 24. VALUE OF c and n0.... QUICKSORT ASSIGNMENT • We have the no. Of comparisons(yi) and the corresponding input size(xi). • Fit these points to the curve f(x)=axlogx +bx +c. • Use the method of least squares. • R^2 = (yi-f(xi))^2. • Take Partial derivative of R^2 w.r.t a,b and c... And equate to 0. • We get 3 variables and 3 equations. • Finally, a=1.792, b= -7.48, c=79.8962.