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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:28:26+00:00 2026-06-07T13:28:26+00:00

Given number of binary tree nodes (X) write method that returns the number of

  • 0

Given number of binary tree nodes (X) write method that returns the number of random permutations of binary trees with X nodes.

Examples:

X=1: 1

     o

X=2: 2

     o    o
   o        o

X=3: 5

        o    o          o     o        o
      o        o      o         o    o   o
    o            o      o     o

I ended up with :

    public static int numOfPerms(int numOfNodes) {
       if (numOfNodes<=2 && numOfNodes > 0) {
           return numOfNodes;
       }
       int res = 1;
       for (int i=1; i<=numOfNodes; i++) {
           res = res*(4*i-1)/(i+1);
       }
       return res;
    } 

I would appreciate sharing here better solutions.

  • 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-07T13:28:28+00:00Added an answer on June 7, 2026 at 1:28 pm

    Try this recursive method:

    static int numOfPerms(int numOfNodes) {
        if (numOfNodes == 1) {
            return 1; 
        }
    
        numOfNodes = numOfNodes - 1;
        return ((numOfPerms(numOfNodes) * (2*numOfNodes+2) * 
                (2*numOfNodes+1))/((numOfNodes+1)*(numOfNodes+2)));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a binary number that repeats, for example 0.(0011) or 0.0(101), how would one
Given this binary tree (actually, the binary tree can be random and dynamic, this
Suppose in a given binary tree if each node contains number of child elements
I saw this problem: Given a binary search tree and a number, find a
I am looking for a sound algorithm that would randomly place a given number
A binary tree of N nodes is 'curious' if it is a binary tree
Consider the problem of counting the number of structurally distinct binary search trees :
Given a binary number, what is the fastest way of removing the lowest order
Given a tree (binary) structure, with depth N. Is it possible to compute some
I am implementing a tree which is a Binary Expression Tree. The leaf nodes

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.