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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:55:48+00:00 2026-05-16T06:55:48+00:00

this question is about best practices. I’m implementing a 3D interval Kd-Tree and, because

  • 0

this question is about best practices. I’m implementing a 3D interval Kd-Tree and, because of the recursive structure of the tree I would be tempted to create a unique class, KdTree to represent the tree itself, the nodes and the leaves.

However: elements are contained only at leaves, some general tree parameters (such as the maximum number of elements before splitting the space) are meant to be the same for all the tree and finally splitting planes have no sense at all in leaves.

That said: should I make up three classes (KdTree, KdNode, KdLeaf) or just pretend that each node or leaf is in fact a Kd-Tree (which, in fact, is precisely the case) and duplicate data?

Tommaso

  • 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-05-16T06:55:48+00:00Added an answer on May 16, 2026 at 6:55 am

    I would say there is no need for a Tree class. The top element is a node like all the rest.

    To differentiate the leaves and the branch nodes, I’d go for

     namespace KdTree
     { 
           abstract class Node 
           {
                 virtual EnumLeafNodes(LeafNodeCallback callback);
                 virtual GetLeafCount();
    
           }
    
           class Leaf : Node 
           {
                 // implement virtuals by returning/counting leaf values
           }
    
           class Branch : Node
           {
                 // implement virtuals by delegating to child nodes
    
                 // direct children:
                 Node[] children;  
           }   
     }
    

    Note that this is very much pseudocode (C#-ish). The idea behind this design is that you use virtual functions to differentiate the behavior between branches and leaf nodes, and the branches can delegate to their child nodes. This is a trivial example on what is know as the Visitor pattern.

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

Sidebar

Related Questions

This may be a question about convention, best practices and/or personal preferences: So I'm
I know this is a subjective question, but I'm always curious about best-practices in
This question arose when I was working on answering another question about best practices
This is a question about best practices i guess but it applies directly to
This is a question about sass best practices. Lets say I have a _colors.scss
Colleagues, Preamble. My question is more about best practices. I know one workaround. This
This is more a question about best practices. I have a view with many
this is mostly a theoritical question about the best practices. I'm currently programming a
I have this question about best practices in following examples: interface Request; interface Service
This is more of a question about best practices. My server allows users to

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.