a.
The possible position of key N-2 if N> 7 is in either at level 1 or level 2.
At level 0, only N could be possible.
So the possible position of key N-2 is a[2],a[3],a[4],a[5],a[6],a[7] which is independent of N
All the red nodes in foll. diagram are possible position of key N-2.

b. The possible position of 2 is either the leaf node or the parent of last node if N is even and value of last node is 1.
Any other position is not possible because if no. of children is two, key of the node must be greater than 2.
So, if N is odd, possible position of key 2 is a[(N+1)/2],a[(N+1)/2 + 1], ......... a[N]
and if N is even, possible position of key 2 is a[N/2],a[N/2 + 1], ......... a[N].
Diagram of this is not possible to draw.
1. Suppose that an array al] is a max-heap that contains the distinct integer keys 1,...
Suppose that A is an array whose integer elements are organized into a max-heap. Also suppose that e is an integer. Write an algorithm IS-IN-MAX-HEAP(A, e) that tests if e is an element of A. Your algorithm must not change A, and it must not make copies of A. It must avoid visiting all elements of A where possible—so it must not use linear search. You may state your answer in English, in Cormen’s pseudocode notation, or in a programming...
Using C++, data structures, C++ STL, inputs and expected
outputs are shown below.
Max Heap Heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either > (in a max heap) or s (in a min heap) the key of C. The node at the "top" of the heap (with no parents) is called the root node. In binary-tree based heap, it...
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...
Consider the following max-heap stored as an array: <7, 6, 4, 2, 5, 1, 3>. Draw this max-heap as an (undirected) binary tree and give both adjacency-list representation and adjacency-matrix representation of the binary tree
1. In Lab 4, you developed a program to build a Max Heap, and then Heap Sort. Update the program by adding two additional functions: (a) AddData(A, N, V) where V is the new value added. (b) Delete a data Delete by giving the index of the data position Make sure to display the array after calling each of the function. 2. Write a program to implement Binary Search Algorithm, which will return the index of the data searched (V)....
5. A three-heap with n elements can be stored in an array A, where A[O] contains the root of the tree. a) Draw the three-heap that results from inserting 5, 2, 8, 3, 6, 4, 9, 7, 1 in that order into an initially empty three-heap. You do not need to show the array representation of the heap. You are only required to show the final tree, although if you draw intermediate trees. b) Assuming that elements are placed in...
Suppose we have an array that contains tuples. These tuple contains three positive numbers. Implement an algorithm that counts how many distinct tuple that an array has(contains same number in same order). ex) [(1, 2, 1), (2, 2, 2), (3, 8, 3), (1, 2, 1), (3, 4, 3)] gives 4. 1 The algorithm should be implemented in Python3. 2 The function must have average-case runtime of O(n). You can assume Simple Uniform Random Hashing. 3 Python built-in dictionary cannot be...
4 Easy Quiz Questions Question 1: Below are the contents of the id array for the quick-find version of the Union-Find algorithm. 0,4,7,0,4,4,4,7,8,0 The contents are listed in order from slot 0 to slot 9. (So for example, id[1] is 4 and id[2] is 7. What are the contents of the id array after the call union(5, 3)? Use the same format as above (a comma-separated listing of the contents without spaces). _____________________ Question 2 Below are the contents of...
#include <stdio.h>
// Define other functions here to process the filled array: average, max, min, sort, search
// Define computeAvg here
// Define findMax here
// Define findMin here
// Define selectionSort here ( copy from zyBooks 11.6.1 )
// Define binarySearch here
int main(void) {
// Declare variables
FILE* inFile = NULL; // File pointer
int singleNum; // Data value read from file
int valuesRead; // Number of data values read in by fscanf
int counter=0; // Counter of...
PROGRAM DESCRIPTION Using the given class definitions for either C++, create a minimum heap that stores integers and and implements a minimum priority queue. (Your program can be "hard coded" for integers - it does not need to use templates, generics, or polymorphism.) Your data structure must always store its internal data as a heap. Your toString function should return a string with the heap values as a comma separated list, also including the size of the heap as well....