



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Prof. Balamohan Pawar delivered this lecture at Allahabad University for Aeronautical Engineering and Computer Programming course. Its main points are: Sort, Merge, Analysis, Heaps, Array, Binary, Tree, Location, Build, Recursion
Typology: Slides
1 / 7
This page cannot be seen from the preview
Don't miss anything!




5
Statement^
Work
7
-^ T(n) =aT(n/b) + cna(aT(n/b/b) + cn/b) + cn^22 aT(n/b) + cna/b + cn^22 aT(n/b) + cn(a/b + 1)^22 a(aT(n/b/b) + cn/b 2 ) + cn(a/b + 1) (^33 22) aT(n/b) + cn(a/b) + cn(a/b + 1) (^33 22) aT(n/b) + cn(a/b+ a/b + 1)…k k k-1k-1^ k-2k-2^2 aT(n/b ) + cn(a/b + a/b^ + … + a/b =⎧⎪⎞⎛⎨>+⎟⎜ ⎪⎩⎠⎝^2 + a/b + 1) (^1) nc n = (^) )( nT (^1) ncnaTb docsity.com
9
k-1k-1^22 /b^ + ... + a/b+ a/b + 1)
=^1 nc ⎧⎪ n ⎞⎛= (^) )( nT ⎨>+^1 ncnaT ⎟⎜ ⎪ b ⎩⎠⎝ k-1k-1 (^22) /b + ... + a/b+ a/b + 1)kk-1k-1 (^22) = ac + cn(a /b + ... + a/b+ a/b + 1)k k-1k-1 (^22) = ca+ cn(a /b + ... + a/b+ a/b + 1)k k k-1k-1 (^22) = cna/b + cn(a/b + ... + a/b+ a/b + 1)k k (^22) = cn (a /b + ... + a/b+ a/b + 1)
nb^ kk (^22) – T(n) = cn(a/b+ ... + a^ /b+ a/b + 1)
=^1 nc ⎧⎪ n ⎞⎛= (^) )( nT ⎨>+^1 ncnaT ⎟⎜ ⎪ b ⎩⎠⎝ n + 1)= O(n log n)
11 Heapsort: Best of two worlds• Merge sort– Advantage: O(n log n)• Insertion sort– Advantage: Can sort in place, and efficientfor nearly sorted arrays Heapsort^ Combines the advantage of Merge andInsertion sort^
Heaps
16 14 10 8 7
9 3
has all leaves at the same depthHeaps are^ nearly
complete binary trees
docsity.com
17 Is the tree a Heap?^1614
Heap_Array =^
Now it is a heap^1614
Heap_Array =^14
19 Heapify Heapify^ (A,^ i)lchild^ :=^ Left(i)rchild^ :=^ Right(i)^ if^ (lchild^ <=^ heap_size
and^ A[lchild]^ >^ A[i])
then largest^ :=^ lchild else largest^ :=^ i if (rchild^ <=^ heap_size^
and^ A[rchild]^ >^ A[largest])
then
Creating a heap• Given an unsorted array build_heap (A, Size)heap_size(A) := Size; for i in^ ⎣Size/2⎦^ downto
^1 Heapify(A, i);
docsity.com
21 Build_Heap 1 24 3 16 9 10 14
Heap_Array =
Build_Heap 1 24 3 16 9 10 14
Heap_Array =
4 6 8 105 7 9 23 Build_Heap 1 144 3 16 9 10 2
Heap_Array =
4 5 6 7 8 9 10
Build_Heap 1 144 10 16 9 3 2
Heap_Array =
4 5 6 7 8 9 10
docsity.com
29 Heap 14 816 10 7 9 3 2 4 1 Heap_Array =
6 8 105 7 9
Heap Sort BuildHeap(A); for i in size^ downto^^2 Swap(A[1], A[i])heap_size:= heap_size -1;Heapify(A, 1);
docsity.com