In addition to these operations, you should also implement two display methods, for testing purposes. Prints the array representation (e.g. [16,14,10,8,7,3,9,1,4,2]) printAsArray: printAsTree: Prints the heap as a sideways tree, as shown below:

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

use any programming language and output screenshots

BUILD-MAX-HEAP:
Takes an arbitrary array and builds it into a max heap
Takes an almost-heap with one violation, and fixes the violation
Returns the largest element in the max heap
МАХ-НЕАРIFY:
НЕАР-МАХІМUM:
Removes and returns the largest element in the max heap
Inserts a new element into the heap, preserving the heap property
НЕАР-ЕXTRACТ-МАX:
MAX-HEAP-INSERT:
In addition to these operations, you should also implement two display methods, for testing purposes.
Prints the array representation (e.g. [16,14,10,8,7,3,9,1,4,2])
printAsArray:
printAsTree:
Prints the heap as a sideways tree, as shown below:
10
16
7
14
4
8.
1
Hint: For printAsTree(), you'll find it easier to write the function recursively including a depth argument (which
indicates how far to the right to indent the output). Recursion will be used to print the left and right subtrees (with a
incremented depth).
The implementation of heapsort() will be a function that takes an arbitrary array, and sorts it using a heap. Be sure to
include testing code, where you create a heap from an arbitrary array, use buildheap(), and then heapsort the array
(printing the array before and after), as well as testing the other operations mentioned above.
Transcribed Image Text:BUILD-MAX-HEAP: Takes an arbitrary array and builds it into a max heap Takes an almost-heap with one violation, and fixes the violation Returns the largest element in the max heap МАХ-НЕАРIFY: НЕАР-МАХІМUM: Removes and returns the largest element in the max heap Inserts a new element into the heap, preserving the heap property НЕАР-ЕXTRACТ-МАX: MAX-HEAP-INSERT: In addition to these operations, you should also implement two display methods, for testing purposes. Prints the array representation (e.g. [16,14,10,8,7,3,9,1,4,2]) printAsArray: printAsTree: Prints the heap as a sideways tree, as shown below: 10 16 7 14 4 8. 1 Hint: For printAsTree(), you'll find it easier to write the function recursively including a depth argument (which indicates how far to the right to indent the output). Recursion will be used to print the left and right subtrees (with a incremented depth). The implementation of heapsort() will be a function that takes an arbitrary array, and sorts it using a heap. Be sure to include testing code, where you create a heap from an arbitrary array, use buildheap(), and then heapsort the array (printing the array before and after), as well as testing the other operations mentioned above.
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Graphical User Interface
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education