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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:32:12+00:00 2026-05-16T05:32:12+00:00

Given a simple binary tree, how can we prove that tree is a binary

  • 0

Given a simple binary tree, how can we prove that tree is a binary search tree? When we traverse a binary tree, how do we know if the node we are on is the left or right child of its parent? I came up with one solution where i would pass some flag in recursive function call which could keep track of whether the node is left or right child of its parent as well as we need one parent node pointer through which we can compare :-

if(flag == 'L' && node->value < node->parent->value)
   then continue recursion;
else{
   print "not a binary search tree"
   exit;
}

In the same way one if condition is needed for R. Apart from this can you think any other efficient way?

Thanks in advance 🙂

  • 1 1 Answer
  • 4 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-16T05:32:13+00:00Added an answer on May 16, 2026 at 5:32 am

    I would just check:

    currentNode.Left.max() < currentNode.Value and currentNode.Left.isBinarySearchTree(). If both are fulfilled, it’s a binary search tree.

    Edit:

    The above does traverse the left tree twice (once for the max() and once for isBinarySearchTree. However, it can be done using just one traversal:

    Store the minimum and maximum element in your tree class. Updates, etc. of course can be done in O(1) space and time.

    Then, instead of using max(), make a method isInRange(m,M), that checks, whether a (sub)tree contains only elements in the range (m,m+1,...,M).

    Define isInRange(m,M) as follows:

    bool isInRange(m,M){
     if (m < currentNode.Value <= M){
      return (currentNode.Left.isInRange(m, currentNode.Value) && currentNode.Right.isInrange(currentNode.Value+1, M));
     }
     return false;
    }
    

    Then, the initial call would be root.isInRange(globalmin, globalmax).

    Didn’t test it so I don’t know if it matters in performance.

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

Sidebar

Related Questions

Given a binary tree (with left and right child only), how do you write
Assuming a complete binary tree, each node can be adressed with the position it
Simple question - given an IList<T> how do you perform a binary search without
Given a simple namespaced route map.namespace :api do |api| api.resources :genres end how can
Given a simple parent/child class structure. I want to use linqkit to apply a
Given the following simple BST definition: data Tree x = Empty | Leaf x
Simple task: given that an article has many comments, be able to display in
Ii have a problem. i have to convert a Binary Tree in its zigZag
Given a binary number that repeats, for example 0.(0011) or 0.0(101), how would one
Given that Lucene is a robust document based search engine could it be used

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.