Source Code in C++:
#include <iostream>
#include <iterator>
using namespace std;
bool isValidHeap(int arr[],int n) //function to check if an
array is a valid terneary min heap
{
for(int i=0;i<n;i++) //iterating through all the nodes
{
for(int j=3*i+1;j<=3*i+3 && j<n;j++) //iterating
through the child nodes for every node, if available
{
if(arr[i]>arr[j]) //if a parent node is higher than child node,
it is not valid
return false;
}
}
return true; //if program reaches this point, heap was valid min
heap
}
int main()
{
//testing the function
int arr1[]={4,7,10,6,12,9};
cout << "Array1 is " << (isValidHeap(arr1,6)?"":"not")
<< "a valid heap" << endl;
int arr2[]={5,10,9,4,12};
cout << "Array2 is " << (isValidHeap(arr2,5)?"":"not ")
<< "a valid heap" << endl;
return 0;
}
Output:

Task: A ternary heap is like a binary heap, except instead of each node having a max of two children, each node has a max of three children. Given a ternary min heap, return true if it is a valid hea...
Implement downHeap(Node *n) for a min heap implemented as an ordinary binary tree with an integer member variable "value" and left and right child pointers. Any node might have only a left child, only a right child, both, or neither. The starter code below defines a class called "Node" that has two child pointers ("left" , "right") and an integer "value" member variable. There is also a constructor Node(int val) that initializes the children to nullptr and the node's value...