Write an efficient algorithm that checks if a vector-basedbinary tree is a valid max heap.
Question IV (25 minutes-20% Write an efficient algorithm that checks if a vector-based binary tree is a valid max heap For a inan tree to be a max heap, it has to be complete and each item is the largest in its subtree For instancet heap in Figure 5 is valid while the one in Figure 6 is invalid. Further, is it possible to use parallelisn t speed up the function? Explain. NULL 30 10 40 33 7 6 6 5 20 30 10 40 Figure 6 Figure 5 Note: left child’s index is: 2p+ 1, right child index is: 2p + 2 (p being the parent index). Parent index is: (c-1)/2 (c being the index of a child) Show transcribed image text Question IV (25 minutes-20% Write an efficient algorithm that checks if a vector-based binary tree is a valid max heap For a inan tree to be a max heap, it has to be complete and each item is the largest in its subtree For instancet heap in Figure 5 is valid while the one in Figure 6 is invalid. Further, is it possible to use parallelisn t speed up the function? Explain. NULL 30 10 40 33 7 6 6 5 20 30 10 40 Figure 6 Figure 5 Note: left child’s index is: 2p+ 1, right child index is: 2p + 2 (p being the parent index). Parent index is: (c-1)/2 (c being the index of a child)
Expert Answer
Answer to Write an efficient algorithm that checks if a vector-based binary tree is a valid max heap….