Question

• Apply the MAX-HEAPIFY algorithm to the following array A on node i = 2 and give the resulting array. | i Ali | 1 | 2 | 3 |

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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}

Add a comment
Know the answer?
Add Answer to:
• Apply the MAX-HEAPIFY algorithm to the following array A on node i = 2 and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need it in JAVA Write a program that randomly populates an array of size 100,...

    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...

    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...

    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...

  • Please ignore red marks. Thanks 6. (8 pts) Illustrate the algorithmic operations on the maximum binary...

    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...

  • JAVA Objectives: 1. Apply linear search algorithm 2. Apply select sort algorithm 3. Apply array iteration...

    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[])...

  • For each variable of interest, do the following: 1. Find the mean, five-number summary, range, variance,...

    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 μ...

  • Apply the A" algorithm to the 8-puzzle problem to the initial tile pattern shown below to arrive ...

    Apply the A" algorithm to the 8-puzzle problem to the initial tile pattern shown below to arrive at the goal node. Show expansion of the tiles as illustrated in lecture notes and book chapter, along with evaluation value f g+h, numeric order of selected nodes and backtracking arrows Numeric order of chosen node #of search bles where n is a node 47 displaced nitial node 81 Goal node 12 5 8 13 7 4 3 6 2 5 6 25...

  • Create a JavaFX application that generates a 10 x 10 grid. Populate each cell in the grid with a ...

    Create a JavaFX application that generates a 10 x 10 grid. Populate each cell in the grid with a random integer in the range [0, 99]. If the integer is divisible by 2, color the cell blue. If the integer is divisible by 3, color the cell yellow. If the integer is divisible by 6, color the cell green. Here's a sample run: Number Grid 74 74 38 57 62 40 42 65 27 38 44 8 48 60 30...

  • Q3) Apply Quick sort algorithm to sort the following Array (Show complete steps, and show the...

    Q3) Apply Quick sort algorithm to sort the following Array (Show complete steps, and show the values of p,r and q) 7 13 5 2 4 10 15 6 3 6

  • Use C++ (2D Array) Write a program which: 1. Assigns data given below into the 2D...

    Use C++ (2D Array) Write a program which: 1. Assigns data given below into the 2D array of integers which is 10x10. 2. Prints out the contents of the 2D array after assigning the data to make sure correct data was assigned. 3. Figures out and prints out the square root of the sum of ALL the elements in the 2D array. 4. Figures out and prints out the average of ALL THE ELEMENTS in the 2D array. 5. Figures...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT