Output: array[] = {81, 62, 76, 43, 54, 63, 66, 38, 19, 22}
Since left child of ith node is 2*i and right child is 2*i+1. So, to heapify left and right child is compared with root node. And Swapping is performed to make the parent node with maximum value.
Example Explanation:
i=2, so left child is at i=4 and right child is at i=5. And array[4]=62 and array[5] =54. 62 is maximum among 54 and 63 and also greater than root node that is 19. Swapping will be done between i=2 and i=5 so that parent node is having maximum value than its child. Now, Heapification will be done below i=5 node. Left child of i=5 node is at i=10 and right child is at i=11. And 43 at i=11 is maximum among other 38(i=10) and 43(i=11), And 43 is also greater than parent node that is 19(i=5). So, again swapping will be done between i=5 and i=11. Now node at i=11 is leaf node, no more heapification will be performed. So now updated array is {81, 62, 76, 43, 54, 63, 66, 38, 19, 22}
• Apply the MAX-HEAPIFY algorithm to the following array A on node i = 2 and...
Write a C program to assign natural numbers 1 to 100 into a one-dimensional integer array. Display all the values in the array on the screen. For each number in the array, determine if the number contains digit 7 or is divisible by 7. Display all those numbers on the screen. Original array: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27...
I need it in JAVA Write a program that randomly populates an array of size 100, sorts it, and then finds the median. The random numbers must be from 0-99 and all integer values. Also since there is an even set of numbers the median is found by taking the mean of the two middle numbers (In other words the 50th and 51st). You have to code your own sorting method. You may not use a built in java sorter....
Write a Java program, In this project, you are going to build a max-heap using array representation. In particular, your program should: • Implement two methods of building a max-heap. o Using sequential insertions (its time complexity: ?(?????), by successively applying the regular add method). o Using the optimal method (its time complexity: ?(?), the “smart” way we learned in class). For both methods, your implementations need to keep track of how many swaps (swapping parent and child) are required...
Suppose a binary tree data (in tiny written size) is stored in an array (A) as given below and root is placed at “0”index. Note the array indices are in larger written size (0 to 74). Show the traversal data of the given tree for a) In-Order Traversal b) Post Order Traversal A 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 3 28 13 36 15 9 22 44 7 10 75 33 19 15...
Python 3 Create a function that takes an array and an integer v, and returns the number of v occurrences in the array. Add a variable Nsteps to count how many times the loops have executed and display that information in a message The main program must take an array / list 2D, call the function, and display the result. >>>l3 = [52, 14, 14, 8, 85, 69, 1, 77, 94, 96, 51, 65, 35, 32, 87, 92, 74, 47,...
Please ignore red marks. Thanks
6. (8 pts) Illustrate the algorithmic operations on the maximum binary heap data sti 'perations on the maximum binary heap data structure as directed. BUILD-MAX-HEAP(A) MAX-HEAPIFY (A. i) 1 A heap-size = A.length 11 = LEFT() 2 for i = A.length/2) downto 1 2 r = RIGHT() 3 MAX-HEAPIFY (A,i) 3 if / S 4.heap-size and All > A[i] HEAP-EXTRACT-MAX (A) 4 largest = 1 5 else largest = 1 1 if A.heap-size <1 6...
A max-heap with 10 elements is given in the following array format. The following three sub-questions all refer to this max heap. i 1 2 3 4 5 6 7 8 9 10 A[i] 99 90 80 70 60 50 40 30 20 10 Show the result after applying heap-increase-key(A, 9, 95) to the max-heap at the top of this page: i 1 2 3 4 5 6 7 8 9 10 A[i] Show the result after applying heap-extract-max(A) to...
For each variable of interest, do the following: 1. Find the mean, five-number summary, range, variance, and standard deviation. Display these numbers in a format that is easy to understand. 2. For each variable of interest, use its five-number summary to construct a boxplot. Each boxplot must be constructed horizontally, and must be accompanied by a brief descriptive paragraph that assesses whether the data appear to be symmetrical, left-skewed, or right-skewed. Construct a 95% confidence interval for the mean μ...
Consider the following max-heap: i 0 1 2 3 4 5 6 7 8 pq[i] - 30 18 28 17 6 20 2 9 Show the resulting heap as array after performing delmax().
JAVA Objectives: 1. Apply linear search algorithm 2. Apply select sort algorithm 3. Apply array iteration skill Problem description: Write the following eight methods and write a main function to test these methods // return the index of the first occurrence of key in arr // if key is not found in arra, return -1 public static int linearSearch(int arr[], int key) // sort the arr from least to largest by using select sort algorithm public stati void selectSort(int arr[])...