SlideShare a Scribd company logo
1 of 8
For any Exam related queries, Call us at : - +1 678 648 4277
You can mail us at : - support@programmingexamhelp.com or
reach us at : - https://www.programmingexamhelp.com
Design and Analysis of Algorithms
Problem 1.Seeing the Forest for the van Emde Boas Trees
After listening to a lecture on van Emde Boas Trees, Ben Bitdiddle decides
that he can simplify the implementation by not storing the max and min
fields in each of the vEB substructures separately. Instead, he decides to
insert them into the tree, while still keeping track of the global min in a
separate variable. He dubs this revised version of the data structure the “Bib
Tree”.
(a)Write pseudo-code implementations of the BIB-INSERT, BIB-DELETE,
and BIB-MIN functions for the Bib Tree.
Solution:
Here is a graphic of the structure of a Bib Tree as described:
programmingexamhelp.com
BIB-MIN is the simplest operation, if we are trying to get the global min: we simply
return the value that is already stored. (Here, we use V.root to represent the
structure storing metadata, which is not recursive and only exists at the top level.)
BIB-MIN(V ) :
1 return V.root.min
programmingexamhelp.com
In the code for BIB-INSERT, we define the base case to be when the size of the
universe is 2; any small constant would suffice here.
The base case Bib Tree structure (the leaves of the tree) is distinct from that of the
upper level ones; rather than having an array of clusters and a summary Bib Tree,
it stores only a bit array which indicates the presence (or absence) of the elements
governed by it.
BIB-INSERT(V, x)
1 if V.u == 2
2 V.A[x] = 1
3 else
4 BIB-INSERT(V.cluster[high(x)], low(x))
5 BIB-INSERT(V.summary, high(x))
We’ll also define a helper function called BIB-RECURSIVE-MIN, to get the
smallest element not stored in the global min. (This is necessary for BIB-DELETE).
BIB-RECURSIVE-MIN(V ) :
1 if V.u == 2
2 if V.A[0] == 1
3 return 0
4 elseif V.A[1] == 1 programmingexamhelp.com
5 return 1
6 else return NIL
7 else c = BIB-RECURSIVE-MIN(V.summary)
8 if c = = NIL
9 return NIL
10 else i = BIB-RECURSIVE-MIN(V.cluster[c])
11 return c √ u + i
There are a two key cases for BIB-DELETE: if we delete the global min, we have to
find the next min and delete it from the recursive substructures, as the global min is
not stored recursively. Otherwise, it suffices to simply delete the element from the
appropr √ iate cluster, and delete the cluster from the summary (which is itself a Bib
Tree of size u) if necessary.
BIB-DELETE(V, x) :
1 if x == V.root.min
2 newmin = BIB-RECURSIVE-MIN(V )
3 BIB-DELETE(V, newmin)
4 V.root.min = newmin
5 elseif V.u == 2
6 V.A[x] = 0
7 else
programmingexamhelp.com
8 BIB-DELETE(V.cluster[high(x)], low(x))
9 if BIB-RECURSIVE-MIN(V.cluster[high(x)]) = = NIL // Is the cluster now empty?
10 BIB-DELETE(V.summary, high(x))
It is possible to avoid the extra BIB-RECURSIVE-MIN call in line 7 of BIB-DELETE
above by defining an additional variable to count the number of items stored in
each Bib Tree structure.
(b) Write the recurrences for the run-times of the operations in the revised data
structure and solve the recurrences.
Solution:
BIB-MIN is not recursive, and so just takes O(1) time.
BIB-INSERT has 2 recursive calls to BIB-INSERT, so has recurrence T(u) = 2T( √
u)+ O(1). We can solve this recurrence by substitution: Define m = lg u, so that u =
2m and √ u = 2m/2 , and S(m) = T(2m) = T(u).
Then S(m) = 2S(m/2) +O(1), so S(m) = Θ(m) by the Master method and T(u) = Θ(lg
u).
BIB-RECURSIVE-MIN likewise has recurrence T(u) = 2T( √ u)+O(1) and therefore
also takes time Θ(lg u).
Fina √ lly, as written above BIB-DELETE has a worst-case running time of T(u) =
2T( u) + TBIB-RECURS IVE-MIN = 2T( √ u) + Θ(lg u).
programmingexamhelp.com
Using substitution, as above, we get S(m) = 2S(m/2) + Θ(m), which solves to Θ(m lg
m) = Θ(lg u lg lg u) by the Master method.
(c) Ben Bitdiddle decides to use the Bib-Tree data structure in his implementation of
Prim’s algorithm (§23.2). You can assume that the input graphs of interest all have
integer weights in the range from 1 to n and that edge weights are allowed to
repeat. Show how Ben would make use of his Bib-Tree and provide an analysis of
time complexity for this implementation of Prim.
Solution:
We cannot use the Bib Tree directly for Prim’s algorithm, because the Bib Tree as
described in the previous parts does not have the capability of storing multiple
elements with the same key. In order to make it possible to use the Bib Tree for
Prim’s algorithm, we make the following modifications:
1. At the leaves of the Bib Tree (the base case, where the universe size is u = 2),
make V.A into an array of pointers rather than a bit array as it was previously.
Each pointer is NIL if no vertex has that key, and is a pointer to the head of a
linked list containing all vertices with that key otherwise.
2. 2. In the base case of BIB-INSERT, if we are inserting a value v with key k:
rather than setting V.A[k] to be 1, we instead add v to the end of the linked list at
V.A[k], or create a new linked list with one element if V.A[k] was previously NIL.
Additionally, when we
programmingexamhelp.com
insert (k, v), we store a pointer to its position in that linked list with the vertex v,
which will become useful later for the modified BIB-DELETE.
3. When BIB-DELETE(k, v) is called, at the base case, we can delete v from the
linked list at k by following the pointer stored with v upon its insertion.
We implement EXTRACT-MIN by getting a vertex whose current key is the global
min; then we must call BIB-DELETE on that key (with the vertex) to remove the
vertex from the linked list, and potentially replace the global min with the next
smallest element. In the worst case, this takes as much time as BIB-DELETE, which
takes Θ(lg n lg lg n) time by the previous part of the pset.
INSERT(k, v) is simply a call to the modified BIB-INSERT procedure. DECREASE-
KEY(k, v) involves a call to the modified BIB-DELETE followed by one to BIB-
INSERT, which takes a total of Θ(lg n lg lg n) time.
Prim’s algorithm takes |V |TEXTRACT-MIN + |E|TDECREASE-KEY, so with our
modified Bib Trees this takes Θ((E + V ) lg n lg lg n) time.
programmingexamhelp.com

More Related Content

Similar to Algorithm Exam Help

Applicationof datastructures
Applicationof datastructuresApplicationof datastructures
Applicationof datastructuresHitesh Wagle
 
Applicationof datastructures
Applicationof datastructuresApplicationof datastructures
Applicationof datastructuresHitesh Wagle
 
Introducing Assignment invalidates the Substitution Model of Evaluation and v...
Introducing Assignment invalidates the Substitution Model of Evaluation and v...Introducing Assignment invalidates the Substitution Model of Evaluation and v...
Introducing Assignment invalidates the Substitution Model of Evaluation and v...Philip Schwarz
 
Applications of datastructures
Applications of datastructuresApplications of datastructures
Applications of datastructuresRatsietsi Mokete
 
Matlab ch1 intro
Matlab ch1 introMatlab ch1 intro
Matlab ch1 introRagu Nathan
 
Producción Escrita Matemática.
Producción Escrita Matemática.Producción Escrita Matemática.
Producción Escrita Matemática.MarcosArrieche
 
Csci101 lect09 vectorized_code
Csci101 lect09 vectorized_codeCsci101 lect09 vectorized_code
Csci101 lect09 vectorized_codeElsayed Hemayed
 
Simplify writing code with deliberate commits
Simplify writing code with deliberate commitsSimplify writing code with deliberate commits
Simplify writing code with deliberate commitsJoel Chippindale
 
Implementation of Low-Complexity Redundant Multiplier Architecture for Finite...
Implementation of Low-Complexity Redundant Multiplier Architecture for Finite...Implementation of Low-Complexity Redundant Multiplier Architecture for Finite...
Implementation of Low-Complexity Redundant Multiplier Architecture for Finite...ijcisjournal
 

Similar to Algorithm Exam Help (20)

Applicationof datastructures
Applicationof datastructuresApplicationof datastructures
Applicationof datastructures
 
Applicationof datastructures
Applicationof datastructuresApplicationof datastructures
Applicationof datastructures
 
Algorithms Design Exam Help
Algorithms Design Exam HelpAlgorithms Design Exam Help
Algorithms Design Exam Help
 
CV2005_3Lec02.ppt
CV2005_3Lec02.pptCV2005_3Lec02.ppt
CV2005_3Lec02.ppt
 
003 bd ds
003 bd ds003 bd ds
003 bd ds
 
Computer Science Assignment Help
Computer Science Assignment HelpComputer Science Assignment Help
Computer Science Assignment Help
 
Introducing Assignment invalidates the Substitution Model of Evaluation and v...
Introducing Assignment invalidates the Substitution Model of Evaluation and v...Introducing Assignment invalidates the Substitution Model of Evaluation and v...
Introducing Assignment invalidates the Substitution Model of Evaluation and v...
 
Applications of datastructures
Applications of datastructuresApplications of datastructures
Applications of datastructures
 
affTA09 - LampiranA
affTA09 - LampiranAaffTA09 - LampiranA
affTA09 - LampiranA
 
Computer Network Assignment Help
Computer Network Assignment HelpComputer Network Assignment Help
Computer Network Assignment Help
 
Matlab ch1 intro
Matlab ch1 introMatlab ch1 intro
Matlab ch1 intro
 
Stacks.ppt
Stacks.pptStacks.ppt
Stacks.ppt
 
Stacks.ppt
Stacks.pptStacks.ppt
Stacks.ppt
 
Producción Escrita Matemática.
Producción Escrita Matemática.Producción Escrita Matemática.
Producción Escrita Matemática.
 
Csci101 lect09 vectorized_code
Csci101 lect09 vectorized_codeCsci101 lect09 vectorized_code
Csci101 lect09 vectorized_code
 
Introduction to OpenCV
Introduction to OpenCVIntroduction to OpenCV
Introduction to OpenCV
 
Simplify writing code with deliberate commits
Simplify writing code with deliberate commitsSimplify writing code with deliberate commits
Simplify writing code with deliberate commits
 
Implementation of Low-Complexity Redundant Multiplier Architecture for Finite...
Implementation of Low-Complexity Redundant Multiplier Architecture for Finite...Implementation of Low-Complexity Redundant Multiplier Architecture for Finite...
Implementation of Low-Complexity Redundant Multiplier Architecture for Finite...
 
Dynamic pgmming
Dynamic pgmmingDynamic pgmming
Dynamic pgmming
 
M2-Recursion.pptx
M2-Recursion.pptxM2-Recursion.pptx
M2-Recursion.pptx
 

More from Programming Exam Help (20)

Best Algorithms Design Exam Help
Best Algorithms Design Exam Help Best Algorithms Design Exam Help
Best Algorithms Design Exam Help
 
Algorithm Exam Help
Algorithm Exam HelpAlgorithm Exam Help
Algorithm Exam Help
 
Design and Analysis of Algorithms Exam Help
Design and Analysis of Algorithms Exam HelpDesign and Analysis of Algorithms Exam Help
Design and Analysis of Algorithms Exam Help
 
Algorithm Exam Help
Algorithm Exam HelpAlgorithm Exam Help
Algorithm Exam Help
 
Algorithms Exam Help
Algorithms Exam HelpAlgorithms Exam Help
Algorithms Exam Help
 
Algorithms Design Exam Help
Algorithms Design Exam HelpAlgorithms Design Exam Help
Algorithms Design Exam Help
 
Algorithms Exam Help
Algorithms Exam HelpAlgorithms Exam Help
Algorithms Exam Help
 
Algorithms Exam Help
Algorithms Exam HelpAlgorithms Exam Help
Algorithms Exam Help
 
Algorithms Exam Help
Algorithms Exam HelpAlgorithms Exam Help
Algorithms Exam Help
 
C Exam Help
C Exam Help C Exam Help
C Exam Help
 
Algorithm Exam Help
Algorithm Exam HelpAlgorithm Exam Help
Algorithm Exam Help
 
C Exam Help
C Exam Help C Exam Help
C Exam Help
 
Computer Science Exam Help
Computer Science Exam HelpComputer Science Exam Help
Computer Science Exam Help
 
Programming Exam Help
Programming Exam Help Programming Exam Help
Programming Exam Help
 
Algorithm Exam Help
Algorithm Exam HelpAlgorithm Exam Help
Algorithm Exam Help
 
Programming Exam Help
Programming Exam Help Programming Exam Help
Programming Exam Help
 
Programming Exam Help
Programming Exam Help Programming Exam Help
Programming Exam Help
 
Algorithm Exam Help
Algorithm Exam Help Algorithm Exam Help
Algorithm Exam Help
 
Programming Exam Help
Programming Exam Help Programming Exam Help
Programming Exam Help
 
Computer Science Exam Help
Computer Science Exam Help Computer Science Exam Help
Computer Science Exam Help
 

Recently uploaded

會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽中 央社
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxMarlene Maheu
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsSandeep D Chaudhary
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppCeline George
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfcupulin
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfJerry Chew
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxLimon Prince
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 

Recently uploaded (20)

會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽會考英聽
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 
PSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptxPSYPACT- Practicing Over State Lines May 2024.pptx
PSYPACT- Practicing Over State Lines May 2024.pptx
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdfContoh Aksi Nyata Refleksi Diri ( NUR ).pdf
Contoh Aksi Nyata Refleksi Diri ( NUR ).pdf
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdfRich Dad Poor Dad ( PDFDrive.com )--.pdf
Rich Dad Poor Dad ( PDFDrive.com )--.pdf
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptxAnalyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
Analyzing and resolving a communication crisis in Dhaka textiles LTD.pptx
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 

Algorithm Exam Help

  • 1. For any Exam related queries, Call us at : - +1 678 648 4277 You can mail us at : - support@programmingexamhelp.com or reach us at : - https://www.programmingexamhelp.com
  • 2. Design and Analysis of Algorithms Problem 1.Seeing the Forest for the van Emde Boas Trees After listening to a lecture on van Emde Boas Trees, Ben Bitdiddle decides that he can simplify the implementation by not storing the max and min fields in each of the vEB substructures separately. Instead, he decides to insert them into the tree, while still keeping track of the global min in a separate variable. He dubs this revised version of the data structure the “Bib Tree”. (a)Write pseudo-code implementations of the BIB-INSERT, BIB-DELETE, and BIB-MIN functions for the Bib Tree. Solution: Here is a graphic of the structure of a Bib Tree as described: programmingexamhelp.com
  • 3. BIB-MIN is the simplest operation, if we are trying to get the global min: we simply return the value that is already stored. (Here, we use V.root to represent the structure storing metadata, which is not recursive and only exists at the top level.) BIB-MIN(V ) : 1 return V.root.min programmingexamhelp.com
  • 4. In the code for BIB-INSERT, we define the base case to be when the size of the universe is 2; any small constant would suffice here. The base case Bib Tree structure (the leaves of the tree) is distinct from that of the upper level ones; rather than having an array of clusters and a summary Bib Tree, it stores only a bit array which indicates the presence (or absence) of the elements governed by it. BIB-INSERT(V, x) 1 if V.u == 2 2 V.A[x] = 1 3 else 4 BIB-INSERT(V.cluster[high(x)], low(x)) 5 BIB-INSERT(V.summary, high(x)) We’ll also define a helper function called BIB-RECURSIVE-MIN, to get the smallest element not stored in the global min. (This is necessary for BIB-DELETE). BIB-RECURSIVE-MIN(V ) : 1 if V.u == 2 2 if V.A[0] == 1 3 return 0 4 elseif V.A[1] == 1 programmingexamhelp.com
  • 5. 5 return 1 6 else return NIL 7 else c = BIB-RECURSIVE-MIN(V.summary) 8 if c = = NIL 9 return NIL 10 else i = BIB-RECURSIVE-MIN(V.cluster[c]) 11 return c √ u + i There are a two key cases for BIB-DELETE: if we delete the global min, we have to find the next min and delete it from the recursive substructures, as the global min is not stored recursively. Otherwise, it suffices to simply delete the element from the appropr √ iate cluster, and delete the cluster from the summary (which is itself a Bib Tree of size u) if necessary. BIB-DELETE(V, x) : 1 if x == V.root.min 2 newmin = BIB-RECURSIVE-MIN(V ) 3 BIB-DELETE(V, newmin) 4 V.root.min = newmin 5 elseif V.u == 2 6 V.A[x] = 0 7 else programmingexamhelp.com
  • 6. 8 BIB-DELETE(V.cluster[high(x)], low(x)) 9 if BIB-RECURSIVE-MIN(V.cluster[high(x)]) = = NIL // Is the cluster now empty? 10 BIB-DELETE(V.summary, high(x)) It is possible to avoid the extra BIB-RECURSIVE-MIN call in line 7 of BIB-DELETE above by defining an additional variable to count the number of items stored in each Bib Tree structure. (b) Write the recurrences for the run-times of the operations in the revised data structure and solve the recurrences. Solution: BIB-MIN is not recursive, and so just takes O(1) time. BIB-INSERT has 2 recursive calls to BIB-INSERT, so has recurrence T(u) = 2T( √ u)+ O(1). We can solve this recurrence by substitution: Define m = lg u, so that u = 2m and √ u = 2m/2 , and S(m) = T(2m) = T(u). Then S(m) = 2S(m/2) +O(1), so S(m) = Θ(m) by the Master method and T(u) = Θ(lg u). BIB-RECURSIVE-MIN likewise has recurrence T(u) = 2T( √ u)+O(1) and therefore also takes time Θ(lg u). Fina √ lly, as written above BIB-DELETE has a worst-case running time of T(u) = 2T( u) + TBIB-RECURS IVE-MIN = 2T( √ u) + Θ(lg u). programmingexamhelp.com
  • 7. Using substitution, as above, we get S(m) = 2S(m/2) + Θ(m), which solves to Θ(m lg m) = Θ(lg u lg lg u) by the Master method. (c) Ben Bitdiddle decides to use the Bib-Tree data structure in his implementation of Prim’s algorithm (§23.2). You can assume that the input graphs of interest all have integer weights in the range from 1 to n and that edge weights are allowed to repeat. Show how Ben would make use of his Bib-Tree and provide an analysis of time complexity for this implementation of Prim. Solution: We cannot use the Bib Tree directly for Prim’s algorithm, because the Bib Tree as described in the previous parts does not have the capability of storing multiple elements with the same key. In order to make it possible to use the Bib Tree for Prim’s algorithm, we make the following modifications: 1. At the leaves of the Bib Tree (the base case, where the universe size is u = 2), make V.A into an array of pointers rather than a bit array as it was previously. Each pointer is NIL if no vertex has that key, and is a pointer to the head of a linked list containing all vertices with that key otherwise. 2. 2. In the base case of BIB-INSERT, if we are inserting a value v with key k: rather than setting V.A[k] to be 1, we instead add v to the end of the linked list at V.A[k], or create a new linked list with one element if V.A[k] was previously NIL. Additionally, when we programmingexamhelp.com
  • 8. insert (k, v), we store a pointer to its position in that linked list with the vertex v, which will become useful later for the modified BIB-DELETE. 3. When BIB-DELETE(k, v) is called, at the base case, we can delete v from the linked list at k by following the pointer stored with v upon its insertion. We implement EXTRACT-MIN by getting a vertex whose current key is the global min; then we must call BIB-DELETE on that key (with the vertex) to remove the vertex from the linked list, and potentially replace the global min with the next smallest element. In the worst case, this takes as much time as BIB-DELETE, which takes Θ(lg n lg lg n) time by the previous part of the pset. INSERT(k, v) is simply a call to the modified BIB-INSERT procedure. DECREASE- KEY(k, v) involves a call to the modified BIB-DELETE followed by one to BIB- INSERT, which takes a total of Θ(lg n lg lg n) time. Prim’s algorithm takes |V |TEXTRACT-MIN + |E|TDECREASE-KEY, so with our modified Bib Trees this takes Θ((E + V ) lg n lg lg n) time. programmingexamhelp.com