SlideShare a Scribd company logo
1 of 5
Appendix A: Heap Bottomup Construction
Course: Algorithm Analysis and Design

1
Heap bottom up construction
This method views every position in the array as the root of a
small heap and uses downheap procedure for such small
heaps.

Figure 1: The heap created from the array of characters:
A, S, O, R, T, I, N, G, E, X, A, M, P, L, E.
2
Heap bottom-up construction procedure
procedure build_heap;
begin
for k:= M div 2 downto 1 do
downheap(k);
end
M: the number of elements in the heap.
The keys in a[ (M div 2)+1 .. M] each form heaps of one
element, so they satisfy the heap condition and don’t
need to be checked.

3
Property: Bottom-up heap construction is lineartime.
For example: To build a heap of 127 elements, the
method calls downheap on
- 64 heaps of size 1
- 32 heaps of size 3
- 16 heaps of size 7
- 8 heaps of size 15
- 4 heaps of size 31
- 2 heaps of size 63
- 1 heaps of size 127
So the method needs 64.0 + 32.1 + 16.2 + 8.3 + 4.4 +
2.5 + 1.6 = 120 “promotions”.
0.26 + 1.25 + 2.24 + 3.23 + 4.22 + 5.21 + 6.20


4
0.26 + 1.25 + 2.24 + 3.23 + 4.22 + 5.21 + 6.20
(M= 127 = 27 -1) m = 7
For M = 2m, an upper bound on the number of comparisions is
(1-1)2m-1 + (2-1)2m-2 + (3 -1)2m-3+… + (k-1)2m-k + … (m-1-1)2m-(m-1)
+ (m -1)2m-m.
= 1.2m-2 + 2.2m-3 +3.2m-4+ 4.2m-5 +…+ (k-1)2m-k + …
(m-2)21 + (m -1)20
= (2m-2 + 2m-3 + …+ 20) + (2m-3 + …+ 20) + (2m-4 + …+ 20) …+(22 + 21
+ 20) + (21 + 20) + 1
= (2m-1 -1)+ (2m-2 -1) + … (23-1) + (22-1) +(21-1)
= (2m-1 + 2m-2 + … 22 + 21)– m +1
= (2m-1 + 2m-2 + … 22 + 21+1) – m
= (2m -1) – m < M
So the complexity of heap bottom-up building is O(M).

5

More Related Content

What's hot

PC Test 2 study guide 2011
PC Test 2 study guide 2011PC Test 2 study guide 2011
PC Test 2 study guide 2011vhiggins1
 
C2 mate factorización por binomio - 5º
C2 mate   factorización por binomio - 5ºC2 mate   factorización por binomio - 5º
C2 mate factorización por binomio - 5ºbrisagaela29
 
Mate factorización por binomio - 2º
Mate   factorización por binomio - 2ºMate   factorización por binomio - 2º
Mate factorización por binomio - 2ºbrisagaela29
 
Fibonacci fast doubling : ARM assembly 實作
Fibonacci fast doubling : ARM assembly 實作Fibonacci fast doubling : ARM assembly 實作
Fibonacci fast doubling : ARM assembly 實作哲綱 吳
 
7th math c2 -l29
7th math c2 -l297th math c2 -l29
7th math c2 -l29jdurst65
 
Trend Based + Reg And Holtns
Trend Based + Reg And HoltnsTrend Based + Reg And Holtns
Trend Based + Reg And Holtns3abooodi
 
Productos notables
Productos notablesProductos notables
Productos notablesPROFTEBA
 
Solucionario evaluación parcial cálculo integral
Solucionario evaluación parcial   cálculo integral Solucionario evaluación parcial   cálculo integral
Solucionario evaluación parcial cálculo integral Abisai Huarcaya
 
Spm additional-mathematical-formulae-pdf
Spm additional-mathematical-formulae-pdfSpm additional-mathematical-formulae-pdf
Spm additional-mathematical-formulae-pdfMahadzir Ismail
 
Important maths formulas
Important maths formulasImportant maths formulas
Important maths formulaskrsraju
 
JEE Main & Advanced Complex numbers questions
JEE Main & Advanced Complex numbers questionsJEE Main & Advanced Complex numbers questions
JEE Main & Advanced Complex numbers questionsBishwajeet Mahato
 
1 fichas refuerzo operaciones combinadas numeros
1 fichas refuerzo operaciones combinadas numeros1 fichas refuerzo operaciones combinadas numeros
1 fichas refuerzo operaciones combinadas numerosBea Marfer
 
Moving Straight Ahead 2.3
Moving Straight Ahead 2.3Moving Straight Ahead 2.3
Moving Straight Ahead 2.3Kathy Favazza
 
Matrix Manipulation in Matlab
Matrix Manipulation in MatlabMatrix Manipulation in Matlab
Matrix Manipulation in MatlabMohamed Loey
 

What's hot (16)

PC Test 2 study guide 2011
PC Test 2 study guide 2011PC Test 2 study guide 2011
PC Test 2 study guide 2011
 
C2 mate factorización por binomio - 5º
C2 mate   factorización por binomio - 5ºC2 mate   factorización por binomio - 5º
C2 mate factorización por binomio - 5º
 
Mate factorización por binomio - 2º
Mate   factorización por binomio - 2ºMate   factorización por binomio - 2º
Mate factorización por binomio - 2º
 
Fibonacci fast doubling : ARM assembly 實作
Fibonacci fast doubling : ARM assembly 實作Fibonacci fast doubling : ARM assembly 實作
Fibonacci fast doubling : ARM assembly 實作
 
7th math c2 -l29
7th math c2 -l297th math c2 -l29
7th math c2 -l29
 
R Statistics
R StatisticsR Statistics
R Statistics
 
Trend Based + Reg And Holtns
Trend Based + Reg And HoltnsTrend Based + Reg And Holtns
Trend Based + Reg And Holtns
 
Productos notables
Productos notablesProductos notables
Productos notables
 
Conformal mapping
Conformal mappingConformal mapping
Conformal mapping
 
Solucionario evaluación parcial cálculo integral
Solucionario evaluación parcial   cálculo integral Solucionario evaluación parcial   cálculo integral
Solucionario evaluación parcial cálculo integral
 
Spm additional-mathematical-formulae-pdf
Spm additional-mathematical-formulae-pdfSpm additional-mathematical-formulae-pdf
Spm additional-mathematical-formulae-pdf
 
Important maths formulas
Important maths formulasImportant maths formulas
Important maths formulas
 
JEE Main & Advanced Complex numbers questions
JEE Main & Advanced Complex numbers questionsJEE Main & Advanced Complex numbers questions
JEE Main & Advanced Complex numbers questions
 
1 fichas refuerzo operaciones combinadas numeros
1 fichas refuerzo operaciones combinadas numeros1 fichas refuerzo operaciones combinadas numeros
1 fichas refuerzo operaciones combinadas numeros
 
Moving Straight Ahead 2.3
Moving Straight Ahead 2.3Moving Straight Ahead 2.3
Moving Straight Ahead 2.3
 
Matrix Manipulation in Matlab
Matrix Manipulation in MatlabMatrix Manipulation in Matlab
Matrix Manipulation in Matlab
 

Similar to Appendix a 2

Dynamic Programming - Matrix Chain Multiplication
Dynamic Programming - Matrix Chain MultiplicationDynamic Programming - Matrix Chain Multiplication
Dynamic Programming - Matrix Chain MultiplicationPecha Inc.
 
A study on number theory and its applications
A study on number theory and its applicationsA study on number theory and its applications
A study on number theory and its applicationsItishree Dash
 
Matrix chain multiplication in design analysis of algorithm
Matrix chain multiplication in design analysis of algorithmMatrix chain multiplication in design analysis of algorithm
Matrix chain multiplication in design analysis of algorithmRajKumar323561
 
Convolutional Neural Network (CNN) presentation from theory to code in Theano
Convolutional Neural Network (CNN) presentation from theory to code in TheanoConvolutional Neural Network (CNN) presentation from theory to code in Theano
Convolutional Neural Network (CNN) presentation from theory to code in TheanoSeongwon Hwang
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplicationKiran K
 
Longest Common Subsequence & Matrix Chain Multiplication
Longest Common Subsequence & Matrix Chain MultiplicationLongest Common Subsequence & Matrix Chain Multiplication
Longest Common Subsequence & Matrix Chain MultiplicationJaneAlamAdnan
 
math1مرحلة اولى -compressed.pdf
math1مرحلة اولى -compressed.pdfmath1مرحلة اولى -compressed.pdf
math1مرحلة اولى -compressed.pdfHebaEng
 
Simultaneous Equations Practical Construction
Simultaneous Equations Practical ConstructionSimultaneous Equations Practical Construction
Simultaneous Equations Practical ConstructionDaniel Ross
 
Expanding Binomial Brackets
Expanding Binomial BracketsExpanding Binomial Brackets
Expanding Binomial BracketsPassy World
 
parameterized complexity for graph Motif
parameterized complexity for graph Motifparameterized complexity for graph Motif
parameterized complexity for graph MotifAMR koura
 
Sim math 9 factoring
Sim math 9 factoringSim math 9 factoring
Sim math 9 factoringRoqueGerale
 
Coin Change Problem
Coin Change ProblemCoin Change Problem
Coin Change ProblemDEVTYPE
 
Digital Communication Assignment Help
Digital Communication Assignment HelpDigital Communication Assignment Help
Digital Communication Assignment HelpEdu Assignment Help
 
matrices and determinantes
matrices and determinantes matrices and determinantes
matrices and determinantes gandhinagar
 
Strategic Intervention Materials
Strategic Intervention MaterialsStrategic Intervention Materials
Strategic Intervention MaterialsBrian Mary
 

Similar to Appendix a 2 (20)

Dynamic Programming - Matrix Chain Multiplication
Dynamic Programming - Matrix Chain MultiplicationDynamic Programming - Matrix Chain Multiplication
Dynamic Programming - Matrix Chain Multiplication
 
A study on number theory and its applications
A study on number theory and its applicationsA study on number theory and its applications
A study on number theory and its applications
 
Matrix chain multiplication in design analysis of algorithm
Matrix chain multiplication in design analysis of algorithmMatrix chain multiplication in design analysis of algorithm
Matrix chain multiplication in design analysis of algorithm
 
Convolutional Neural Network (CNN) presentation from theory to code in Theano
Convolutional Neural Network (CNN) presentation from theory to code in TheanoConvolutional Neural Network (CNN) presentation from theory to code in Theano
Convolutional Neural Network (CNN) presentation from theory to code in Theano
 
Matrix chain multiplication
Matrix chain multiplicationMatrix chain multiplication
Matrix chain multiplication
 
Longest Common Subsequence & Matrix Chain Multiplication
Longest Common Subsequence & Matrix Chain MultiplicationLongest Common Subsequence & Matrix Chain Multiplication
Longest Common Subsequence & Matrix Chain Multiplication
 
Computer graphics 2
Computer graphics 2Computer graphics 2
Computer graphics 2
 
math1مرحلة اولى -compressed.pdf
math1مرحلة اولى -compressed.pdfmath1مرحلة اولى -compressed.pdf
math1مرحلة اولى -compressed.pdf
 
Simultaneous Equations Practical Construction
Simultaneous Equations Practical ConstructionSimultaneous Equations Practical Construction
Simultaneous Equations Practical Construction
 
Set 1 mawar
Set 1 mawarSet 1 mawar
Set 1 mawar
 
Expanding Binomial Brackets
Expanding Binomial BracketsExpanding Binomial Brackets
Expanding Binomial Brackets
 
parameterized complexity for graph Motif
parameterized complexity for graph Motifparameterized complexity for graph Motif
parameterized complexity for graph Motif
 
Sim math 9 factoring
Sim math 9 factoringSim math 9 factoring
Sim math 9 factoring
 
Class 12 practice paper
Class 12 practice paperClass 12 practice paper
Class 12 practice paper
 
Coin Change Problem
Coin Change ProblemCoin Change Problem
Coin Change Problem
 
TABREZ KHAN.ppt
TABREZ KHAN.pptTABREZ KHAN.ppt
TABREZ KHAN.ppt
 
Digital Communication Assignment Help
Digital Communication Assignment HelpDigital Communication Assignment Help
Digital Communication Assignment Help
 
matrices and determinantes
matrices and determinantes matrices and determinantes
matrices and determinantes
 
Strategic Intervention Materials
Strategic Intervention MaterialsStrategic Intervention Materials
Strategic Intervention Materials
 
Daa chapter 3
Daa chapter 3Daa chapter 3
Daa chapter 3
 

More from Loc Tran

đạI học quốc gia thành phố hồ chí minh
đạI học quốc gia thành phố hồ chí minhđạI học quốc gia thành phố hồ chí minh
đạI học quốc gia thành phố hồ chí minhLoc Tran
 
Chap4 new (tran dai's conflicted copy 2013 04-02)
Chap4 new (tran dai's conflicted copy 2013 04-02)Chap4 new (tran dai's conflicted copy 2013 04-02)
Chap4 new (tran dai's conflicted copy 2013 04-02)Loc Tran
 
Chap2 new (tran dai's conflicted copy 2013 04-02)
Chap2 new (tran dai's conflicted copy 2013 04-02)Chap2 new (tran dai's conflicted copy 2013 04-02)
Chap2 new (tran dai's conflicted copy 2013 04-02)Loc Tran
 
Chap1 new (tran dai's conflicted copy 2013 04-02)
Chap1 new (tran dai's conflicted copy 2013 04-02)Chap1 new (tran dai's conflicted copy 2013 04-02)
Chap1 new (tran dai's conflicted copy 2013 04-02)Loc Tran
 
Appendix b 2
Appendix b 2Appendix b 2
Appendix b 2Loc Tran
 
Chap8 part ii
Chap8 part iiChap8 part ii
Chap8 part iiLoc Tran
 

More from Loc Tran (13)

đạI học quốc gia thành phố hồ chí minh
đạI học quốc gia thành phố hồ chí minhđạI học quốc gia thành phố hồ chí minh
đạI học quốc gia thành phố hồ chí minh
 
Chap8 new
Chap8 newChap8 new
Chap8 new
 
Chap7 new
Chap7 newChap7 new
Chap7 new
 
Chap6 new
Chap6 newChap6 new
Chap6 new
 
Chap5 new
Chap5 newChap5 new
Chap5 new
 
Chap4 new
Chap4 newChap4 new
Chap4 new
 
Chap4 new (tran dai's conflicted copy 2013 04-02)
Chap4 new (tran dai's conflicted copy 2013 04-02)Chap4 new (tran dai's conflicted copy 2013 04-02)
Chap4 new (tran dai's conflicted copy 2013 04-02)
 
Chap3 new
Chap3 newChap3 new
Chap3 new
 
Chap2 new
Chap2 newChap2 new
Chap2 new
 
Chap2 new (tran dai's conflicted copy 2013 04-02)
Chap2 new (tran dai's conflicted copy 2013 04-02)Chap2 new (tran dai's conflicted copy 2013 04-02)
Chap2 new (tran dai's conflicted copy 2013 04-02)
 
Chap1 new (tran dai's conflicted copy 2013 04-02)
Chap1 new (tran dai's conflicted copy 2013 04-02)Chap1 new (tran dai's conflicted copy 2013 04-02)
Chap1 new (tran dai's conflicted copy 2013 04-02)
 
Appendix b 2
Appendix b 2Appendix b 2
Appendix b 2
 
Chap8 part ii
Chap8 part iiChap8 part ii
Chap8 part ii
 

Recently uploaded

History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxsocialsciencegdgrohi
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentInMediaRes1
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
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
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
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
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
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
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 

Recently uploaded (20)

History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptxHistory Class XII Ch. 3 Kinship, Caste and Class (1).pptx
History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
 
Meghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media ComponentMeghan Sutherland In Media Res Media Component
Meghan Sutherland In Media Res Media Component
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
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
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
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
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
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
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 

Appendix a 2

  • 1. Appendix A: Heap Bottomup Construction Course: Algorithm Analysis and Design 1
  • 2. Heap bottom up construction This method views every position in the array as the root of a small heap and uses downheap procedure for such small heaps. Figure 1: The heap created from the array of characters: A, S, O, R, T, I, N, G, E, X, A, M, P, L, E. 2
  • 3. Heap bottom-up construction procedure procedure build_heap; begin for k:= M div 2 downto 1 do downheap(k); end M: the number of elements in the heap. The keys in a[ (M div 2)+1 .. M] each form heaps of one element, so they satisfy the heap condition and don’t need to be checked. 3
  • 4. Property: Bottom-up heap construction is lineartime. For example: To build a heap of 127 elements, the method calls downheap on - 64 heaps of size 1 - 32 heaps of size 3 - 16 heaps of size 7 - 8 heaps of size 15 - 4 heaps of size 31 - 2 heaps of size 63 - 1 heaps of size 127 So the method needs 64.0 + 32.1 + 16.2 + 8.3 + 4.4 + 2.5 + 1.6 = 120 “promotions”. 0.26 + 1.25 + 2.24 + 3.23 + 4.22 + 5.21 + 6.20  4
  • 5. 0.26 + 1.25 + 2.24 + 3.23 + 4.22 + 5.21 + 6.20 (M= 127 = 27 -1) m = 7 For M = 2m, an upper bound on the number of comparisions is (1-1)2m-1 + (2-1)2m-2 + (3 -1)2m-3+… + (k-1)2m-k + … (m-1-1)2m-(m-1) + (m -1)2m-m. = 1.2m-2 + 2.2m-3 +3.2m-4+ 4.2m-5 +…+ (k-1)2m-k + … (m-2)21 + (m -1)20 = (2m-2 + 2m-3 + …+ 20) + (2m-3 + …+ 20) + (2m-4 + …+ 20) …+(22 + 21 + 20) + (21 + 20) + 1 = (2m-1 -1)+ (2m-2 -1) + … (23-1) + (22-1) +(21-1) = (2m-1 + 2m-2 + … 22 + 21)– m +1 = (2m-1 + 2m-2 + … 22 + 21+1) – m = (2m -1) – m < M So the complexity of heap bottom-up building is O(M). 5