CramX Logo
Analysis of Algorithms: Heapification, Minimum Spanning Tree, Inversions, Sorting, and Random-Select - Document preview page 1

Analysis of Algorithms: Heapification, Minimum Spanning Tree, Inversions, Sorting, and Random-Select - Page 1

Document preview content for Analysis of Algorithms: Heapification, Minimum Spanning Tree, Inversions, Sorting, and Random-Select

Analysis of Algorithms: Heapification, Minimum Spanning Tree, Inversions, Sorting, and Random-Select

This paper analyzes key algorithms in computer science, including heapification, minimum spanning trees, and sorting techniques.

Michael Davis
Contributor
4.5
0
12 months ago
Preview (3 of 8 Pages)
100%
Log in to unlock
Page 1 of 3
Analysis of Algorithms: Heapification, Minimum Spanning Tree, Inversions, Sorting, and Random-Select - Page 1 preview imageAnalysis of Algorithms: Heapification, Minimum Spanning Tree, Inversions,Sorting, and Random-SelectProblem 1:Answer:The provided solution will not heapify the given array.TheHeapifyHeap()function can beconsidered as building a heap from the bottom up, consecutively pushing downward to establishthe property of the heap.The algorithm for the supporting functionHeapifyHeap()is given below:Algorithmalter_heapify(array, arraySize) isInput:An arrayarrayand its sizearraySize.Ouput:A bubble down array.Assign the index in array of the last parent node to the variablebegin.The index of the lastparent node will be equal to(arraySize-2 ) / 2.//assign valuei← (arraySize-2 ) / 2With the help of awhileloop push down the node at indexbeginto the proper place suchthat all nodes below theindexbeginare in heap order.//create while loopwhile i ≥ 0 do// call PushDown()PushDown(array,begin, arraySize-1)// decrement begini ← i1After pushing down the root, all the elements will be in heap order. Thus, now the bubble downarray is heapify. An example to show this is as given below:
Page 2 of 3
Analysis of Algorithms: Heapification, Minimum Spanning Tree, Inversions, Sorting, and Random-Select - Page 2 preview image
Page 3 of 3
Analysis of Algorithms: Heapification, Minimum Spanning Tree, Inversions, Sorting, and Random-Select - Page 3 preview imageProblem 2:a)What is the length of minimum spanning tree in Figure 1?Answer:The given figure shows that there are six nodes. Thus, the minimum length will be n-1. So, hereit will be 6-1=5. So, the minimum length of this spanning tree is 5.b)Assume an algorithm A solves the minimum spanning tree problem. Prove that A has a timecomplexity ofΩ(n log n).Answer:The total number of the comparisons required in the worst case for finding the largest path froma givenminimum spanning tree ofthe desired leave is()()log N!.The given expression can be evaluated using theStirling formula()N1N!2NN /1NeO=+The value of the expression after evaluation is as given below:()()()log N!NlogN= So, the value of the lower bound after expanding is()Nlog N.Thus, it can be said that thealgorithm will have time complexity of()Nlog N. For example,A minimum spanning tree algorithm such as Prim-Jarnik’s algorithm can be used to find asolution for calculating the cost of traveling salesman with a slight modification. Instead of
Preview Mode

This document has 8 pages. Sign in to access the full document!