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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:17:14+00:00 2026-06-08T11:17:14+00:00

Which is the following data structures be best suited for insertion, deletion, lookup, set

  • 0

Which is the following data structures be best suited for insertion, deletion, lookup, set intersection, union? Optimize time complexity.

  1. Bitmaps
  2. Binary search tree
  • 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-06-08T11:17:15+00:00Added an answer on June 8, 2026 at 11:17 am

    Foreward

    The question is ambiguous, so I will make some assumptions.

    First we are trying to represent a set of numbers over the range [0 to M] where M is a reasonably small number like 100,000.

    The BST can simply contain the elements that are in the set.

    The Bitmap can just be M bits long, and a bit is set if the number at that position is in the set, if not, the number is not in the set. I will assume that a Bitmap has already been created of size M.

    In this answer I consider Self-Balancing Binary Search Trees and Bitmaps–for non-balancing BSTs you would have to deal with best case, average case, and worst cases for each operation.

    Operations and Complexity

    Insertion: Add n to the set.

    • BSTs take O( log(n) ) time for insertion.
    • Bitmaps requires a simple (OR 1) operation on the target bit, and doing a quick division and some shifts to put that 1 in the right place, still this stays O( 1 ).

    Deletion: Remove n from the set.

    • BSTs find the element, then delete it, then rotate tree, so overall O( log(n) ).
    • Bitmaps requires a simple (AND 0) operation on the target bit, and doing a quick division and some shifts to put that 1 in the right place, still this stays O( 1 ).

    Look-Up: Is n in the set?

    • BSTs take O( log(n) ) to look up n.
    • Bitmaps return the value of (AND 1) on the specific target bit, doing division and shifts to put the 1 in the right place, overall O( 1 ).

    Set Intersection: Here’s 2 sets, which ones are the same.

    • BSTs: Do in-order traversals of both BSTs in a kind-of-MergeSort style, if two elements are the same add that into the return BST.

      • Adding elements to the return BST in sorted order is bad for balancing, so you could modify this by doing an in-order traversal over half of the BSTs, and a reverse-order traversal over the last halfs of the bSTs, then add the intersecting elements from the forward-list and the reverse-list in alternating order.
      • Overall this is something like O( n*log(n) ) since adding all the elements to the return BST takes longer than traversing.
    • Bitmap: Walk over both bitmaps, storing the ( AND ) of bytes (or say 32 bits at a time) and store it in the result location as a bitmap. O( M ) where M is the size of the range the bitmaps are initialized to.

    Set Union: Here’s 2 sets, combine them.

    • BSTs: create a new BST by adding all elements from BST1 and BST2 into it by doing a breadth-first traversal of BST1 and BST2 alternating between BST1 and BST2. If the element is already there, then don’t add it again. Overall this is something like O( n * log(n) ).
    • Bitmap: Same as set intersection, but use ( OR ) operation. O( M ) where M is the size of the range of the bitmaps.

    Ambiguities in the Question

    • What are the items to be stored in these sets (numbers, objects)
    • Are the Binary Search Trees to be analyzed Self-Balancing?
    • Is this a set chosen from a reasonably small finite range? (i.e. can this be done with a Bitmap? )
    • It is unclear what Optimize Time Complexity means, although it seems to mean “What is the lowest known Big-O (upper bound) for the average-case for this operation on this data structure?”

    Conclusion

    Bitmaps are better than self-balancing-BSTs for just about all of these operation.

    Downsides of inclusion/exclusion Bitmaps:

    • You only store inclusion/exclusion, and don’t store any data about that element.
    • Only works on integers, or objects hashed to integers in a 1-to-1 fashion (If the hash function is reversible you can get the objects back out.)
    • You must have a fixed range of elements, like integers 0 to 100,000.
    • The fixed range must be reasonably small, like less than 100 Million.
    • Union and Intersection depend on Range Size and not on number of elements represented.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables with the following (simplified) structures: table "Factors" which holds data
I have the swiss data set provided by R, which has the following form:
I'm trying to figure out the best way to represent the following data structures
I need a data structure which can handle the following: date_from (datetime) date_to (datetime)
I need a data structure which will support the following operations in a performant
I have to build a tree using the following data which comes from a
I have a C# MVC application which I need to output the following data
I have a textarea in which the user enters the following data: Paul:Nine, Rome
I have data which resembles the following: D.STEIN,DS,01,ALTRES,TTTTTTFFTT D.STEIN,DS,01,APCASH,TTTTTTFFTT D.STEIN,DS,01,APINH,TTTTTTFFTT D.STEIN,DS,01,APINV,TTTTTTFFTT D.STEIN,DS,01,APMISC,TTTTTTFFTT D.STEIN,DS,01,APPCHK,TTTTTTFFTT D.STEIN,DS,01,APWLNK,TTTTTTFFTT
I have data which resembles the following: D.STEIN,DS,01,ALTRES,TTTTTTFFTT D.STEIN,DS,01,APCASH,TTTTTTFFTT D.STEIN,DS,01,APINH,TTTTTTFFTT D.STEIN,DS,01,APINV,TTTTTTFFTT D.STEIN,DS,01,APMISC,TTTTTTFFTT D.STEIN,DS,01,APPCHK,TTTTTTFFTT D.STEIN,DS,01,APWLNK,TTTTTTFFTT

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.