SlideShare a Scribd company logo
1 of 24
Download to read offline
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 3Kumar
 
digital control Chapter 2 slide
digital control Chapter 2 slidedigital control Chapter 2 slide
digital control Chapter 2 slideasyrafjpk
 
Seismic data processing lecture 4
Seismic data processing lecture 4Seismic data processing lecture 4
Seismic data processing lecture 4Amin 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 5vijayanand Kandaswamy
 
Applications of Z transform
Applications of Z transformApplications of Z transform
Applications of Z transformAakankshaR
 
asymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysisasymptotic analysis and insertion sort analysis
asymptotic analysis and insertion sort analysisAnindita Kundu
 
Lti and z transform
Lti and z transformLti and z transform
Lti and z transformpranvendra29
 
Asymptotic Notations
Asymptotic NotationsAsymptotic Notations
Asymptotic NotationsRishabh Soni
 
Spline Interpolation
Spline InterpolationSpline Interpolation
Spline InterpolationaiQUANT
 
Lec 5 asymptotic notations and recurrences
Lec 5 asymptotic notations and recurrencesLec 5 asymptotic notations and recurrences
Lec 5 asymptotic notations and recurrencesAnkita Karia
 
Application of Convolution Theorem
Application of Convolution TheoremApplication of Convolution Theorem
Application of Convolution Theoremijtsrd
 
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 TRANSFORMTowfeeq Umar
 
Discreate time system and z transform
Discreate time system and z transformDiscreate time system and z transform
Discreate time system and z transformVIKAS KUMAR MANJHI
 
Dcs lec02 - z-transform
Dcs   lec02 - z-transformDcs   lec02 - z-transform
Dcs lec02 - z-transformAmr E. Mohamed
 
Pseudo Random Number Generators
Pseudo Random Number GeneratorsPseudo Random Number Generators
Pseudo Random Number GeneratorsDarshini 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 lectureKhalaf 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 SystemsAmr 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.pptxTekle12
 
unit-4-dynamic programming
unit-4-dynamic programmingunit-4-dynamic programming
unit-4-dynamic programminghodcsencet
 
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).pptxHarshitSingh334328
 
Introduction to dynamic programming
Introduction to dynamic programmingIntroduction to dynamic programming
Introduction to dynamic programmingAmisha Narsingani
 
Computer algorithm(Dynamic Programming).pdf
Computer algorithm(Dynamic Programming).pdfComputer algorithm(Dynamic Programming).pdf
Computer algorithm(Dynamic Programming).pdfjannatulferdousmaish
 
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 SolverJi-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 NotesSreedhar 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 POWERmuthukrishnavinayaga
 
Algorithm in computer science
Algorithm in computer scienceAlgorithm in computer science
Algorithm in computer scienceRiazul Islam
 
4optmizationtechniques-150308051251-conversion-gate01.pdf
4optmizationtechniques-150308051251-conversion-gate01.pdf4optmizationtechniques-150308051251-conversion-gate01.pdf
4optmizationtechniques-150308051251-conversion-gate01.pdfBechanYadav4
 
Firefly exact MCMC for Big Data
Firefly exact MCMC for Big DataFirefly exact MCMC for Big Data
Firefly exact MCMC for Big DataGianvito Siciliano
 
Undecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation AlgorithmsUndecidable Problems and Approximation Algorithms
Undecidable Problems and Approximation AlgorithmsMuthu 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 AlgorithmsCool Guy
 

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
 
Optmization techniques
Optmization techniquesOptmization techniques
Optmization techniques
 
optmizationtechniques.pdf
optmizationtechniques.pdfoptmizationtechniques.pdf
optmizationtechniques.pdf
 
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

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...RKavithamani
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 

Recently uploaded (20)

18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
Privatization and Disinvestment - Meaning, Objectives, Advantages and Disadva...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 

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.