[SOLVED] Homework03 Priority Queues

24.99 $

Programming resource
Digital learning resource
Category:
Practical programming resource
Suitable for guided study and reference
Tutor guidance available when needed

Description

5/5 - (1 vote)

Problem

Given an integer array with no duplicates. A priority queue building on this array is defined as follow: The root is the maximum number in the array The left subtree and right subtree are the heaps of the subarray divided by the root number. Construct the heap by the given array. Example Given [16 14 10  8  7  9  3  2  4  1] the priority queue visualized by this heap is:

 

Write a program that builds a priority queue on input array and output an array representation of the heap.

 

Sample input

2,4,1

16,14,10,8,7,9,3,2,4,1

 

Sample output

The array representation of the heap is [4 2 1]

The array representation of the heap is [16 14 10  8  7  9  3  2  4  1]

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.