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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:24:37+00:00 2026-06-01T18:24:37+00:00

I am hopelessly lost when it comes to recursive functions. I am required to

  • 0

I am hopelessly lost when it comes to recursive functions. I am required to create a recursive function to traverse a binary tree and insert a new node in between specific values. Would i need to recopy my traverse function and modify it in every other function that i use it in? Would someone please evaluate the traverse function?

I think my traversing code is alright.

Node traverse (Node currentNode){
    if (!currentNode.left.equals(null)){
        traverse (currentNode.left);
        return currentNode.left;
    }
    if (!currentNode.right.equals(null)){
        traverse (currentNode.right);
        return currentNode.right;
    }
    return currentNode;
}
  • 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-01T18:24:39+00:00Added an answer on June 1, 2026 at 6:24 pm

    When it comes to binary trees, there are several different types of traversals that can be done recursively. They’re written in the order they’re referenced then visited (L=Left child, V = visit that node, R = right child).

    • In-order traversal (LVR)
    • Reverse order traversal (RVL)
    • Preorder traversal (VLR)
    • Postorder traversal (LRV)

    Your code appears to be performing the postorder traversal method, but you’re getting a few things mixed up. First, the node is what you want to traverse; the data is what you want to visit. Second, you have no reason to return the node itself, in the way that this is implemented. Your code doesn’t allow for a condition to say, ‘I’m looking for this particular data, do you have it Mr. Node@0xdeadbeef?’, which would be found with some sort of extra search parameter.

    An academic BST traversal only prints the nodes itself. If you wanted to add a search functionality, it’s only one more parameter, as well as an additional check for the right node.

    Here’s a snippet:

    // Academic
    
    public void traverse (Node root){ // Each child of a tree is a root of its subtree.
        if (root.left != null){
            traverse (root.left);
        }
        System.out.println(root.data);
        if (root.right != null){
            traverse (root.right);
        }
    }
    
    // Search with a valid node returned, assuming int
    
    public Node traverse (Node root, int data){ // What data are you looking for again?
        if(root.data == data) {
            return root;
        }
        if (root.left != null && data < root.data) {
            return traverse (root.left, data);
        }
        if (root.right != null && data > root.data) {
            return traverse (root.right, data);
        }
        return null;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am to create a function to read a table containing some 65 tables
I'm trying to create a function in PHP which would go through CSS and
I realize this is probably a hopelessly newbie question, but what is the difference
I'm having a hard time getting this to work, and I'm hopelessly confused with
I'm hopeless at Javascript. This is what I have: <script type=text/javascript> function beginrefresh(){ //set
I'm really hopeless when it comes to Unix-like systems. I tried to download an
This may be a hopelessly vague question. But I am interested to hear whatever
Why is glTexSubImage2D() suddenly causing GL_INVALID_OPERATION? I'm trying to upgrade my hopelessly outdated augmented
I hope that this isn't too hopelessly subjective. ask user to supply a set
This is the code snippet I have been hopelessly stuck on. template <class T,

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.