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...
Give an algorithm to determine whether or not the elements of an array of integers are all unique. Argue that your algorithm is correct, and that it terminates (doesn’t run forever). Give best and worst case run-time analyses. That is, what are big-O and big-Omega for your algorithm?
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...
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...
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.
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.
Devise a heap-sorting-based algorithm for finding the k smallest EVEN elements of an unsorted set of n-element array. The corresponding average analytical time-complexity should also be provided. (Show your work; the time complexity for heap-building must be included; it is assumed that 50% of elements are even )
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...