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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:01:18+00:00 2026-06-18T01:01:18+00:00

Below is the Question I was asked in an interview and I believe there

  • 0

Below is the Question I was asked in an interview and I believe there are many solutions to this question but I want to know what can be the best solution (and stackoverflow is perfect for this 🙂 ).

Q: We have a tree like structure and have three threads. Now we have to perform three operations: Insert, Delete and lookup. How will you design this?

My Approach: I will take mutex for insert and delete operation as I want only one thread to perform at a time insert or delete. While in case of lookup I will allow all the three threads to enter in the function but keep a count(counting semaphore) so that insert and delete operation can’t be perform this time.
Similarly when insert or delete operation is going no thread is allowed to do lookup, same with the case for insert and delete.

Now he cross questioned me that as I am allowing only one thread at a time to insert so if two nodes on different leaf need to be inserted then still my approach will allow one at a time, this made be stuck.

Is my approach fine ?
What can be other approaches ?

  • 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-18T01:01:19+00:00Added an answer on June 18, 2026 at 1:01 am

    How about like this? Similar to a traffic road block(broken paths).

    • Each node will have two flags say leftClear_f and rightClear_f indicating clear-path ahead
    • There will be only one MutEx for the tree

    Lookup Operation:

    • If flags are set indicating path ahead is under modification, got to conditional_wait and wait for signal.
    • after getting signal check the flag and continue.

    Insert Operation

    • follow the Lookup till you get to the location of insertion.
    • acquire MutEx and set relevant flag of parent_node and both child_nodes after checking their state.
    • Release the MutEx so that parallel Delete/Insert can happen on other valid unbroken paths
    • Acquire MutEx after insert operation and update the relevant flag in the parent_node and child_nodes.

    Delete Operation
    same as Insert operation except that it deletes nodes.

    PS: You can also maintain the details of the nodes under Insert or Delete process someplace else. Other operation can jump the broken paths if necessary/needed! It sounds complicated yet doable.

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

Sidebar

Related Questions

This question is asked many times in SO. But still I can't get stuff.
I know this topic might be a very commonly asked question but I still
I know this question was asked earlier once but I see no answer to
In a recent interview I was asked below question. Given a set of nodes
The question below is not really a programming question, but more of how can
Recently I attended interview in java, the interviewer asked a question like below: I
I was asked in an interview this question so I answered with the following:
this is an interview question my friend was asked yesterday. The question was something
I asked this question (below) a week ago and got the answer I was
This was the question asked to me in an interview in c: #include<stdio.h> void

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.