120 likes | 216 Views
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.
E N D
Extra material Prove that bottom-up construction of a heap for n items takes O(n) units of time Applied Algorithmics - week2
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
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
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
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
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
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
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
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
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
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
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