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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:06:46+00:00 2026-05-26T02:06:46+00:00

I have a BST which has duplicate entries. I am trying to find duplicate

  • 0

I have a BST which has duplicate entries. I am trying to find duplicate entries. Now obviously I can write a dumb algorithm which traverses the whole tree, which is easy.

However, I want to write a more efficient one. Here’s what I’ve done/thought so far:

Assume the following tree.

      10
     /   \
    5    15
   /\    / \
  2  8   10 16
      \    \
       8   12

If I want to find all 8’s, I will first find the 8 on the left subtree of the 10. To find a duplicate, if it has no right child, is it going to be the left-most node on the right-subtree of the the first parent that is larger than that node (8)? And if it did have a right child, then it can be either in the left most node of its right subtree or the right most node on its left subtree?

Are those all the cases, which can be achieved with a bunch of loops and if-statements?

If not, what’s a better approach? Can anyone help?

Thanks

EDIT:
Actually I just realized it can’t be the “left most node” or “right most node”. That would find the node that is the next highest value or the previous lowest value. Would it be one node before?

EDIT 2:

Fixed my BST example. It follows the following insertion method:

if (node == null) 
    return new NodeBST<Value>(name, value);

if (node.key().compareTo(name) > 0)
    node.setLeft(insert(node.left(), name, value));     
else
    node.setRight(insert(node.right(), name, value));

This means duplicates will be added to the right of their duplicates.. right?

  • 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-26T02:06:47+00:00Added an answer on May 26, 2026 at 2:06 am
    1. Find an element that matches your key using the usual binary tree search algorithm. If not found, stop.
    2. Examine the LH sub-branch. If its key matches, make that the current node and repeat this step.
    3. You are now at the first element in the tree with that key. Now do a tree walk from this node while the keys are equal, i.e. visit this node, the right sub-tree, the parent, the parent’s right sub-tree, etc, left as an exercise for the reader.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Find function in order to find an element from a BST
Have a matrix report now that has Position, Hours and Wages for a location
i have a native win32 c++ application which has a checkbox in it. I
I have a rails time-based query which has some odd timezone sensitive behaviour, even
I have a WCF service which exposes a Generic interface (and the service has
I have a string which has a version number. I want to read the
So I am implementing a BST, and right now I am trying to add
I have a MongoDB collection which has a created_at stored in each document. These
I have a BST in python, with each node holding 3 pieces of data.
Here is what I'm doing. I have a class which I instance and it

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.