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
Which colour scheme and design elements would you choose for a website for a neighbourhood swim team
ladessa [460]
F this is not related to math I’d pick light blue or a teal blue with either white or gold
7 0
2 years ago
Which of the following statements is false? Question 16 options: A) With non-static interface methods, helper methods can now be
Delicious77 [7]

Answer:

The best answer is "A"

Explanation:

With non-static interface methods, helper methods can now be declared directly in interfaces rather than in separate classes.

5 0
3 years ago
Read 2 more answers
In which patten the modern computer work ?​
umka21 [38]

Answer:

Von Neumann describió el fundamento de todo ordenador electrónico con programas almacenados. Describía, a diferencia de como pasaba anteriormente, como podía funcionar un ordenador con sus unidades conectadas permanentemente y su funcionamiento estuviese coordinado desde la unidad de control (a efectos prácticos es la CPU). Aunque la tecnología ha avanzado mucho y aumentado la complejidad de la arquitectura inicial, la base de su funcionamiento es la misma y probablemente lo seguirá siendo durante mucho tiempo. El artículo viene acompañado de una representación gráfica del funcionamiento.

Explanation:

4 0
3 years ago
You are on a team of developers writing a new teacher tool. The students names are stored in a 2D array called “seatingChart”. A
Lesechka [4]

Answer:

Wait what? Some of the words are mashed together...

5 0
3 years ago
You are the network administrator for a growing business. When you were hired, the organization was small, and only a single swi
jek_recluse [69]

Answer:

-use syslog to implement centralized logging

Explanation:

3 0
3 years ago
Other questions:
  • Which of the following is true about the strategy that uses page fault frequency (PFF) to prevent thrashing?
    6·2 answers
  • Which activity constitutes legal computer activity?
    12·1 answer
  • Modify the Eggs program to create a new one named EggsInteractive that prompts the user for and accepts a number of eggs for eac
    13·1 answer
  • What did I do wrong? May you please correct it for me...I was also looking on how to delay when it prints. Like when it prints a
    9·1 answer
  • The first computer was developed by the government to spy on communist activities. Please select the best answer from the choice
    13·1 answer
  • While performing disk and file maintenance on the company file server, you determine a user in the accounting department has bee
    13·2 answers
  • Give short answers.
    14·1 answer
  • Suppose you are choosing between the following three algorithms:
    11·1 answer
  • Please help me i’ll give you brainlist
    13·1 answer
  • What are two advantages of edge computing over cloud computing?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!