The algorithmic problem Range

Posted on 2011-10-16
Last Modified: 2012-05-12
Consider the algorithmic problem Range de fined as follows:
Input: a, possibly NULL, node x in a binary search tree; two key values a,b with a less or egual to b;
Output: the sequence of entries in the binary search tree with root x whose key values are in the range [a..b].
Give a recursive algorithm to solve the above problem.
Question by:gudni12345
    1 Comment
    LVL 37

    Accepted Solution

    It's really easy. It's supposed to be recursive and you know in a binary search tree that every node less than the root is on the left of the root and every node greater is on the right side.
    So all you need to do is look at x and see where it falls in the range. Then just recurse the tree from x putting all the values in the range out as output.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Suggested Solutions

    Okay. So what exactly is the problem here? How often have we come across situations where we need to know if two strings are 'similar' but not necessarily the same? I have, plenty of times. Until recently, I thought any functionality like that wo…
    The greatest common divisor (gcd) of two positive integers is their largest common divisor. Let's consider two numbers 12 and 20. The divisors of 12 are 1, 2, 3, 4, 6, 12 The divisors of 20 are 1, 2, 4, 5, 10 20 The highest number among the c…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now