Complete the code to declare a max heap using a list in C#.
List<int> maxHeap = new List<int>[1];In C#, to create a new list, you use parentheses () after the type.
Complete the code to get the index of the left child of a node at index i in a heap.
int leftChildIndex = [1];2 * i which is the formula for 1-based indexing.i + 1 which is just the next element.In a heap stored as an array or list, the left child of node at index i is at 2 * i + 1.
Fix the error in the code to get the parent index of a node at index i in a heap.
int parentIndex = (i - 1) [1] 2;
The parent of a node at index i is at index (i - 1) / 2 in zero-based indexing.
Fill both blanks to complete the condition that checks if a node at index i has a right child in the heap.
bool hasRightChild = (rightChildIndex < [1]) && (rightChildIndex == i [2] 1);
To check if right child exists, its index must be less than the heap size (heap.Count in C# List). The right child index is 2 * i + 2, which is i + 1 more than left child index 2 * i + 1.
Fill all three blanks to complete the code that swaps two elements at indices i and j in the heap list.
int temp = heap[[1]]; heap[[2]] = heap[[3]]; heap[[1]] = temp;
To swap elements at indices i and j, store heap[i] in temp, assign heap[j] to heap[i], then assign temp to heap[j].
