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

The Archive Base Latest Questions

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

I know that the Map container in STL is internally a Red-Black Tree, which

  • 0

I know that the Map container in STL is internally a Red-Black Tree, which is a self-balancing tree.

In Map, the lowest element is at the top of the tree. So, for a map of integer to ‘anything’, the lowest integer will be at the top and so on. It always balances itself. That’s why we get a log n complexity while searching for an integer and its associated value.

But in case of map of string to ‘anything’, how does it balances and orders itself, if it does? Which string would be at the top of the tree? Does it matches the ASCII values or something?

This might be lame, but I need to know this as I have to ensure that I am adhering to the complexity of log n in my code.

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

    In Map, the lowest element is at the top of the tree.

    No, the least element is at the left-most node, the one you reach by following the left child pointer until it’s null. In the case of strings, the least element is the one that always compared “less than” all the other strings you’ve inserted into the map. The default comparison is lexicographic.

    The balancing proceeds as usual, by a bunch of pointer swaps. The path from the root to any leaf is guaranteed to have length Θ(lg n), no matter what.

    (This is assuming the original STL implementation of map, which is still common, though a conforming C++ library might use a different structure.)

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

Sidebar

Related Questions

I know that a map destructor calls each of the contained element's destructors. What
Did you know that : Map<Object,Object> m1 = new HashMap<Object, Object>(); Map<Object,Object> m2 =
I only know that the difference between hashmap and map is that hashmap is
I know about map/reduce alghoritm and its use. It's using functions that are called
Does anyone know of an Image Map-like Blackberry Control that I can use in
C++ Boost has Bimap container that is a bidirectional map: http://www.boost.org/doc/libs/1_43_0/libs/bimap/doc/html/index.html Does anyone know
I have a templatized container class in C++ which is similar to a std::map
Map is a container class that is used to store the aggregate data... Its
What I mean is - we know that the std::map 's elements are sorted
I have a map with a bunch of buttons that show and hide container

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.