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 8015513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:16:37+00:00 2026-06-04T20:16:37+00:00

I am wondering why the default size of a PriorityQueue in Java is 11

  • 0

I am wondering why the default size of a PriorityQueue in Java is 11. I looked up the implementation and it made things more confusingly for me.

The priority queue is implemented as a heap. Its capacity is adjusted using this function:

/**
 * Increases the capacity of the array.
 *
 * @param minCapacity the desired minimum capacity
 */
private void grow(int minCapacity) {
    if (minCapacity < 0) // overflow
        throw new OutOfMemoryError();
    int oldCapacity = queue.length;
    // Double size if small; else grow by 50%
    int newCapacity = ((oldCapacity < 64)?
                       ((oldCapacity + 1) * 2):
                       ((oldCapacity / 2) * 3));
    if (newCapacity < 0) // overflow
        newCapacity = Integer.MAX_VALUE;
    if (newCapacity < minCapacity)
        newCapacity = minCapacity;
    queue = Arrays.copyOf(queue, newCapacity);
}

I don’t understand the initial value 11 for the capacity. I think that the capacity should always be 2 to the number of levels. Any clarification?

  • 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-04T20:16:38+00:00Added an answer on June 4, 2026 at 8:16 pm

    11 is probably a number that was chosen more or less arbitrarily, as a trade off between memory consumption (a too large number would consume too much memory for nothing), and CPU consumption (a too low number would need too many resizes of the queue). And they probably benchmarked typical use cases to choose this number and the strategy used to resize the queue.

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

Sidebar

Related Questions

Im just wondering how to set a default zoom on my google maps application
I'm wondering if there is a defined standard for what the default action is
I am wondering if there is any other configuration options for a default controller.
I'm wondering what is the default path when saving a file using the NSArray
I'm wondering if it's possible to restore an element's style to it's default state,
I am looking at implementation of IOUtils.copy() from Apache Commons at http://www.docjar.com/html/api/org/apache/commons/io/IOUtils.java.html and it
I'm wondering what is default state of autocommmit in iOS Core Data and if
Wondering if there is any way to get the lambda expressions that result from
Wondering what is the best or most popular database client tool. Similar to Microsoft's
Wondering if anyone can suggest a good file replication tool that will replicate across

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.