Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9132975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:24:21+00:00 2026-06-17T08:24:21+00:00

I am having some trouble with my homework. I was asked to implement a

  • 0

I am having some trouble with my homework. I was asked to implement a priority queue, using a heap in C++.

While searching for code examples for creating a heap, I encountered many times in this definition:

An array A that represents a heap is an array with two attributes:

– length, the number of elements in the array

– heap-size, the number of heap elements stored in the array

So my question is this: what is A? do I need to implement it by myself (let’s say make a class heap which holds 3 fields- array of elements, length, and heap_size)?

I just don’t know how to start.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:24:22+00:00Added an answer on June 17, 2026 at 8:24 am

    The binary heap data structure is usually drawn as a binary tree with certain properties, but is typically implemented using a plain array. The reason for this is that the array version uses less memory than the explicit binary tree and is a lot easier to manipulate. Consequently, the array A that you’re seeing described is the array that holds all the values in the heap.

    The two fields you are seeing represent the raw total size of that array (length), which tracks how much storage space is available, and the number of elements within that array that you are actually using (heap-size). When you insert an element into the heap, you will need to make sure that space exists for it, possibly reallocating the array to be larger and copying over the existing elements, then will need to run a bubble-up operation to insert the new element into the heap.

    Typically, though, you would sidestep the logic for maintaining the array and these two fields by layering the heap on top of a dynamic array, like the C++ std::vector or Java ArrayList. That way, the logic to track storage space and grow the array is handled for you automatically.

    Depending on the assignment parameters, since this is being done in C++, you might want to look into the std::make_heap, std::push_heap, and std::pop_heap algorithms from the <algorithm> header. They make it very easy to implement a heap on top of an existing container like std::vector. In fact, this is how the std::priority_queue class is typically implemented.

    If you need to implement the heap operations yourself, you might want to check out the description of a binary heap given in this assignment handout, which seems to closely match the assignment you’ve been given.

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically having some trouble with using Hover to hide or show an item. The
I am trying to debug some homework but I am having trouble with these
Having some trouble with the following code. I've created a class to manage the
Having some trouble with some code i wrote 2 years ago, Getting spammed with
Having some trouble with my view in asp.net mvc. My using directive's namespace is
I'm having a little trouble with some basic trig. I'm doing some math homework,
I'm stuck on a homework question... so far, using Arrays ONLY I'm having trouble
Am having some trouble hooking up instance variables in the visual object editor using
I'm playing with some code for a blackjack program but I'm having trouble finding
Having some trouble with NSUserDefaults here. Here's how I'm creating it: NSString *theCity =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.