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

  • Home
  • SEARCH
  • 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 7764605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:57:16+00:00 2026-06-01T14:57:16+00:00

I have a BST in python, with each node holding 3 pieces of data.

  • 0

I have a BST in python, with each node holding 3 pieces of data. Those pieces of data being ID, Mark, and Name.

What I’m trying to do is search for a Name, but the nodes are based on IDs, this is how I’ve searched. The function is supposed to output the ID of the specific Name.

def findName(tree,name):
    if tree==None:
        return None
    elif tree['name']==name:
        return tree['id']
    if tree['left']!=None:
        return findName(tree['left'],name)
    if tree['right']!=None:
        return findName(tree['right'],name) 

Unfortunately I’ll only ever be searching the left side of the Tree, and not the right, the opposite applies if I search the right side first.

How do I search both sides for this?

  • 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-01T14:57:17+00:00Added an answer on June 1, 2026 at 2:57 pm

    You shouldn’t return if you’re not yet finished! Instead, you can replace your last 4 lines with a single, short-circuiting or:

    return findName(tree['left'], name) or findName(tree['right'], name)
    

    Make sure your IDs don’t include 0, though, otherwise this method will fail because 0 is a falsy value, just like None.

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

Sidebar

Related Questions

I have been trying to implement the delete BST function but I don't know
i wana create a bst tree in c++ but i have a syntax error
I wanted to make a dictionary using BST but I did not have any
I have this code fragment class bst { public node root=null; bst() { root=null;
I have a BST which has duplicate entries. I am trying to find duplicate
I have been using a driver to test one of my data structures(Binary Search
I have created a BST full of WordInfo objects that have a vector to
I have a Find function in order to find an element from a BST
This is my homework and I have thought a lot about it but I
So I'm trying to create my own BST for a spellchecker because I want

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.