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
A diagram of a flow chart to find the average of 10 numbers​
Nat2105 [25]

Answer:

Kindly check attached picture

Explanation:

Flowchart gives a graphical representation of a steps taken towers the execution of a program.

In the flowchart attached, A variable was initialized and set to 0 ; then a for loop was used to iterate integers 1 up to 10, for each number. It is added to the initialized variable sum until all the 10 integer numbers are added. The the average is obtained by dividing by 10.

4 0
3 years ago
In what country have regulators demanded that facebook stop collecting biometric data on its users?
Helga [31]
America or Australia
6 0
4 years ago
What is the difference between a Yahoo! and Yippy!?\
dmitriy555 [2]

Answer:

I guess the year it was found that's it

Yahoo- January 1994

Yippy- 2004 under the name Clusty but then was sold in 2010 to a company now called Yippy

5 0
3 years ago
unittttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt
alukav5142 [94]
What the hell is the point of this, just to waist people's time?
5 0
3 years ago
What help the ict in your life?and write own idea three or four sentence
My name is Ann [436]

Answer:

I am a software engineering student

computers have createed an impact in my life because through computers i work, I do research and many more

7 0
3 years ago
Other questions:
  • I need the alphabet quickly! sorry bad with remembering!
    10·1 answer
  • The two variables causing the point of difference between the time codes are the frequency and the count
    6·1 answer
  • What are the keys in all rows that sit between the touch keys
    11·1 answer
  • The central device on a network that provides a common connection point for nodes on that network is called the
    8·1 answer
  • If a computer file will not open, what should you do? A. Make sure you have the correct software to open it. B. Change the name
    9·1 answer
  • Which of the following controls will provide an area in the form for the user to enter a name? a. button b. label c. text box d.
    8·1 answer
  • You are seeking a way to store computer files so you have backup copies anywhere you go.? Which one of the secondary storage typ
    11·1 answer
  • Which element of the Word program window displays information about the current document, such as number of pages, and also incl
    14·1 answer
  • Write a Python program that accepts a numeric value from the user and prints the number starting from 0 up to the user’s value.
    8·1 answer
  • FIRST ANSWER GETS BRAINLIEST IM GIVING 30 POINTS!!!! Select the correct answer. Emma's project team has to create an application
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!