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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:11:42+00:00 2026-05-27T12:11:42+00:00

I wrote an exam paper today, for a university course concerned with the implementation

  • 0

I wrote an exam paper today, for a university course concerned with the implementation of data structures in Java. The last question was along these lines:

Explain why it’s convienient to use a TreeMap<Integer, Integer> to store a polynomial with integral coefficients, especially when the polynomial is supposed to be printed out in standard form, as a String.

Realising that it was a mistake, I nevertheless proceeded to explain why I did not think it was a good idea. I instead argued to use a simple int[] array, since arrays have O(1) random access, O(n) iteration in both directions and no extra memory footprint for pointers (references).

Assuming I’m wrong and there is some benefit to using a (sorted) TreeMap, can anyone please explain those benefits to me? I reason that since Matlab, Octave, Maple and other well-tested numerical programs use arrays to store polynomials, it can’t be all wrong.

  • 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-05-27T12:11:42+00:00Added an answer on May 27, 2026 at 12:11 pm

    I think the most striking example is x^10000 + 3x^2 + 2 or something. You want to make a new int[10000] instead of 3 nodes in a TreeMap? 🙂

    And of course being sorted you can iterate in order to construct and manipulate your polynomial easier.

    And are you sure that numerical programs use arrays for that? I’d like to see a citation of their internal implementation if you believe that’s the case.

    As for the memory footprint issue, the standard implementation of java.util.TreeMap will yield 7 extra references and primitives, one of which has a reference inside it, another of which has 7 references inside it. So you’re looking at 15 extra references for that. Each entry will have 5 references and a primitive, so instead of 2 + 1*n for your array, you have 15 + 6*n. So any time you have (14 + 5*n) empty polynomials, using a TreeMap uses less memory than using an array.

    The smallest example of this would be x^20 which would have 21 array elements and 1 array reference for a total of 22 words, while the TreeMap would only have 21 words.

    It’s conceivable I’m missing a reference in the implementation but I went over it pretty good.

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

Sidebar

Related Questions

I just wrote this exam, in which there was question: Consider a array of
Wrote a quick Java proggy to spawn 10 threads with each priority and calculate
I wrote a windows service using VB that read some legacy data from Visual
This is a past exam paper on binary search trees I am attempting. I
I am writing some Java questions to help my friends in the Java exam.
i have no idea how to get these errors out. i wrote the whole
Preparing for exam and got stuck at this question: Allowed operators are <<,+,& no
I'm studying for an exam, and a previous exam had this question: 1. void
So I'm working on some code (going over a practice exam for a course
I'm currently studying for a CS course's final exam and I've run into a

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.