1 / 12

Extra material

Extra material. Prove that bottom-up construction of a heap for n items takes O(n) units of time. Bottom-up construction of a heap. 14. 8. 9. 25. 27. 6. 5. 16. 15. 4. 12. 20. 23. 11. 7. 16,15,4,12,11,7,23,20,25,5,6,27,9,8,14. Bottom-up construction of a heap. 16. 15. 4.

Download Presentation

Extra material

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Extra material Prove that bottom-up construction of a heap for n items takes O(n) units of time Applied Algorithmics - week2

  2. Bottom-up construction of a heap 14 8 9 25 27 6 5 16 15 4 12 20 23 11 7 16,15,4,12,11,7,23,20,25,5,6,27,9,8,14 Applied Algorithmics - week2

  3. Bottom-up construction of a heap 16 15 4 12 20 23 11 7 16,15,4,12,11,7,23,20,25,5,6,27,9,8,14 Applied Algorithmics - week2

  4. Bottom-up construction of a heap 25 6 27 5 16 15 4 12 20 23 11 7 16,15,4,12,11,7,23,20,25,5,6,27,9,8,14 Applied Algorithmics - week2

  5. Bottom-up construction of a heap 15 11 20 4 16 5 25 12 27 23 6 7 16,15,4,12,11,7,23,20,25,5,6,27,9,8,14 Applied Algorithmics - week2

  6. Bottom-up construction of a heap 9 8 15 11 20 4 16 5 25 12 27 23 6 7 16,15,4,12,11,7,23,20,25,5,6,27,9,8,14 Applied Algorithmics - week2

  7. Bottom-up construction of a heap 4 11 15 8 20 9 16 5 25 12 27 23 6 7 16,15,4,12,11,7,23,20,25,5,6,27,9,8,14 Applied Algorithmics - week2

  8. Bottom-up construction of a heap 4 11 15 8 20 5 16 9 25 12 27 23 6 7 16,15,4,12,11,7,23,20,25,5,6,27,9,8,14 Applied Algorithmics - week2

  9. Bottom-up construction of a heap 14 4 11 15 8 20 5 16 9 25 12 27 23 6 7 16,15,4,12,11,7,23,20,25,5,6,27,9,8,14 Applied Algorithmics - week2

  10. Bottom-up construction of a heap 4 5 11 15 8 20 9 16 14 25 12 27 23 6 7 16,15,4,12,11,7,23,20,25,5,6,27,9,8,14 Applied Algorithmics - week2

  11. Extra material Prove that bottom-up construction of a heap with n items takes O(n) units of time 20 1*(logn-1) Sum=n/4*1+n/8*2+n/16*3++1*(log n-1) = ∑ n(i-1)/2i =n∑ i/2i -n∑ 1/2i ∑ 1/2i= 1/2+1/4+1/8+1/16 1/2log n≤ 1, also in general case ∑ 1/2i ≤ 1/2k+1/ 2k+1+ 1/2log n≤ 1/2k-1 21 2*(logn-2) i=logn i=logn i=logn 22 3*(logn-3) i=2 i=2 i=2 23 i=logn i=1 2logn-2 n/4*1 i=logn 2logn-1 n/2*0 i=k 1/8 1/2 1/4 Applied Algorithmics - week2

  12. Extra material Prove that bottom-up construction of a heap with n items takes O(n) units of time 20 1*(logn-1) Sum=n/4*1+n/8*2+n/16*3++1*(log n-1) = ∑ n(i-1)/2i = n∑ i/2i - n∑ 1/2i i=2 1/4 + 1/4 i=3 1/8 + 1/8 + 1/8 i=4 1/16 +1/16 +1/16 +1/16  i=logn 1/logn +1/logn+  +1/logn ≤1/2+≤1/2+≤1/4 + ≤1/2log(n-2)≤1.5 n∑ i/2i - n∑ 1/2i ≤ n 21 2*(logn-2) i=logn i=logn i=logn 22 3*(logn-3) A B i=2 i=2 i=2 23 B A A-B 2logn-2 n/4*1 2logn-1 n/2*0 i=logn i=logn i=2 i=2 Applied Algorithmics - week2

More Related