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

  • Home
  • SEARCH
  • 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 1052315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T17:04:28+00:00 2026-05-16T17:04:28+00:00

From my understanding, TreeMap : 1. Insert O( logN ) 2. Delete O( logN

  • 0

From my understanding,

TreeMap :
1. Insert O( logN )
2. Delete O( logN )
3. Retrieve O( logN )
HashMap :
1. Insert O( 1 ) -> O( N )
2. Delete O( 1 ) -> O( N )
3. Retrieve O( 1 ) -> O( N )

I know that TreeMap using Red-Black tree as internal data structure. However, I’m not so sure about HashMap’s internal data structure.

  1. Is HaspMap implemented using
    Hash-Table?
  2. If the answer is “Yes”, then does it use array-base’s implementation
    or reference-base’s implementation?
  3. And if it used array-base then is it sorted or unsorted?

I’m working on a small project using Java to demonstrate the runtime complexity of all operations( insert, delete, retrieve ) between HashMap and TreeMap, but I don’t really know how to link the theory formula with actual result from running a program. For example, from running a quick test :
1. Insert 10,000 elements
2. Delete 100 elements
3. Retrieve 100 elements

I got this info:

     HashMap
Create time : 6348015 nano seconds.
Remove time : 98458 nano seconds.
Retrieve Found time : 59762 nano seconds.
Retrieve Not Found time : 39097 nano seconds.
 --- end ---

     TreeMap
Create time : 20518163 nano seconds.
Remove time : 274221 nano seconds.
Retrieve Found time : 112072 nano seconds.
Retrieve Not Found time : 168442 nano seconds.
 --- end ---

I would like to know how can I find the link these times with the theoretical time complexity such as O( N ) or O( logN )?
And this result surprised me since I always think TreeMap would beat HashMap badly. Could anyone give me some brief explanation about these things? Thanks 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-16T17:04:29+00:00Added an answer on May 16, 2026 at 5:04 pm

    If you want to show the complexity of some operation, you can’t just use one data point, you have to show how the time changes when N changes.

    Also, often algorithms or data-structures with better theoretical complexity have worse running times for smaller data-sets.

    Another thing to think about is to have representative values. For example if you insert values 1, 2, 3, … into an RB-tree, that’s the worst-case scenario (I think), because it has to rebalance quite often. Inserting random values will probably give different result.

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

Sidebar

Related Questions

From my understanding, Lua is an embeddable scripting language that can execute methods on
I'm using TortoiseHg 0.5 (which includes Mercurial 1.0.2) on Vista64. My understanding from the
My understanding of Hibernate is that as objects are loaded from the DB they
Are there any understanding / maintainability issues that result from code like inVar1 ==
From my understanding the XMPP protocol is based on an always-on connection where you
From my understanding of the CSS spec, a table above or below a paragraph
I tried to write generic function that remove the duplicate elements from array. public
I often come across web applications that expose internal database primary keys through forms
From a web developer point of view, what changes are expected in the development
From a desktop application developer point of view, is there any difference between developing

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.