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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:53:31+00:00 2026-06-13T18:53:31+00:00

Need to define a seek(u,v) function, where u is the new node within the

  • 0

Need to define a seek(u,v) function, where u is the new node within the tree (the node where I want to start searching), and v is the number of descendants below the new node, and this function would return index of highest key value. The tree doesn’t have a be a BST, there can be nodes with many many children. Example:

input:
5             // tree with 5 nodes
1 3 5 2 7     // the nodes' keys
1 2           // 1 and 2 are linked
2 3           // 2 and 3 are linked
1 4           // 1 and 4 are linked
3 5           // 3 and 5 are linked
4             // # of seek() requests
2 3           // index 2 of tree, which would be key 5, 3 descendants from index 3 
4 1           // index 4 of tree, but only return highest from index 4 to 4 (it would 
              // return itself)
3 2           // index 3, next 2 descendants
3 2           // same

output:
5             // Returned index 5 because the 7 is the highest key from array[3 'til 5]
4             // Returned index 4 because the range is one, plus 4's children are null
5             // Returned index 5 because the 7 is the highest key from array[4 'til 5]
5             // Same as prior line

I was thinking about putting the new root into a new Red Black Tree, but can’t find a way to efficiently save successor or predecessor information for each node. Also thinking about putting into an array, but due to the nature of an unbalanced and unsorted tree, it doesn’t guarantee that my tree would be sorted, plus because it’s not a BST i can’t perform an inorder tree walk. Any suggestions as to how I can get the highest key from a specific range?

  • 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-13T18:53:32+00:00Added an answer on June 13, 2026 at 6:53 pm

    I dont understand very well what you mean by : “the number of descendants below the new node”. The way you say it, it implies there is a some sort of imposed tree walk, or at least an order in which you have to visit the nodes. In that case it would be best to explain more thoroughly what you mean.

    In the rest of the answer I assume you mean distance from u.

    From a pure algorithmic point of view, since you cannot assume anything about your tree, you have to visit all concerned vertices of the graph (i.e vertices at a distance <= v from u) to get your result. It means any partial tree traversal (such as depth-first or breadth-First) should be enough and necessary (since you have to visit all concerned nodes below u), since the order in which we visit the nodes doesn’t matter.

    If you can, it’s simpler to use a recursive function seek'(u,v) which return a couple (index, key) defined as follows :

    • if v > 1, you define seek'(u,v) as the couple which maximizes its second component among the couples (u, key(u)) and seek(w,v-1) for w son of u.
    • else (v = 1) you define seek'(u,v) as (u, key(u))

    You then have seek(u,v) = first(seek'(u,v)).

    All of what I said presumes you have built a tree from the input, or that you can easily get the key of a node and its sons from its index.

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

Sidebar

Related Questions

I am new to Yii framework and i need to define a function which
I need to define this function called total. total :: (Int -> Int) ->
Why is there a need to define a new method in RESTful controller, follow
I need to define mutually-dependent vars. By this I mean that one var contains
We need to define a conditional compilation symbol in a class library project. This
I need to define a main function that reads integers and prints them back
I need to define many variables and I don't want to do it one
I need to define a singleton ActiveRecord model. I do this: class Universe <
I need to define a read and a print function for a class that
I need to define a calculated member in MDX (this is SAS OLAP, but

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.