1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
saul85 [17]
4 years ago
6

Implement the function is_maxheap which takes a list of integers and returns True if the list represents a valid max-heap, and F

alse otherwise. Assume that the list represents the contents of a complete binary tree, following the parent/child indexing conventions established in class. E.g., is_maxheap should return True for the following inputs: a) [] b) [10] c) [10, 7, 8] E.g., is_maxheap should return False for the following inputs: a) [1, 2] b) [5, 6, 3] You should not define or use any external data structures in your implementation besides the list passed in.

Computers and Technology
1 answer:
harkovskaia [24]4 years ago
5 0

Answer:

I am writing a Python function:

def is_maxheap(list):

   #finds the length of the list  

   size=len(list)

   #loop has a variable i which starts traversing from root til end of last #internal node

   for i in range(int((size - 2) / 2) + 1):  

       if list[2 * i + 1] > list[i]:  #If left child is greater than its parent then return #false  

               return False  

       if (2 * i + 2 < size and

           list[2 * i + 2] > list[i]):    #checks if right child is greater, if yes then #returns false  

               return False

   return True

Explanation:

The function is_maxheap() traverses through all the internal nodes of the list iteratively. While traversing it checks if the  node is greater than its children or not. To check the working of this function you can write a main() function to check the working on a given list. The main() function has a list of integers. It then calls is_maxheap() method by passing that list to the function. The program displays a message: "valid max heap" if the list represents valid max-heap otherwise it returns invalid max heap.

def main():

   list = [10,7,8]  

   size = len(list)  

   if is_maxheap(list):

       print("Valid Max Heap")  

   else:  

       print("Invalid Max Heap")          

main()

The program along with its output is attached in a screenshot.

You might be interested in
How many responses does a computer expect to receive when it broadcasts an ARP request?why?
Alla [95]

Answer: The response that is expected when it broadcast an ARP request is one or zero.

Explanation: ARP request means Address Resolution Protocol which is a protocol responsible for the mapping of the IP(Internet protocol)address of a system to the MAC(Media Access Control) layer. Only one response is received only if the IP address is present in the ARP otherwise if the IP address does not matches then no response is returned.Thus only one or zero response can be received when a ARP request is process.

5 0
3 years ago
Define Class in C++. Briefly discuss.
lesya [120]

Answer:

Class are the collection of variable and member function.

Class are the blueprint of an object.

Explanation:

Following are the points regarding class in c++

1.In C++ class is an user defined datatype..

2.Classes are the collection of variable and function in c++.

3.To access the property of class we can create object of that class

4.We can use following syntax to declared any class in c++

class classname

{

accessmodifier:

//statement and function

};

main()

{

classname objectname;

}

implementation of class in c++

#include<iostream>

class test // class declaration

{

public: // access modifier

void fun3() // Method definition

{

cout<<" hello :";

}

};

void main() // main function

{

test ob;// creating object

ob.fun3(); // calling function

}

In this program we declared a class "test " in class test. We giving public access modifier .The public access modifier define that variable and function are accessible outside the class and in main method we create the object ob which call the function fun3().

Output:hello :

3 0
3 years ago
Which type of address defines a single network interface in a computer or other device?
White raven [17]
MAC address
......... ..
4 0
3 years ago
A _____ cloud allows an organization to take advantage of the scalability and cost-effectiveness that a public cloud computing e
balu736 [363]

Answer:

Hybrid

Explanation:

Hybrid cloud is a solution that combines a private cloud with one or more public cloud services, with proprietary software enabling communication between each distinct service.

5 0
4 years ago
Given the declarations struct BrandInfo { string company; string model; }; struct DiskType { BrandInfo brand; float capacity; };
Nonamiya [84]

Answer:

Type of myDisk.brand is BrandInfo.

Explanation:

4 0
3 years ago
Other questions:
  • Write a program that reads in 10 numbers from the user and stores them in a 1D array of size 10. Then, write BubbleSort to sort
    13·1 answer
  • What effects will the different types of lighting produce on mountains?
    15·1 answer
  • An organization's contact information includes its _____.
    9·2 answers
  • A popular encryption method used to protect data that travel over a wireless network is ____
    12·1 answer
  • How do you validate the type of text that a user enters?
    7·1 answer
  • When dealing with a person who is behaving violently you should argue with them. A. False B. True
    5·1 answer
  • What is the meaning of the phrase the video has gone viral
    9·2 answers
  • Write a CPP Program to read an integer number. Use a pointer to display this numbe
    5·1 answer
  • Hey everyone. I am so bored
    14·2 answers
  • Write a factorial method that takes in an integer as input, recursively computes its factorial using BigInteger and return a Big
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!