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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:36:58+00:00 2026-05-13T13:36:58+00:00

Randomized binary search trees like treap give a good performance (in the order of

  • 0

Randomized binary search trees like treap give a good performance (in the order of O(log n)) with high probability while avoiding complicated (and costly) rebalancing operations that are needed for deterministic balanced trees like AVL, red-blackm, AA, etc.

We know that if we add random keys to a simple BST, we can expect it is reasonably balanced. A simple reason is that the number of heavily non-balanced trees for n nodes it’s much lower than the number of “almost balanced” trees and hence, a random order for the insertion of the keys is likely to end up with an acceptable tree.

In this case, in “The Art of Computer Programming”, Knuth gives a little bit more than 1.3*lg2(n) as the average length of a path which is rather good. He also says that deleting a random key from the a random tree preserves its randomness (and hence its good average balancing).

It seems, then, that a binary search tree where keys are inserted and deleted in a random order would most likely give performance in the order of O(log n) for all three operations: search, insert and delete.

That said, I wonder if the following approach would give the same good properties:

  • take an hash function h(x) that is known to be “good” (e.g. it ensure an even spread of the keys)
  • use the order set by h(x) on the keys instead of the ordering on k.
  • in case of collision, order according the key. That should be rare if the hash key is good enough and the range of the hash function is much bigger than the set of the keys.

To give an example a BST for the key { 4, 3, 5 , 1, 2} inserted in that order, would be:

                  4
                 / \
                3   5
               /\
              1  2

Assuming the hash function would map them to (respectively) {221,142,12,380,18) we would get.

                    221(4)
                   /   \
              142(3)  380(1)
             /    \
           12(5) 18(2)

The key point is that a “regular” BST may degenerate because the keys are inserted according the same ordering relation that is used to store them in the tree (their “natural” ordering, for example the alphabetical order of string) but the hash function induces an ordering on the keys that is completely unrelated to the “natural” one and, hence, should give the same results as if the keys were inserted in random order.

A strong assumption is that the hash function is “good”, but it’s not an unreasonable one, I think.

I didn’t find any reference to a similar approach in the literature so it might be completely wrong, but I can’t see why!

Do you see any drawback in my reasoning? Anyone has already attempted doing it?

  • 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-13T13:36:59+00:00Added an answer on May 13, 2026 at 1:36 pm

    I think what you are suggesting is to simply order using hash values, relying on the spread of hash values for a balanced tree. This works, and it should give you adequately balanced trees in practice with a good hash function.

    The reason we don’t see other people using something like this, IMO, is that if you order by hash function, your data structure is no longer sorted. Yes, it is still sorted by hash function, but the element with the smallest hash function is usually not the element you would need to search for, whereas searches like the smallest/largest/k-th element are often useful. Since the data structure would no longer have this property, it makes a lot more sense to have a hash table that uses the hash function to store in an array to get O(1) performance instead of O(log n).

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

Sidebar

Ask A Question

Stats

  • Questions 394k
  • Answers 394k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It is possible to share resources with Maven, for example… May 15, 2026 at 2:14 am
  • Editorial Team
    Editorial Team added an answer It seems to be the outline of the coordinates area,… May 15, 2026 at 2:14 am
  • Editorial Team
    Editorial Team added an answer The activemq.prefetchSize is only available on a SUBSCRIBE message, not… May 15, 2026 at 2:14 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.