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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:20:29+00:00 2026-05-23T15:20:29+00:00

I am brushing up algorithms and data structures and have a few questions as

  • 0

I am brushing up algorithms and data structures and have a few questions as well as statements I would like you to check.

ArrayList – O(1) (size, get, set, …), O(n) – add operation.
LinkedList – all operation O(1) (including add() ), except for retrieving n-th element which is O(n). I assume size() operation runs in O(1) as well, right?

TreeSet – all operations O(lg(N)). size() operation takes O(lg(n)), right?

HashSet – all operations O(1) if proper hash function is applied.
HashMap – all operations O(1), anologous to HashSet.

Any further explanations are highly welcome. Thank you in advance.

  • 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-23T15:20:29+00:00Added an answer on May 23, 2026 at 3:20 pm

    ArrayList.add() is amortized O(1). If the operation doesn’t require a resize, it’s O(1). If it does require a resize, it’s O(n), but the size is then increased such that the next resize won’t occur for a while.

    From the Javadoc:

    The add operation runs in amortized constant time, that is, adding n elements requires O(n) time. All of the other operations run in linear time (roughly speaking). The constant factor is low compared to that for the LinkedList implementation.

    The documentation is generally pretty good for Java collections, in terms of performance analysis.

    The O(1) for hash algorithms isn’t a matter of just applying a “proper” hash function – even with a very good hash function, you could still happen to get hash collisions. The usual complexity is O(1), but of course it can be O(n) if all the hashes happen to collide.

    (Additionally, that’s counting the cost of hashing as O(1) – in reality, if you’re hashing strings for example, each call to hashCode may be O(k) in the length of the string.)

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

Sidebar

Related Questions

So I've been brushing up on my Java skills as of late and have
I have been brushing up on my design patterns and came across a thought
I've been brushing up on my C++ as of late, and I have a
so as per one of my previous questions, I'm brushing up on my C
I'm working on a Windows Form in VB.NET 2005 and I would like to
Currently I'm brushing up on my Fortran95 knowledge (don't ask why)... I'm running in
Possible Duplicate: When should you use 'friend' in C++? I was brushing up on
I am brushing up again and I am getting an error: Cannot call member
For brushing up my C, I'm writing some useful library code. When it came
I am brushing up on my design patterns at the moment and got 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.