ALGORITHM:
Considering max heap
We will run a loop for i= 1 to i<=n/2
We know that when a heap is represented in form of an array then considering the ith element to be the parent, it's left child is at index (2*i +1) and it's right child is at (2*i + 2)
So ,we will check if 2*i + 1 <=n then we will check if, H[2*i + 1] is less than H[i].If the second condition doesn't hold true then we will return false as our answer .
Doing the same for the right child.
After coming out of the for loop we will then return true.
Time Complexity:
The time complexity for this algorithm is O(n) because we are traversing the array once.
Outline an algorithm for checking whether an array H[1..n) is a heap and determine its time...
1. Argue that the problem, H, of creating a MIN-HEAP from an unsorted array of integers using the HEAPIFY algorithm discussed in class is at least as hard - and maybe even harder - than the problem, M, of finding the minimum element of the same unsorted array of integers.
Computer Algorithm question 8) Give an algorithm for building a heap in O(n) 9) Prove the algorithm given in 8) runs in O(n) time. 10) What is the asymptotic runtime of an algorithm represented by the following recurrence equation? 11) Suppose you have the following priority queue implemented as a (max) heap. What will the heap look like when the max node is removed and the heap is readjusted? Assume on each heapify operation the largest child node is selected...
5. A three-heap with n elements can be stored in an array A, where A[O] contains the root of the tree. a) Draw the three-heap that results from inserting 5, 2, 8, 3, 6, 4, 9, 7, 1 in that order into an initially empty three-heap. You do not need to show the array representation of the heap. You are only required to show the final tree, although if you draw intermediate trees. b) Assuming that elements are placed in...
need solution plz Question 1 (CLO-4, PLo-3) Figure 1 show an input tree T. 1. Analyze the tree and mention weather the tree is a heap or not by checking heap's property. If yes, justify your answer. If no, make it a heap by adjusting the node's location 2. Alter the value of T[l1] to 100 using alter-heap algorithm. Analyze the tree again and state whether i. The tree is still a heap or not? ii. If not, which one...
Convert the array a = [10, 26, 52, 76, 13, 8, 3, 33, 60, 42] into a maximum heap using the linear time heap building algorithm. Show the order of all items after each iteration.
need full solution of this question plz help me Question 1 (CLO-4, PLo-3) Figure 1 show an input tree T. 1. Analyze the tree and mention weather the tree is a heap or not by checking heap's property. If yes, justify your answer. If no, make it a heap by adjusting the node's location 2. Alter the value of T[l1] to 100 using alter-heap algorithm. Analyze the tree again and state whether i. The tree is still a heap or...
Show that the worst-case runtime of the Algorithm Heapify is on an array of length n in Ω(log(n)). Note: Construct a heap A with n nodes and show that heapify is called recursively accordingly.
In the lectures, we studied binary heaps. A min-Heap can be visualized as a binary tree of height with each node having at most two children with the property that value of a node is at most the value of its children. Such heap containing n elements can be represented (stored) as an array with the property Suppose that you would like to construct a & min Heap: each node has at most& children and the value of a node...
Consider the following algorithm. ALGORITHM Enigma(A[0.n - 1]) //Input: An array A[0.n - 1] of integer numbers for i leftarrow 0 to n - 2 do for j leftarrow i +1 to n - 1 do if A[i] = = A[j] return false return true a) What does this algorithm do? b) Compute the running time of this algorithm.
Provide an O(k log k) algorithm that uses a heap data structure to find the kth largest element from the heap of n elements where n > k. Sketch your algorithm. (Hint: You may need to use an additional heap) Use the example data below to demonstrate the process. (e.g. Find the 7 largest element from this heap and it should be 45) Justify the running time. Heap H 100 80 70 40 50 65 60 20 40 10 30...